Index: /trunk/SRC/Interpolation/compute_fromreg_bilinear_weigaddr.pro
===================================================================
--- /trunk/SRC/Interpolation/compute_fromreg_bilinear_weigaddr.pro	(revision 472)
+++ /trunk/SRC/Interpolation/compute_fromreg_bilinear_weigaddr.pro	(revision 473)
@@ -8,8 +8,8 @@
 ; Interpolation
 ;
-; @param alonin{in}{required}{type=2d array}
+; @param alonin{in}{required}{type=1d array}
 ; longitude of the input data
 ;
-; @param alatin {in}{required}{type=2d array}
+; @param alatin {in}{required}{type=1d array}
 ; latitude of the input data
 ;
Index: /trunk/SRC/Interpolation/extrapolate.pro
===================================================================
--- /trunk/SRC/Interpolation/extrapolate.pro	(revision 472)
+++ /trunk/SRC/Interpolation/extrapolate.pro	(revision 473)
@@ -64,5 +64,6 @@
 ;-
 FUNCTION extrapolate, zinput, maskinput, nb_iteration, FILLXDIR = fillxdir, FILLYDIR = fillydir $
-                      , X_PERIODIC = x_periodic, MINVAL=minval, MAXVAL=maxval, GE0=ge0, _EXTRA=ex
+                      , X_PERIODIC = x_periodic, MINVAL = minval, MAXVAL = maxval, GE0 = ge0 $
+                      , SMWIN = smwin, NSMOOTH = nsmooth, _EXTRA = ex
 ;
   compile_opt idl2, strictarrsubs
@@ -104,5 +105,5 @@
     ztmp[temporary(nan)] = 1.e20
     msk = temporary(msk) * temporary(finztmp)
-  ENDIF ELSE finztmp = -1 ; free memory
+  ENDIF ELSE finztmp = -1       ; free memory
   z = temporary(ztmp)
   nx2 = nx+2
@@ -186,6 +187,6 @@
       keyword_set(fillydir):zcoast = z[nx2+coast]+z[-nx2+coast]
       ELSE:zcoast = z[1+coast]+z[-1+coast]+z[nx2+coast]+z[-nx2+coast] $
-             +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $
-                          +z[-nx2+1+coast]+z[-nx2-1+coast])
+                    +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $
+                                 +z[-nx2+1+coast]+z[-nx2-1+coast])
     ENDCASE
 ;
@@ -224,8 +225,54 @@
 ;
   ENDWHILE
+;
+  z = z[1:nx, 1:ny]
+;
+;---------------------------------------------------------------
+; smooth the filled values
+;---------------------------------------------------------------
+  IF n_elements(smwin) EQ 0 THEN smwin = 0
+  IF smwin EQ 0 OR smwin EQ 1 THEN return, z
+  IF n_elements(nsmooth) EQ 0 THEN nsmooth = 25
+  IF nsmooth EQ 0 THEN return, z
+
+; add extra bands to avoid edge errors...
+
+  one = replicate(1, smwin) 
+  IF keyword_set(x_periodic) THEN BEGIN
+;   nx-smwin   nx-1    0       smwin-1                      nx-smwin      nx-1    0       smwin-1
+;     |----------|     |----------|------------------------------|----------|     |----------|
+;     0      smwin-1  smwin   2*smwin-1                          nx  nx+smwin-1  nx+smwin nx+2*smwin-1 
+    z   = [         z[nx-smwin:nx-1, *],         z,         z[0:smwin-1, *] ]
+    msk = [ maskinput[nx-smwin:nx-1, *], maskinput, maskinput[0:smwin-1, *] ]
+;; IF array_equal(z[0:smwin-1, *], z[nx:nx+smwin-1, *]) NE 1 THEN stop
+;; IF array_equal(z[nx+smwin:nx+2*smwin-1, *], z[smwin:2*smwin-1, *]) NE 1 THEN stop
+  ENDIF ELSE BEGIN 
+    z   = [         one#(z[0, *])[*],         z,         one#(z[nx-1, *])[*] ]
+    msk = [ one#(maskinput[0, *])[*], maskinput, one#(maskinput[nx-1, *])[*] ]
+  ENDELSE 
+  z   = [ [  z[*, 0]#one], [  z], [  z[*, ny-1]#one] ]
+  msk = [ [msk[*, 0]#one], [msk], [msk[*, ny-1]#one] ]
+
+  zorg = z
+  mskm1 = 1-msk
+  FOR i = 1, nsmooth DO BEGIN
+    z = smooth( temporary(z)*mskm1 + zorg*msk, smwin )
+    IF keyword_set(x_periodic) THEN BEGIN
+      z[0:smwin-1, *] = z[nx:nx+smwin-1, *]
+      z[nx+smwin:nx+2*smwin-1, *] =  z[smwin:2*smwin-1, *]
+    ENDIF ELSE BEGIN 
+      z[0:smwin-1, *] = one#(z[smwin, *])[*]
+      z[nx+smwin:nx+2*smwin-1, *] = one#(z[nx+smwin-1, *])[*]
+    ENDELSE 
+    z[*, 0:smwin-1] = z[*, smwin]#one
+    z[*, ny+smwin:ny+2*smwin-1] = z[*, ny+smwin-1]#one
+  ENDFOR  
+  z = temporary(z)*mskm1 + zorg*msk
+  z = (temporary(z))[smwin:nx+smwin-1, smwin:ny+smwin-1]
+;
 ;---------------------------------------------------------------
 ; we return the original size of the array
 ;---------------------------------------------------------------
 ;
-  return, z[1:nx, 1:ny]
+  return, z
 END
Index: /trunk/SRC/Interpolation/file_interp.pro
===================================================================
--- /trunk/SRC/Interpolation/file_interp.pro	(revision 472)
+++ /trunk/SRC/Interpolation/file_interp.pro	(revision 473)
@@ -29,4 +29,6 @@
                         , DIVX = divx, DIVY = divy, OUTMASK_IND = outmask_ind $
                         , GETHAN = gethan, LETHAN = lethan, SET_OUTMSKVAL = set_outmskval $
+                        , DATA_SMWIN = data_smwin, DATA_NSMOOTH = data_nsmooth $
+                        , EXTRAP_SMWIN = extrap_smwin, EXTRAP_NSMOOTH = extrap_nsmooth $
                         , _EXTRA = ex
 ;
@@ -34,10 +36,13 @@
 ;
 ; for byte, short and long, convert to double before extrapolation and interpolation
-  intype = size(data, /type)
+  sz = size(data)
+  nx = sz[1]
+  ny = sz[2]
+  intype = sz[3]
   if intype LE 3 THEN data = double(temporary(data))
 ;
 ; take care of NaN values
   nanmask = finite(data)
-  totnanmask = total(nanmask)
+  totnanmask = total(nanmask, /integer)
   IF totnanmask EQ 0 THEN return, !values.f_nan
   IF totnanmask NE n_elements(nanmask) THEN BEGIN
@@ -57,8 +62,29 @@
     IF mask[0] NE -1 THEN mask = temporary(missmask) * mask ELSE mask = temporary(missmask)
   ENDIF
-
 ; extrapolation
   IF keyword_set(smooth) THEN data = extrapsmooth(temporary(data), mask, /x_periodic, _extra = ex) $
-  ELSE data = extrapolate(temporary(data), mask, /x_periodic, _extra = ex)
+  ELSE data = extrapolate(temporary(data), mask, /x_periodic, SMWIN = extrap_smwin, NSMOOTH = extrap_nsmooth, _extra = ex)
+; smooth
+  IF keyword_set(data_smwin) THEN BEGIN
+; add extra bands to avoid edge errors...
+    one = replicate(1, data_smwin)
+;    
+;   nx-smwin   nx-1    0       smwin-1                      nx-smwin      nx-1    0       smwin-1
+;     |----------|     |----------|------------------------------|----------|     |----------|
+;     0      smwin-1  smwin   2*smwin-1                          nx  nx+smwin-1  nx+smwin nx+2*smwin-1 
+; define boundaries (extra colomns and rows)
+    data = [ data[nx-data_smwin:nx-1, *], data, data[0:data_smwin-1, *] ]
+    data = [ [data[*, 0]#one], [data], [data[*, ny-1]#one] ]
+    FOR i = 1, data_nsmooth DO BEGIN 
+      data = smooth( temporary(data), data_smwin )
+; update boundaries
+      data[0:data_smwin-1, *] = data[nx:nx+data_smwin-1, *]
+      data[nx+data_smwin:nx+2*data_smwin-1, *] =  data[data_smwin:2*data_smwin-1, *]
+      data[*, 0:data_smwin-1] = data[*, data_smwin]#one
+      data[*, ny+data_smwin:ny+2*data_smwin-1] = data[*, ny+data_smwin-1]#one
+    ENDFOR  
+; keep only the interior domain
+    data = (temporary(data))[data_smwin:nx+data_smwin-1, data_smwin:ny+data_smwin-1]
+  ENDIF
 ; interpolation
   IF method EQ 'boxmean' THEN BEGIN
@@ -314,4 +340,6 @@
                  , OUTXAXISNAME = outxaxisname, OUTYAXISNAME = outyaxisname $
                  , GETHAN = gethan, LETHAN = lethan, SET_OUTMSKVAL = set_outmskval $
+                 , DATA_SMWIN = data_smwin, DATA_NSMOOTH = data_nsmooth $
+                 , EXTRAP_SMWIN = extrap_smwin, EXTRAP_NSMOOTH = extrap_nsmooth $
                  , _EXTRA = ex
 ;
@@ -555,5 +583,8 @@
                                                   , SET_OUTMSKVAL = outmiss[i] $
                                                   , DIVX = divx, DIVY = divy, OUTMASK_IND = outmask_ind $
-                                                  , GETHAN = gethan, LETHAN = lethan, _extra = ex)
+                                                  , GETHAN = gethan, LETHAN = lethan $
+                                                  , DATA_SMWIN = data_smwin, DATA_NSMOOTH = data_nsmooth $
+                                                  , EXTRAP_SMWIN = extrap_smwin, EXTRAP_NSMOOTH = extrap_nsmooth $
+                                                  , _extra = ex)
               IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout)
               ncdf_varput, outid, outvarid[i], temporary(data)
@@ -575,5 +606,8 @@
                                                     , SET_OUTMSKVAL = outmiss[i] $
                                                     , DIVX = divx, DIVY = divy, OUTMASK_IND = outmask_ind $
-                                                    , GETHAN = gethan, LETHAN = lethan, _extra = ex)
+                                                    , GETHAN = gethan, LETHAN = lethan $
+                                                    , DATA_SMWIN = data_smwin, DATA_NSMOOTH = data_nsmooth $
+                                                    , EXTRAP_SMWIN = extrap_smwin, EXTRAP_NSMOOTH = extrap_nsmooth $
+                                                    , _extra = ex)
                 IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout)
                 ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt
@@ -596,5 +630,8 @@
                                                       , SET_OUTMSKVAL = outmiss[i] $
                                                       , DIVX = divx, DIVY = divy, OUTMASK_IND = outmask_ind $
-                                                      , GETHAN = gethan, LETHAN = lethan, _extra = ex)
+                                                      , GETHAN = gethan, LETHAN = lethan $
+                                                      , DATA_SMWIN = data_smwin, DATA_NSMOOTH = data_nsmooth $
+                                                      , EXTRAP_SMWIN = extrap_smwin, EXTRAP_NSMOOTH = extrap_nsmooth $
+                                                      , _extra = ex)
                   IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout)
                   ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt
