Index: trunk/SRC/Interpolation/file_interp.pro
===================================================================
--- trunk/SRC/Interpolation/file_interp.pro	(revision 361)
+++ trunk/SRC/Interpolation/file_interp.pro	(revision 362)
@@ -6,5 +6,5 @@
 FUNCTION call_interp2d, data, inlon, inlat, inmask, outlon, outlat $
                       , INIRR=inirr, METHOD=method, SMOOTH=smooth $
-                      , WEIG=weig, ADDR=addr, NAN_VALUE=NaN_value, _EXTRA=ex
+                      , WEIG=weig, ADDR=addr, MISSING_VALUE=missing_value, _EXTRA=ex
 ;
   compile_opt idl2, strictarrsubs
@@ -15,12 +15,17 @@
 ;
 ; take care of NaN values
-  mask = inmask *finite(data)
-;
-  IF keyword_set(NaN_value) THEN BEGIN
+  nanmsk = finite(data)
+  IF total(nanmsk) NE n_elements(nanmsk) THEN BEGIN
+    data[where(nanmsk EQ 0b)] = 1.e20 ; put large value to be sure they are removed during the interpolation
+    mask = inmask * temporary(nanmsk)
+  ENDIF ELSE mask = inmask
+;
+  tpmiss = size(missing_value, /type)
+  IF tpmiss NE 0 AND tpmiss NE 7 THEN BEGIN
     CASE 1 OF
-      nan_value GT 1.e6:mask = temporary(mask) * (data LT (nan_value-10.))
-      nan_value LT -1.e6:mask = temporary(mask) * (data GT (nan_value+10.))
-      abs(nan_value) LT 1.e-6:mask = temporary(mask) * (abs(data) GT 1.e-6)
-      ELSE:mask = temporary(mask) * (data NE nan_value)
+      missing_value GT 1.e6:mask = temporary(mask) * (data LT (missing_value-10.))
+      missing_value LT -1.e6:mask = temporary(mask) * (data GT (missing_value+10.))
+      abs(missing_value) LT 1.e-6:mask = temporary(mask) * (abs(data) GT 1.e-6)
+      ELSE:mask = temporary(mask) * (data NE missing_value)
     ENDCASE
   ENDIF
@@ -142,6 +147,9 @@
 ; @keyword INMISSING_VALUE {type=scalar}
 ; To define (or redefine if the attribute is already existing) the
-; missing values used with INUSEASMASK keyword. Note that this value is
-; not used if INTESTOP keyword is given and contains 2 words.  
+; missing values used with INUSEASMASK keyword to build the input mask.
+; Note that this value is not used if INTESTOP keyword is given and
+; contains 2 words.
+; Note: do not mismatch with MISSING_VALUE used to detect missing
+; values at reach record.   
 ;
 ; @keyword OUTMISSING_VALUE {type=scalar}
@@ -154,8 +162,8 @@
 ; INTESTOP can contain 1 or 2 words. The first word is the operator
 ; definition: "EQ" "NE" "GE" "GT" "LE" "LT" (default is NE). The
-; second word define the testing value. If TESTOP contains only 1
+; second word define the testing value. If INTESTOP contains only 1
 ; word, then the test value is denifed by
-;   1) MISSING_VALUE keyword
-;   2) attribute missing_value or _fillvalue of the variable USEASMASK
+;   1) INMISSING_VALUE keyword
+;   2) attribute missing_value or _fillvalue of the variable INUSEASMASK
 ;   3) !Values.f_nan (can be used only with NE and EQ operators)
 ;
@@ -170,8 +178,12 @@
 ; same as inaddscl_before but for output mask file maskout
 ;
-; @keyword NAN_VALUE {type=scalar}{default=not used}
-; define the missing value in input data (missing values are treated
+; @keyword MISSING_VALUE {type=scalar}{default=defined by attribute missing_value or _fillvalue}
+; (Re)define the missing value in input data (missing values are treated
 ; like masked values and will be filled with extrapolation before
-; interpolation).
+; interpolation). 
+; Note: do not mismatch with (IN/OUT)MISSING_VALUE which are missing value
+; used (in association with (IN/OUT)USEASMASK) to built the mask (that
+; does not change from one record to another).
+; Note: this value will be apply to all interpolated variables
 ;
 ; @keyword ADDR {type=2d array or variable name}
@@ -222,5 +234,5 @@
 ; IDL> file_interp, filein, fileout, gridout, inxaxisname = 'lo', inyaxisname = 'la', keep = ['lo', 'la', 'cond_sed']
 ;
-; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, nan_value = -1000.00
+; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, missing_value = -1000.00
 ;
 ; @history
@@ -241,5 +253,5 @@
                , OUTUSEASMASK=outuseasmask, OUTMISSING_VALUE=outmissing_value $
                , OUTADDSCL_BEFORE=outaddscl_before, OUTTESTOP = outtestop $
-               , NAN_VALUE=NaN_value, WEIG=weig, ADDR=addr $
+               , MISSING_VALUE=MISSING_VALUE, WEIG=weig, ADDR=addr $
                , INXAXISNAME=inxaxisname, INYAXISNAME=inyaxisname $
                , OUTXAXISNAME=outxaxisname, OUTYAXISNAME=outyaxisname $
@@ -409,4 +421,6 @@
         END
         ELSE:BEGIN
+          IF n_elements(missing_value) NE 0 THEN var_missing_value = MISSING_VALUE $
+          ELSE ncdf_getatt, inid, i, MISSING_VALUE = var_missing_value
           CASE varinq.ndims OF
             0:BEGIN             ; salar
@@ -422,5 +436,5 @@
               IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, inmask[*, *, 0], outlon, outlat $
                                                   , INIRR = inirr, METHOD = method, SMOOTH = smooth $
-                                                  , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex)
+                                                  , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex)
               ncdf_varput, outid, outvarid[i], temporary(data)
             END
@@ -437,5 +451,5 @@
                 IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $
                                                     , INIRR = inirr, METHOD = method, SMOOTH = smooth $
-                                                    , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex)
+                                                    , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex)
                 ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt
               ENDFOR
@@ -453,5 +467,5 @@
                   IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $
                                                       , INIRR = inirr, METHOD = method, SMOOTH = smooth $
-                                                      , WEIG = weig, ADDR = addr, NAN_VALUE = NaN_value, _extra = ex)
+                                                      , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex)
                   ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt
                 ENDFOR
