Index: /trunk/SRC/Interpolation/compute_fromirr_bilinear_weigaddr.pro
===================================================================
--- /trunk/SRC/Interpolation/compute_fromirr_bilinear_weigaddr.pro	(revision 270)
+++ /trunk/SRC/Interpolation/compute_fromirr_bilinear_weigaddr.pro	(revision 271)
@@ -40,5 +40,5 @@
 ; @restrictions
 ;  -  the input grid must be an "irregular 2D grid", defined as a grid made
-;  of quadrilateral cells which corners positions are defined with olonin and olat
+;  of quadrilateral cells
 ;  -  We supposed the data are located on a sphere, with a periodicity along
 ;  the longitude
@@ -71,28 +71,38 @@
   IF n_elements(omsk) EQ 1 AND omsk[0] EQ -1 THEN BEGIN
     omsk = replicate(1b, jpio, jpjo)
-   IF jpio EQ 182 AND jpjo EQ 149 THEN BEGIN
-      lontmp = (olonin[1:180, *] + 3600) MOD 360
-      lattmp = olat[1:180, *]
-      bad = abs(abs(lontmp - shift(lontmp, 1, 0)) - 180) LT 176 $
-            OR  abs(abs(lontmp - shift(lontmp, 0, 1)) - 180) LT 176 $
-            OR  abs(abs(lontmp - shift(lontmp, 1, 1)) - 180) LT 176 $
-            OR  abs(abs(lattmp - shift(lattmp, 1, 0)) - 180) LT 176 $
-            OR  abs(abs(lattmp - shift(lattmp, 0, 1)) - 180) LT 176 $
-            OR  abs(abs(lattmp - shift(lattmp, 1, 1)) - 180) LT 176
-      bad = bad AND lattmp LT 50
-      omsk[1:180, 1:148] = 1b - bad[*, 1:148]
-      omsk[0, *] = omsk[180, *]
-      omsk[181, *] = omsk[1, *]
-    ENDIF ELSE omsk = replicate(1b, jpio, jpjo)
-  ENDIF
-  IF n_elements(amsk) EQ 1 AND amsk[0] EQ -1 THEN amsk = replicate(1b, jpia, jpja)
-  IF n_elements(omsk) NE jpio*jpjo THEN BEGIN
-    ras = report('input grid mask do not have the good size')
-    stop
-  ENDIF
-  IF n_elements(amsk) NE jpia*jpja THEN BEGIN
-    ras = report('output grid mask do not have the good size')
-    stop
-  ENDIF
+; if this is ORCA2 grid...
+    IF (jpio EQ 180 OR jpio EQ 182) AND (jpjo EQ 149  OR jpjo EQ 148  OR jpjo EQ 147 ) THEN BEGIN
+; we look for ill defined cells.
+      IF jpio EQ 182 THEN lontmp = olonin[1:180, *] ELSE lontmp = olonin
+; longitudinal size of the cells...
+      a = (lontmp-shift(lontmp, 1, 0))
+      d1 = 0.5 * max( [[[a]], [[360+a]]] MOD 360, dimension = 3)
+      a = (lontmp-shift(lontmp, 1, 1))
+      d2 = 0.5 * max( [[[a]], [[360+a]]] MOD 360, dimension = 3)
+      a = (shift(lontmp, 0, 1)-shift(lontmp, 1, 0))
+      d3 = 0.5 * max( [[[a]], [[360+a]]] MOD 360, dimension = 3)
+      a = (shift(lontmp, 0, 1)-shift(lontmp, 1, 1))
+      d4 = 0.5 * max( [[[a]], [[360+a]]] MOD 360, dimension = 3)
+      md = [[[d1]], [[d2]], [[d3]], [[d4]]]
+      bad = max(md, dimension = 3) GE 1.5
+      bad = (bad + shift(bad, -1, -1) + shift(bad, 0, -1) + shift(bad, -1, 0)) < 1
+      IF jpio EQ 182 THEN BEGIN
+        omsk[1:180, 80:120] = 1b - bad[*, 80:120]
+        omsk[0, *] = omsk[180, *]
+        omsk[181, *] = omsk[1, *]
+      ENDIF ELSE omsk[*, 80:120] = 1b - bad[*, 80:120]
+    ENDIF
+  ENDIF ELSE BEGIN 
+    IF n_elements(omsk) NE jpio*jpjo THEN BEGIN
+      ras = report('input grid mask do not have the good size')
+      stop
+    ENDIF
+  ENDELSE 
+  IF n_elements(amsk) EQ 1 AND amsk[0] EQ -1 THEN amsk = replicate(1b, jpia, jpja) ELSE BEGIN 
+    IF n_elements(amsk) NE jpia*jpja THEN BEGIN
+      ras = report('output grid mask do not have the good size')
+      stop
+    ENDIF
+  ENDELSE 
 ;
 ; longitude, between 0 and 360
@@ -175,8 +185,8 @@
 ; ORCA cases : orca grid is irregular only northward of 40N
         CASE 1 OF
-          jpio EQ 92   AND (jpjo EQ 76   OR jpjo EQ 75   OR jpjo EQ 74  ):onsphere = yy GT 40
-          jpio EQ 180  AND (jpjo EQ 149  OR jpjo EQ 148  OR jpjo EQ 147 ):onsphere = yy GT 40
-          jpio EQ 720  AND (jpjo EQ 522  OR jpjo EQ 521  OR jpjo EQ 520 ):onsphere = yy GT 40
-          jpio EQ 1440 AND (jpjo EQ 1021 OR jpjo EQ 1020 OR jpjo EQ 1019):onsphere = yy GT 40
+          (jpio EQ 90 OR jpio EQ 92) AND (jpjo EQ 76   OR jpjo EQ 75   OR jpjo EQ 74  ):onsphere = yy GT 40
+          (jpio EQ 180 OR jpio EQ 182) AND (jpjo EQ 149  OR jpjo EQ 148  OR jpjo EQ 147 ):onsphere = yy GT 40
+          (jpio EQ 720 OR jpio EQ 722)  AND (jpjo EQ 522  OR jpjo EQ 521  OR jpjo EQ 520 ):onsphere = yy GT 40
+          (jpio EQ 1440 OR jpio EQ 1442) AND (jpjo EQ 1021 OR jpjo EQ 1020 OR jpjo EQ 1019):onsphere = yy GT 40
           ELSE:onsphere = 1
         ENDCASE
@@ -233,5 +243,5 @@
           ELSE: BEGIN
 ; we keep its address
-        foraddr[n] = ind
+            foraddr[n] = ind
 ; keep the new coordinates
             forweight[n, 0] = xy[0]
@@ -274,7 +284,7 @@
   a = reform(forweight[*, 0], 1, nawater)
   b = reform(forweight[*, 1], 1, nawater)
-  forweight =  -1 ; free memory
+  forweight =  -1               ; free memory
   newaweig = [(1-a)*(1-b), (1-b)*a, a*b, (1-a)*b]
-  a = -1 &  b = -1 ; free memory
+  a = -1 &  b = -1              ; free memory
 ; mask the weight to suppress the corner located on land
   newaweig = newaweig*((omsk)[newaaddr])
Index: /trunk/SRC/Interpolation/extrapolate.pro
===================================================================
--- /trunk/SRC/Interpolation/extrapolate.pro	(revision 270)
+++ /trunk/SRC/Interpolation/extrapolate.pro	(revision 271)
@@ -16,8 +16,7 @@
 ; put -1 if input data are not masked
 ;
-; @param nb_iteration {in}{optional}{type=integer scalar}{default=10.E20}
+; @param nb_iteration {in}{optional}{type=integer}{default=large enough to fill everything}
 ; Maximum number of iterations done in the extrapolation process. If there
 ; is no more masked values we exit extrapolate before reaching nb_iteration
-; (to be sure to fill everything, you can use a very large value)
 ;
 ; @keyword X_PERIODIC {type=scalar, 0 or 1}{default=0}
@@ -32,4 +31,7 @@
 ; @keyword GE0 {type=scalar 0 or 1}{default=0}
 ; put 1 to force the extrapolated values to be larger than 0, same as using minval=0.
+;
+; @keyword 
+; _EXTRA to be able to call extrapolate with _extra keyword
 ;
 ; @returns
@@ -54,13 +56,15 @@
 ;
 FUNCTION extrapolate, zinput, maskinput, nb_iteration, X_PERIODIC = x_periodic $
-                      , MINVAL = minval, MAXVAL = maxval, GE0 = ge0
+                      , MINVAL = minval, MAXVAL = maxval, GE0 = ge0, _EXTRA = ex
 ;
   compile_opt idl2, strictarrsubs
 ;
 ; check the number of iteration used in the extrapolation.
-  IF n_elements(nb_iteration) EQ 0 THEN nb_iteration = 10.E20
+  szin = size(zinput)
+  IF szin[0] NE 2 THEN return, -1. ELSE szin = szin[1:2]
+  nx = szin[0]
+  ny = szin[1]
+  IF n_elements(nb_iteration) EQ 0 THEN nb_iteration = max(szin)
   IF nb_iteration EQ 0 THEN return, zinput
-  nx = (size(zinput))[1]
-  ny = (size(zinput))[2]
 ; take care of the boundary conditions...
 ;
Index: /trunk/SRC/Interpolation/extrapsmooth.pro
===================================================================
--- /trunk/SRC/Interpolation/extrapsmooth.pro	(revision 270)
+++ /trunk/SRC/Interpolation/extrapsmooth.pro	(revision 271)
@@ -27,4 +27,7 @@
 ; put 1 to force the extrapolated values to be larger than 0, same as using minval=0.
 ;
+; @keyword 
+; _EXTRA to be able to call extrapsmooth with _extra keyword
+;
 ; @returns
 ; the extrapolated array with no more masked values
@@ -47,5 +50,5 @@
 ;-
 ;
-FUNCTION extrapsmooth, in, mskin, X_PERIODIC = x_periodic, MINVAL = minval, MAXVAL = maxval, GE0 = ge0
+FUNCTION extrapsmooth, in, mskin, X_PERIODIC = x_periodic, MINVAL = minval, MAXVAL = maxval, GE0 = ge0, _EXTRA = ex
 ;
   compile_opt strictarr, strictarrsubs
Index: /trunk/SRC/Interpolation/fromirr.pro
===================================================================
--- /trunk/SRC/Interpolation/fromirr.pro	(revision 270)
+++ /trunk/SRC/Interpolation/fromirr.pro	(revision 271)
@@ -49,4 +49,7 @@
 ; lonout, latout are used only to know the output domain size
 ;
+; @keyword 
+; _EXTRA to be able to call fromirr with _extra keyword
+;
 ; @returns
 ; 2D array the interpolated data
@@ -87,5 +90,5 @@
 ;
 FUNCTION fromirr, method, datain, lonin, latin, mskin, lonout, latout, mskout $
-                  , WEIG = weig, ADDR = addr
+                  , WEIG = weig, ADDR = addr, _EXTRA = ex
 ;
   compile_opt strictarr, strictarrsubs
Index: /trunk/SRC/Interpolation/fromreg.pro
===================================================================
--- /trunk/SRC/Interpolation/fromreg.pro	(revision 270)
+++ /trunk/SRC/Interpolation/fromreg.pro	(revision 271)
@@ -53,4 +53,7 @@
 ; of the input data when performing the interpolation.
 ;
+; @keyword 
+; _EXTRA to be able to call fromreg with _extra keyword
+;
 ; @returns
 ; 2D array the interpolated data
@@ -90,5 +93,5 @@
                   , WEIG = weig, ADDR = addr $
                   , NONORTHERNLINE = nonorthernline $
-                  , NOSOUTHERNLINE = nosouthernline
+                  , NOSOUTHERNLINE = nosouthernline, _EXTRA = ex
 ;
   compile_opt idl2, strictarrsubs
Index: /trunk/SRC/Interpolation/get_gridparams.pro
===================================================================
--- /trunk/SRC/Interpolation/get_gridparams.pro	(revision 270)
+++ /trunk/SRC/Interpolation/get_gridparams.pro	(revision 271)
@@ -2,9 +2,8 @@
 ;
 ; @file_comments
-; 1) extract from a NetCDF file the longitude, latitude, and their dimensions
+; Case 1: extract from a NetCDF file longitude and latitude arrays, their dimensions
 ; and make sure it is 1D or 2D arrays
 ;
-; or
-; 2) given longitude and latitude arrays, get their dimensions and make
+; Case 2: given longitude and latitude arrays, get their dimensions and make
 ; sure they are 1D or 2D arrays
 ;
@@ -14,49 +13,47 @@
 ; @examples
 ;
-; 1)
-; IDL> get_gridparams, file, lonname, latname, lon, lat, jpi, jpj, n_dimensions
-;
-; or
-;
-; 2)
+; Case 1:
+; IDL> get_gridparams, file name/id, lonname, latname, lon, lat, jpi, jpj, n_dimensions
+;
+; Case 2:
 ; IDL> get_gridparams, lon, lat, jpi, jpj, n_dimensions
 ;
 ; @param in1 {in}{required}
-; Case 1: the name of the netcdf file
-; Case 2: 1d or 2d arrays defining longitudes and latitudes.
-; Out: the variable that will contain the longitudes
+; Case 1: name or the id (returned by ncdf_open) of the netcdf file
+; Case 2: 1D or 2D arrays defining longitudes, will be forced to have
+;         n_dimensions dimensions when returned
 ;
 ; @param in2 {in}{required}
-; Case 1: the name of the variable that contains the longitude in the NetCDF file
-; Case 2: 1d or 2d arrays defining longitudes and latitudes.
-;         Note that these arrays are also outputs and can therefore be modified.
-; Out: the variable that will contain the latitudes
-;
-; @param in3 {in}{required}
-; Case 1: the name of the variable that contains the latitude in the NetCDF file
-; Case 2: the number of points in the longitudinal direction.
+; Case 1: name of the variable containing the longitude in the NetCDF file
+; Case 2: 1D or 2D arrays defining latitudes, will be forced to have
+;         n_dimensions dimensions when returned
+;
+; @param in3 
+; Case 1: name of the variable containing the latitude in the NetCDF file
+; Case 2: returned number of points in longitudinal direction.
 ;
 ; @param in4 {out}
-; Case 1: the number of points in the longitudinal direction
-; Case 2: the number of points in the latitudinal direction
-;
-; @param in5 {out}
-; Case 1: the number of points in the latitudinal direction
-; Case 2: 1 or 2 to specify if lon and lat should be 1D (jpi or jpj)
-; arrays or 2D arrays (jpi,jpj). Note that of  n_dimensions = 1, then the
-; grid must be regular (each longitude must be the same for all latitudes
-; and each latitude should be the same for all longitudes).
+; Case 1: returned longitudes array, with n_dimensions dimensions
+; Case 2: returned number of points in latitudinal direction
+;
+; @param in5
+; Case 1: returned latitudes array, with n_dimensions dimensions 
+; Case 2: input scalar (1 or 2) to specify if lon and lat should be returned 
+;         as 1D or 2D arrays. Note that if n_dimensions = 1, the grid must be
+;         regular (longitude and latitudes can be described as 1D arrays).
 ;
 ; @param in6 {out}
-; the variable that will contain the longitudes
+; Case 1: returned number of points in longitudinal direction.
 ;
 ; @param in7 {out}
-; the variable that will contain the latitudes
-;
-; @param in8 {out}
-; 1 or 2 to specify if lon and lat should be 1D (jpi or jpj)
-;
-; @keyword DOUBLE
-; use double precision to perform the computation
+; Case 1: returned number of points in latitudinal direction
+;
+; @param in8 {in}
+; Case 1: input scalar (1 or 2) to specify if lon and lat should be returned 
+;         as 1D or 2D arrays. Note that if n_dimensions = 1, the grid must be
+;         regular (longitude and latitudes can be described as 1D arrays).
+;
+; @keyword DOUBLE {default=0}{type=scalar: 0 or 1}
+; activate to force double precision for lon/lat arrays
 ;
 ; @examples
@@ -84,12 +81,14 @@
     8:BEGIN
 ; get longitude and latitude
-      IF file_test(in1) EQ 0 THEN BEGIN
-        ras = report('file ' + in1 + ' does not exist')
-        stop
-      ENDIF
-      cdfido = ncdf_open(in1)
+      IF size(in1, /type) EQ 7 THEN BEGIN
+        IF file_test(in1) EQ 0 THEN BEGIN
+          ras = report('file ' + in1 + ' does not exist')
+          stop
+        ENDIF
+        cdfido = ncdf_open(in1)
+      ENDIF ELSE cdfido = in1
       ncdf_varget, cdfido, in2, lon
       ncdf_varget, cdfido, in3, lat
-      ncdf_close, cdfido
+      IF size(in1, /type) EQ 7 THEN ncdf_close, cdfido
       n_dimensions = in8
     END
Index: /trunk/SRC/ReadWrite/ncdf_getaxis.pro
===================================================================
--- /trunk/SRC/ReadWrite/ncdf_getaxis.pro	(revision 270)
+++ /trunk/SRC/ReadWrite/ncdf_getaxis.pro	(revision 271)
@@ -5,5 +5,5 @@
 ;
 ; @categories
-; Reading
+; Read NetCDF file
 ;
 ; @param cdfid {in}{required}{type=scalar}
@@ -29,16 +29,20 @@
 ;
 ; @keyword XDIMNAME {default='longitude', 'lon', 'x', 'longitude*', 'lon*', 'x*', '*longitude*', '*lon*' or '*x*'}{type=scalar string}
-; A string giving the name of the x dimension
+; A string giving the name of the x dimension or/and a named variable
+; in which x dimension name is returned.
 ;
 ; @keyword YDIMNAME {default='latitude', 'lat', 'y', 'latitude*', 'lat*', 'y*', 'eta_*', '*latitude*', '*lat*', '*y*'}{type=scalar string}
-; A string giving the name of the y dimension
+; A string giving the name of the y dimension or/and a named variable
+; in which y dimension name is returned.
 ;
 ; @keyword XAXISNAME {default='x', 'longitude', 'nav_lon', 'lon', 'lon_rho' or 'NbLongitudes'}{type=scalar string}
 ; A string giving the name of the variable in the file
-; that contains the [xyz]axis.
+; that contains the x axis or/and a named variable
+; in which this variable name is returned.
 ;
 ; @keyword YAXISNAME {default='y', 'latitude', 'nav_lat','lat', 'lat_rho' or 'NbLatitudes'}{type=scalar string}
 ; A string giving the name of the variable in the file
-; that contains the [xyz]axis.
+; that contains the y axis or/and a named variable
+; in which this variable name is returned.
 ;
 ; @keyword XYINDEX {default=0}{type=scalar: 0 or 1}
@@ -47,6 +51,4 @@
 ; x/yaxis = keyword_set(start1) + findgen(jpi/jpj)
 ;
-; @keyword XYINDEX {default=0}{type=scalar: 0 or 1}
-;
 ; @keyword _EXTRA
 ; Used to be able to call ncdf_getaxis with _extra
@@ -60,5 +62,5 @@
 ;-
 ;
-PRO ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $
+PRO ncdf_getaxis, fileid, dimidx, dimidy, xaxis, yaxis $
                   , XAXISNAME = xaxisname, YAXISNAME = yaxisname $
                   , XDIMNAME = xdimname, YDIMNAME = ydimname $
@@ -67,5 +69,6 @@
   compile_opt idl2, strictarrsubs
 ;
-
+; should we open the file?
+  IF size(fileid, /type) EQ 7 THEN cdfid = ncdf_open(fileid) ELSE cdfid = fileid
 ; what is inside the file
   inside = ncdf_inquire(cdfid)
@@ -97,4 +100,5 @@
                     , '''longitude'', ''nav_lon'', ''lon'', ''lon_rho'', ''nblongitudes''' $
                     , ' we use a fake xaxis based on x dimension size (or use XAXISNAME keyword)'], /simple)
+    xaxisname = 'Not Found'
 ; try to get the dimension corresponding to x
 ; roms file?
@@ -125,12 +129,14 @@
         ENDELSE
       ENDCASE
-    ENDIF
-    romsgrid = 0b
+      romsgrid = 0b
+    ENDIF ELSE romsgrid = 1b
   ENDIF ELSE BEGIN
     romsgrid = strmid(namevar[xvarid], 0, 4) EQ 'lon_'
     xinq = ncdf_varinq(cdfid, xvarid)
+    xaxisname = xinq.name
     dimidx = xinq.dim[0]
     IF xinq.ndims GE 2 THEN ncdf_diminq, cdfid, xinq.dim[1], blabla, jpjfromx
   ENDELSE
+  IF arg_present(xdimname) THEN ncdf_diminq, cdfid, dimidx,  xdimname, jpifromx
 ;
   IF arg_present(xaxis) THEN BEGIN
@@ -162,4 +168,5 @@
                     , '''latitude'', ''nav_lat'', ''lat'', ''lat_rho'', ''nblatitudes''' $
                     , ' we use a fake yaxis based on y dimension size (or use YAXISNAME keyword)'], /simple)
+    yaxisname = 'Not Found'
 ; try to get the dimension corresponding to y
 ; roms file?
@@ -193,4 +200,5 @@
   ENDIF ELSE BEGIN
     yinq = ncdf_varinq(cdfid, yvarid)
+    yaxisname = yinq.name
     IF yinq.ndims GE 2 THEN BEGIN
       ncdf_diminq, cdfid, yinq.dim[0], blabla, jpifromy
@@ -198,4 +206,5 @@
     ENDIF ELSE dimidy = yinq.dim[0]
   ENDELSE
+  IF arg_present(ydimname) THEN ncdf_diminq, cdfid, dimidy,  ydimname, jpjfromy
 ;
   IF arg_present(yaxis) THEN BEGIN
@@ -224,4 +233,6 @@
   ENDIF
 
+  IF size(fileid, /type) EQ 7 THEN ncdf_close, cdfid
+
   return
 END
Index: unk/SRC/ReadWrite/ncdf_timeget.pro
===================================================================
--- /trunk/SRC/ReadWrite/ncdf_timeget.pro	(revision 270)
+++ 	(revision )
@@ -1,87 +1,0 @@
-;+
-;
-; @file_comments
-; get the time axis from a netcdf_file and transforms it in
-; Julian days of IDL.
-;
-; @categories
-; Reading
-;
-; @param CDFID {in}{required}
-; the ID of the ncdf_file, which is already open
-;
-; @param TIMEID {in}{required}
-; the ID or the name of the variable which describe the calendar
-;
-; @keyword YYYYMMDD
-; active to obtain the date as a long integer with
-; the format YearYearYearYearMonthMonthDayDay
-;
-; @keyword _EXTRA
-; the keyword parameters of ncdf_varget
-;
-; @returns
-; a long array of IDL Julian days
-;
-; @restrictions
-; the calendar variable must have the units attribute
-; following the syntax bellow:
-;
-; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
-; time_counter:units = "hours since 0001-01-01 00:00:00" ;
-; time_counter:units = "days since 1979-01-01 00:00:00" ;
-; time_counter:units = "months since 1979-01-01 00:00:00" ;
-; time_counter:units = "years since 1979-01-01 00:00:00" ;
-;
-; @history
-; Sebastien Masson (smasson\@lodyc.jussieu.fr)
-;                      June 2001
-; @version
-; $Id$
-;-
-;
-FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _EXTRA = ex
-;
-  compile_opt idl2, strictarrsubs
-;
-
-   insidetime=ncdf_varinq(cdfid,timeid)
-   if insidetime.natts NE 0 then begin
-      attnames = strarr(insidetime.natts)
-      for attiq=0,insidetime.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,timeid,attiq))
-   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
-; reading of the time axis
-   ncdf_varget, cdfid, timeid, time, _extra = ex
-;
-; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
-; time_counter:units = "hours since 0001-01-01 00:00:00" ;
-; time_counter:units = "days since 1979-01-01 00:00:00" ;
-; time_counter:units = "months since 1979-01-01 00:00:00" ;
-; time_counter:units = "years since 1979-01-01 00:00:00" ;
-;
-   if (where(attnames EQ 'units'))[0] NE -1 then begin
-      ncdf_attget,cdfid,timeid,'units',value
-      value = strtrim(strcompress(string(value)), 2)
-      words = str_sep(value, ' ')
-      unite = words[0]
-      start = str_sep(words[2], '-')
-      case strlowcase(unite) of
-         'seconds':time = julday(start[1], start[2], start[0])+time/(long(24)*3600)
-         'hours':time = julday(start[1], start[2], start[0])+time/long(24)
-         'days':time = julday(start[1], start[2], start[0])+time
-         'months':BEGIN
-            for t = 0, n_elements(time)-1  do begin
-               time[t] = julday(start[1]+time[t], start[2], start[0])
-            endfor
-         END
-         'years':BEGIN
-            for t = 0, n_elements(time)-1  do begin
-               time[t] = julday(start[1], start[2], start[0]+time[t])
-            endfor
-         END
-         ELSE:return, report('bad syntax of the units attribut of the variable '+timeid)
-      ENDCASE
-   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
-   if keyword_set(yyyymmdd) then time = jul2date(time)
-   return, time
-end
Index: /trunk/SRC/ToBeReviewed/HOPE/read_hope.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/HOPE/read_hope.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/HOPE/read_hope.pro	(revision 271)
@@ -452,5 +452,5 @@
   timename = strlowcase((tag_names(dimlist))[wathinside.recdim])
 ; read the time axis in julina days
-  time = ncdf_timeget(cdfid, timename)
+  time = ncdf_gettime(filename, cdfid)
 ; update the dimlist structure
   dimlist.(wathinside.recdim) = time
Index: /trunk/SRC/ToBeReviewed/INIT/initncdf.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/INIT/initncdf.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/INIT/initncdf.pro	(revision 271)
@@ -11,28 +11,7 @@
 ; A string giving the name of the NetCdf file
 ;
-; @keyword INVMASK {default=0}{type=scalar: 0 or 1}
-; Inverse the land/sea mask (that should have 0/1 values for land/sea): mask = 1-mask
-;
-; @keyword MASKNAME {type=string}
-; A string giving the name of the variable in the file
-; that contains the land/sea mask
-;
-; @keyword MISSING_VALUE {type=scalar}
-; To define (or redefine if the attribute is
-; already existing) the missing values used with USEASMASK
-; keyword
-;
 ; @keyword START1 {default=0}{type=scalar: 0 or 1}
 ; Index the axis from 1 instead of 0 when using
 ; /xyindex and/or /zindex
-;
-; @keyword USEASMASK {type=scalar string}
-; A string giving the name of the variable in the file
-; that will be used to build the land/sea mask. In this case the
-; mask is based on the first record (if record dimension
-; exists). The mask is build according to :
-;    1 the keyword missing_value if existing
-;    2 the attribute 'missing_value' if existing
-;    3 NaN values if existing
 ;
 ; @keyword ZAXISNAME {default='z', 'level', 'lev', 'depth...'}{type=scalar string}
@@ -52,6 +31,6 @@
 ;
 ; @keyword _EXTRA
-; Used to pass keywords to <pro>computegrid</pro> and 
-; <pro>ncdf_getaxis</pro>
+; Used to pass keywords to <pro>computegrid</pro>, 
+; <pro>ncdf_getaxis</pro>, <pro>ncdf_getmask</pro> and <pro>isafile</pro>
 ;
 ; @uses
@@ -77,7 +56,5 @@
 ;
 PRO initncdf, ncfilein $
-              , ZAXISNAME = zaxisname, MASKNAME = maskname $
-              , INVMASK = invmask, USEASMASK = useasmask $
-              , MISSING_VALUE = missing_value, START1 = start1 $
+              , ZAXISNAME = zaxisname, START1 = start1 $
               , XYINDEX = xyindex, ZINDEX = zindex $
               , _EXTRA = ex
@@ -100,11 +77,4 @@
 ; what is inside the file
   inside = ncdf_inquire(cdfid)
-;------------------------------------------------------------
-; name of all dimensions
-  namedim = strarr(inside.ndims)
-  for dimiq = 0, inside.ndims-1 do begin
-    ncdf_diminq, cdfid, dimiq, tmpname, value
-    namedim[dimiq] = strlowcase(tmpname)
-  ENDFOR
 ;----------------------------------------------------------
 ; name of the variables
@@ -149,98 +119,11 @@
 ;----------------------------------------------------------
 ; mask
-  IF NOT (keyword_set(maskname) OR keyword_set(useasmask)) AND keyword_set(romsgrid) THEN maskname = 'mask_rho'
-  CASE 1 OF
-    keyword_set(maskname):BEGIN
-      mskid = (where(namevar EQ strlowcase(maskname)))[0]
-      if mskid NE -1 THEN BEGIN
-        mskinq = ncdf_varinq(cdfid, mskid)
-; is the mask variable containing the record dimension?
-        withrcd = (where(mskinq.dim EQ inside.recdim))[0]
-        IF withrcd NE -1 THEN BEGIN
-; in order to read only the first record
-; we need to get the size of each dimension
-          count = replicate(1L, mskinq.ndims)
-          FOR d = 0, mskinq.ndims -1 DO BEGIN
-            IF d NE withrcd THEN BEGIN
-              ncdf_diminq, cdfid, mskinq.dim[d], name, size
-              count[d] = size
-            ENDIF
-          ENDFOR
-; read the variable for the first record
-          ncdf_varget, cdfid, mskid, tmask, count = count
-        ENDIF ELSE ncdf_varget, cdfid, mskid, tmask
-; check if we need to applay add_offset and scale factor
-        FOR a = 0, mskinq.natts-1 DO BEGIN
-          attname = ncdf_attname(cdfid, mskid, a)
-          CASE strlowcase(attname) OF
-            'add_offset':ncdf_attget, cdfid, mskid, attname, add_offset
-            'scale_factor':ncdf_attget, cdfid, mskid, attname, scale_factor
-            ELSE:
-          ENDCASE
-        ENDFOR
-        IF n_elements(scale_factor) NE 0 THEN tmask = tmask*scale_factor
-        IF n_elements(add_offset) NE 0 THEN tmask = tmask+add_offset
-        if keyword_set(invmask) then tmask = 1-tmask
-        tmask = byte(round(tmask))
-      ENDIF ELSE tmask = -1
-    END
-;..................
-    keyword_set(useasmask):BEGIN
-      mskid = (where(namevar EQ strlowcase(useasmask)))[0]
-      if mskid NE -1 THEN BEGIN
-        mskinq = ncdf_varinq(cdfid, mskid)
-; is the mask variable containing the record dimension?
-        withrcd = (where(mskinq.dim EQ inside.recdim))[0]
-        IF withrcd NE -1 THEN BEGIN
-; in order to read only the first record
-; we need to get the size of each dimension
-          count = replicate(1L, mskinq.ndims)
-          FOR d = 0, mskinq.ndims -1 DO BEGIN
-            IF d NE withrcd THEN BEGIN
-              ncdf_diminq, cdfid, mskinq.dim[d], name, size
-              count[d] = size
-            ENDIF
-          ENDFOR
-; read the variable for the first record
-          ncdf_varget, cdfid, mskid, tmask, count = count
-        ENDIF ELSE ncdf_varget, cdfid, mskid, tmask
-; check if we need to applay add_offset and scale factor
-        FOR a = 0, mskinq.natts-1 DO BEGIN
-          attname = ncdf_attname(cdfid, mskid, a)
-          CASE strlowcase(attname) OF
-            'add_offset':ncdf_attget, cdfid, mskid, attname, add_offset
-            'scale_factor':ncdf_attget, cdfid, mskid, attname, scale_factor
-            'missing_value':IF n_elements(missing_value) EQ 0 THEN $
-               ncdf_attget, cdfid, mskid, attname, missing_value
-            ELSE:
-          ENDCASE
-        ENDFOR
-        IF n_elements(scale_factor) NE 0 THEN tmask = tmask*scale_factor
-        IF n_elements(add_offset) NE 0 THEN tmask = tmask+add_offset
-        IF n_elements(missing_value) NE 0 THEN BEGIN
-; we have to take care of the float accuracy
-          CASE 1 OF
-            missing_value GE 1.e6:tmask = tmask LT (missing_value-10)
-            missing_value LE -1.e6:tmask = tmask GT (missing_value-10)
-            abs(missing_value) LE 1.e-6:tmask = abs(tmask) GT 1.e-6
-            ELSE:tmask = tmask NE missing_value
-          ENDCASE
-          if keyword_set(invmask) then tmask = 1-tmask
-        ENDIF ELSE BEGIN
-          tmask = finite(tmask)
-          IF min(tmask) EQ 1 THEN BEGIN
-            ras = report( 'missing or nan values not found...')
-            tmask = -1
-          ENDIF
-        ENDELSE
-      ENDIF ELSE tmask = -1
-    END
-;..................
-    ELSE:tmask  = -1
-  ENDCASE
+  tmask = ncdf_getmask(cdfid, _extra = ex)
+;----------------------------------------------------------
 ;
   ncdf_close, cdfid
 ;
-; compute the grid
+;----------------------------------------------------------
+; call compute the grid
   if NOT keyword_set(zaxis) then BEGIN
     computegrid, xaxis = xaxis, yaxis = yaxis $
Index: /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro	(revision 271)
@@ -31,4 +31,8 @@
 ; Useless, defined for compatibility
 ;
+; @keyword ADDSCL_BEFORE {default=0}{type=scalar: 0 or 1}
+; put 1 to apply add_offset ad scale factor on data before looking for
+; missing values
+;
 ; @keyword BOXZOOM
 ; Contain the boxzoom on which we have to do the reading
@@ -41,5 +45,5 @@
 ;
 ; @keyword INIT {default=0}{type=scalar: 0 or 1}
-; To call automatically initncdf, filename and thus
+; To call automatically initncdf with filename as input argument and thus
 ; redefine all the grid parameters
 ;
@@ -62,10 +66,4 @@
 ; but only the array referring to the field.
 ;
-; @keyword TIMEVAR {type=string}
-; It define the name of the variable that
-; contains the time axis. This keyword can be useful if there
-; is no unlimited dimension or if the time axis selected by default
-; (the first 1D array with unlimited dimension) is not the good one.
-;
 ; @keyword ZETAFILENAME {default=FILENAME}{type=string}
 ; For ROMS outputs. The filename of the file where zeta variable should be read
@@ -75,5 +73,6 @@
 ;
 ; @keyword _EXTRA
-; Used to pass keywords
+; Used to pass keywords to <pro>isafile</pro>, <pro>initncdf</pro>,
+; <pro>ncdf_gettime</pro> and <pro>domdef</pro>
 ;
 ; @returns
@@ -95,5 +94,5 @@
 ;
 FUNCTION read_ncdf, name, beginning, ending, compatibility, BOXZOOM = boxzoom, FILENAME = filename $
-                    , PARENTIN = parentin, TIMESTEP = timestep, TIMEVAR = timevar $
+                    , PARENTIN = parentin, TIMESTEP = timestep, ADDSCL_BEFORE = addscl_before $
                     , TOUT = tout, NOSTRUCT = nostruct, CONT_NOFILL = CONT_NOFILL, INIT = init $
                     , GRID = grid, CALLITSELF = callitself $
@@ -115,5 +114,5 @@
 ;  print,filename
 ; is parent a valid widget ?
-  if keyword_set(parentin) then BEGIN
+  IF keyword_set(parentin) THEN BEGIN
     parent = long(parentin)
     parent = parent*widget_info(parent, /managed)
@@ -123,22 +122,22 @@
 ; Opening of the name file
 ;------------------------------------------------------------
-  if size(filename, /type) NE 7 then $
+  IF size(filename, /type) NE 7 THEN $
     return, report('read_ncdf cancelled')
   IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+filename+' > /dev/null'
   cdfid = ncdf_open(filename)
-  contient = ncdf_inquire(cdfid)
+  inq = ncdf_inquire(cdfid)
 ;------------------------------------------------------------
 ; we check if the variable name exists in the file.
 ;------------------------------------------------------------
-  if ncdf_varid(cdfid, name) EQ -1 then BEGIN
+  IF ncdf_varid(cdfid, name) EQ -1 THEN BEGIN
     ncdf_close, cdfid
     return, report('variable '+name+' !C not found in the file '+filename)
   ENDIF
-  varcontient = ncdf_varinq(cdfid, name)
-  IF varcontient.ndims LT 2 THEN return, report('read_ncdf cannot read scalar or 1D data')
+  varinq = ncdf_varinq(cdfid, name)
+  IF varinq.ndims LT 2 THEN return, report('read_ncdf cannot read scalar or 1D data')
 ; look for the dimension names
-  dimnames = strarr(varcontient.ndims)
-  FOR i = 0, varcontient.ndims-1 DO BEGIN
-    ncdf_diminq, cdfid, varcontient.dim[i], tmp, dimsize
+  dimnames = strarr(varinq.ndims)
+  FOR i = 0, varinq.ndims-1 DO BEGIN
+    ncdf_diminq, cdfid, varinq.dim[i], tmp, dimsize
     dimnames[i] = tmp
   ENDFOR
@@ -146,19 +145,21 @@
 ; shall we redefine the grid parameters
 ;------------------------------------------------------------
-  if keyword_set(init) THEN initncdf, filename, _extra = ex
+  IF keyword_set(init) THEN initncdf, filename, _extra = ex
 ;------------------------------------------------------------
 ; check the time axis and the debut and ending dates
 ;------------------------------------------------------------
-  if n_elements(beginning) EQ 0 then begin
+  IF n_elements(beginning) EQ 0 THEN BEGIN
     beginning = 0
     timestep = 1
-  endif
-  if keyword_set(timestep) then begin
-    firsttps = beginning[0]
-    if n_elements(ending) NE 0 then lasttps = ending[0] ELSE lasttps = firsttps
-    jpt = lasttps-firsttps+1
-    IF NOT keyword_set(callitself) then time = julday(1, 1, 1) + lindgen(jpt)
-  ENDIF ELSE BEGIN
-    if keyword_set(parent) then BEGIN
+  ENDIF
+; define time and jpt
+  CASE 1 OF
+    keyword_set(timestep):BEGIN 
+      firsttps = beginning[0]
+      IF n_elements(ending) NE 0 THEN lasttps = ending[0] ELSE lasttps = firsttps
+      jpt = lasttps-firsttps+1
+      IF NOT keyword_set(callitself) then time = julday(1, 1, 1) + lindgen(jpt)
+    END
+    keyword_set(parent):BEGIN 
       widget_control, parent, get_uvalue = top_uvalue
       filelist = extractatt(top_uvalue, 'filelist')
@@ -168,144 +169,39 @@
       date1 = date2jul(beginning[0])
       if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1
-      firsttps = where(time EQ date1) & firsttps = firsttps[0]
-      lasttps = where(time EQ date2) & lasttps = lasttps[0]
-    ENDIF ELSE BEGIN
-      IF keyword_set(timevar) THEN BEGIN
-        timeid = ncdf_varid(cdfid, timevar)
-        IF timeid EQ -1 THEN BEGIN
-          ncdf_close, cdfid
-          return, report('the file '+filename+' as no variable ' + timevar $
-                         + '. !C Use the TIMESTEP keyword')
-        endif
-        timecontient = ncdf_varinq(cdfid, timeid)
-        contient.recdim = timecontient.dim[0]
-      ENDIF ELSE BEGIN
-; we find the infinite dimension
-        timedim = contient.recdim
-        if timedim EQ -1 then BEGIN
-          ncdf_close, cdfid
-          return, report('the file '+filename+' as no infinite dimension. !C Use TIMESTEP or TIMEVAR keyword')
-        endif
-; we find the FIRST time axis
-        timeid = 0
-        repeat BEGIN       ; As long as we have not find a variable having only one dimension: the infinite one
-          timecontient = ncdf_varinq(cdfid, timeid) ; that the variable contain.
-          timeid = timeid+1
-        endrep until (n_elements(timecontient.dim) EQ 1 $
-                      AND timecontient.dim[0] EQ contient.recdim) $
-          OR timeid EQ contient.nvars+1
-;
-        if timeid EQ contient.nvars+1 then BEGIN
-          ncdf_close, cdfid
-          return, report('the file '+filename+' as no time axis variable. !C Use the TIMESTEP keyword')
-        endif
-        timeid = timeid-1
-      ENDELSE
-; we must found the time origin of the julian calendar used in the
-; time axis.
-; does the attribut units an dcalendar exist for the variable time axis?
-      if timecontient.natts EQ 0 then BEGIN
+      firsttps = (where(abs(time - date1) LT 0.9d/86400.d))[0]   ; beware of rounding errors...
+      lasttps = (where(abs(time - date2) LT 0.9d/86400.d))[0]
+      jpt = lasttps-firsttps+1
+    END
+    ELSE:BEGIN 
+      time = ncdf_gettime(filename, cdfid, caller = 'read_ncdf', err = err, _extra = ex)
+      IF n_elements(err) NE 0 THEN BEGIN
+        dummy = report(err)
         ncdf_close, cdfid
-        return, report('the variable '+timecontient.name+' has no attribut.!C Use the TIMESTEP keyword or add the attribut ''units'' to the variable')
-      endif
-      attnames = strarr(timecontient.natts)
-      for attiq = 0, timecontient.natts-1 do attnames[attiq] = ncdf_attname(cdfid, timeid, attiq)
-      if (where(attnames EQ 'units'))[0] EQ -1 then BEGIN
-        ncdf_close, cdfid
-        return, report('Attribut ''units'' not found for the variable '+timecontient.name+' !C Use the TIMESTEP keyword')
+        return, -1
       ENDIF
-;
-; now we try to find the attribut called calendar...
-; the attribute "calendar" exists?
-; If no, we suppose that the calendar is gregorian calendar
-;
-      if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN
-        ncdf_attget, cdfid, timeid, 'calendar', value
-        value = string(value)
-        CASE value OF
-          'noleap':key_caltype = 'noleap'
-          '360d':key_caltype = '360d'
-          'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
-          ELSE:BEGIN
-;            notused = report('Unknown calendar: '+value+', we use greg calendar.')
-            key_caltype = 'greg'
-          END
-        ENDCASE
-      ENDIF ELSE BEGIN
-;        notused = report('Unknown calendar, we use '+key_caltype+' calendar.')
-        IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
-      ENDELSE
-;
-; now we take acre of units attribut
-      ncdf_attget, cdfid, timeid, 'units', value
-;
-; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
-; time_counter:units = "hours since 0001-01-01 00:00:00" ;
-; time_counter:units = "days since 1979-01-01 00:00:00" ;
-; time_counter:units = "months since 1979-01-01 00:00:00" ;
-; time_counter:units = "years since 1979-01-01 00:00:00" ;
-;
-; we decript the "units" attribut to find the time origin
-      value = strtrim(strcompress(string(value)), 2)
-      mots = str_sep(value, ' ')
-      unite = mots[0]
-      unite = strlowcase(unite)
-      IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1)
-      IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7)
-      IF unite NE 'second' AND unite NE 'hour' AND unite NE 'day' $
-         AND unite NE 'month' AND unite NE 'year' THEN BEGIN
-        ncdf_close, cdfid
-        return, report('time units does not start with seconds/hours/days/months/years')
-      ENDIF
-      IF stregex(value, '[^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*', /boolean) EQ 0 THEN BEGIN
-        ncdf_close, cdfid
-        return, report('attribut units of time has not the good format: [^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*')
-      ENDIF
-      depart = str_sep(mots[2], '-')
-      ncdf_varget, cdfid, timeid, time
-      time = double(time)
-      case unite of
-        'second':time = julday(depart[1], depart[2], depart[0])+time/86400.d
-        'hour':time = julday(depart[1], depart[2], depart[0])+time/24.d
-        'day':time = julday(depart[1], depart[2], depart[0])+time
-        'month':BEGIN
-          if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m
-            time = julday(depart[1], depart[2], depart[0])+round(time*30) $
-            ELSE for t = 0, n_elements(time)-1 DO $
-            time[t] = julday(depart[1]+time[t], depart[2], depart[0])
-        END
-        'year':BEGIN
-          if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y
-            time = julday(depart[1], depart[2], depart[0])+round(time*365) $
-            ELSE for t = 0, n_elements(time)-1 do $
-            time[t] = julday(depart[1], depart[2], depart[0]+time[t])
-        END
-        ELSE:BEGIN
-          ncdf_close, cdfid
-          return, report('The "units" attribute of the time axis must be something like: !C "seconds since 0001-01-01 ..." !C "days since 1979-01-01 ..." !C "months since 1979-01-01 ..." !C "years since 1979-01-01 ..."')
-        end
-      ENDCASE
+; date1
       date1 = date2jul(beginning[0])
+; date2
       if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1
-      time = double(time)
-      firsttps = where(time GE date1) & firsttps = firsttps[0]
+; firsttps
+      firsttps = where(time GE (date1 - 0.9d/86400.d)) & firsttps = firsttps[0]
       if firsttps EQ -1 THEN BEGIN
         ncdf_close, cdfid
         return, report('date 1: '+strtrim(jul2date(date1), 1)+' is not found in the time axis.')
       ENDIF
-      lasttps = where(time LE date2)
-      if lasttps[0] EQ -1 THEN BEGIN
+; lasttps
+      lasttps = where(time LE (date2 + 0.9d/86400.d)) & lasttps = lasttps[n_elements(lasttps)-1]
+      if lasttps EQ -1 THEN BEGIN
         ncdf_close, cdfid
         return, report('the time axis has no date before date 2: '+strtrim(jul2date(date2), 1))
       endif
-      lasttps = lasttps[n_elements(lasttps)-1]
       if lasttps LT firsttps then BEGIN
         ncdf_close, cdfid
         return, report('the time axis has no dates between date1 and  date 2: '+strtrim(jul2date(date1), 1)+' '+strtrim(jul2date(date2), 1))
       endif
-    ENDELSE
-    time = time[firsttps:lasttps]
-    jpt = lasttps-firsttps+1
-  ENDELSE
+      time = time[firsttps:lasttps]
+      jpt = lasttps-firsttps+1
+    END
+  ENDCASE
 ;------------------------------------------------------------
 ; Name of the grid on which the field refer to.
@@ -316,5 +212,5 @@
 ; are we in one of the case corresponding to ROMS conventions?
       CASE 1 OF
-        dimnames[2 <(varcontient.ndims-1)] EQ 's_w':vargrid = 'W'
+        dimnames[2 <(varinq.ndims-1)] EQ 's_w':vargrid = 'W'
         dimnames[0] EQ 'xi_rho' AND dimnames[1] EQ 'eta_rho':vargrid = 'T'
         dimnames[0] EQ 'xi_u'   AND dimnames[1] EQ 'eta_u'  :vargrid = 'U'
@@ -342,11 +238,7 @@
   ENDELSE
 ;---------------------------------------------------------------
-; call the init function ?
-;---------------------------------------------------------------
-
-;---------------------------------------------------------------
 ; redefinition of the  domain
 ;---------------------------------------------------------------
-  if keyword_set(tout) then begin
+  IF keyword_set(tout) THEN BEGIN
     nx = jpi
     ny = jpj
@@ -413,36 +305,11 @@
 ;---------------------------------------------------------------------
 ;---------------------------------------------------------------------
-; We define global variable joined with the variable.
+; We define common (cm_4data) variables associated with the variable.
 ;---------------------------------------------------------------------
 ; varname
   IF NOT keyword_set(callitself) THEN varname = name
-; varunit
-  if varcontient.natts NE 0 then begin
-    attnames = strarr(varcontient.natts)
-    for attiq = 0, varcontient.natts-1 do attnames[attiq] = ncdf_attname(cdfid, name, attiq)
-    lowattnames = strlowcase(attnames)
-;
-    found = (where(lowattnames EQ 'units'))[0]
-    IF found NE -1 then ncdf_attget, cdfid, name, attnames[found], value ELSE value = ''
-    IF NOT keyword_set(callitself) THEN varunit = strtrim(string(value), 2)
-;
-    found = (where(lowattnames EQ 'add_offset'))[0]
-    if found NE -1 then ncdf_attget, cdfid, name, attnames[found], add_offset ELSE add_offset = 0.
-;
-    found = (where(lowattnames EQ 'scale_factor'))[0]
-    if found NE -1 then ncdf_attget, cdfid, name, attnames[found], scale_factor ELSE scale_factor = 1.
-;
-    missing_value = 'no'
-    found = (where(lowattnames EQ '_fillvalue'))[0]
-    if found NE -1 then ncdf_attget, cdfid, name, attnames[found], missing_value
-    found = (where(lowattnames EQ 'missing_value'))[0]
-    if found NE -1 then ncdf_attget, cdfid, name, attnames[found], missing_value
-;
-  ENDIF ELSE BEGIN
-    IF NOT keyword_set(callitself) THEN varunit = ''
-    add_offset = 0.
-    scale_factor = 1.
-    missing_value = 'no'
-  ENDELSE
+; varunit and others...
+  ncdf_getatt, cdfid, name, add_offset = add_offset, scale_factor = scale_factor, missing_value = missing_value, units = units
+  IF NOT keyword_set(callitself) THEN varunit = units
 ; vardate
 ; We make a legible date in function of the specified language.
@@ -455,21 +322,19 @@
 ; We apply the value valmask on land points.
   if NOT keyword_set(cont_nofill) then begin
-    valmask = 1e20
+    valmask = 1.e20
     case 1 of
-      varcontient.ndims eq 2:BEGIN ;xy array
-        mask = mask[*, *, 0]
+      varinq.ndims eq 2:BEGIN ;xy array
+        earth = where(mask[*, *, 0] EQ 0)
+      END
+      varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] EQ -1:BEGIN ;xyz array
         earth = where(mask EQ 0)
       END
-      varcontient.ndims eq 3 AND (where(varcontient.dim EQ contient.recdim))[0] EQ -1:BEGIN ;xyz array
-        earth = where(mask EQ 0)
-      END
-      varcontient.ndims eq 3 AND (where(varcontient.dim EQ contient.recdim))[0] NE -1:BEGIN ;xyt array
-        mask = mask[*, *, 0]
-        earth = where(mask EQ 0)
+      varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1:BEGIN ;xyt array    
+        earth = where(mask[*, *, 0] EQ 0)
         if earth[0] NE -1 then BEGIN
           earth = earth#replicate(1, jpt)+replicate(nx*ny, n_elements(earth))#lindgen(jpt)
         END
       END
-      varcontient.ndims eq 4:BEGIN ;xyzt array
+      varinq.ndims eq 4:BEGIN ;xyzt array
         earth = where(mask EQ 0)
         if earth[0] NE -1 then BEGIN
@@ -477,25 +342,26 @@
         END
       END
-    endcase
+    ENDCASE
   ENDIF ELSE earth = -1
 ; we look for  missing_value
+; we apply add_offset, scale_factor and missing_value
+  IF keyword_set(addscl_before) THEN BEGIN
+    if scale_factor NE 1 then res = temporary(res)*scale_factor
+    if add_offset NE 0 then res = temporary(res)+add_offset
+  ENDIF
   IF size(missing_value, /type) NE 7 then BEGIN
-    IF size(missing_value, /type) EQ 1 THEN BEGIN
-      missing_value = strlowcase(string(missing_value))
-      IF strmid(missing_value, 0, 1, /reverse_offset) EQ 'f' THEN $
-        missing_value = strmid(missing_value, 0, strlen(missing_value)-1)
-      IF isnumber(string(missing_value), tmp) EQ 1 THEN missing_value = tmp ELSE BEGIN
-        ras = report('Warning: missing value is not a number: ' + missing_value)
-        missing_value = - 1
-      ENDELSE
-    ENDIF
-;    if missing_value NE valmask then begin
-    if abs(missing_value) LT 1e6 then missing = where(res EQ missing_value) $
-    ELSE missing = where(abs(res) gt abs(missing_value)/10.)
-;    ENDIF ELSE missing = -1
+    IF finite(missing_value) EQ 1 THEN BEGIN
+        CASE 1 OF
+          missing_value GT 1.e6:missing = where(res GT missing_value-10.)
+          missing_value LT -1.e6:missing = where(res LT missing_value+10.)
+          abs(missing_value) LT 1.e-6:missing = where(res LT 1.e-6)
+          ELSE:missing = where(res EQ missing_value)
+        ENDCASE
+    ENDIF ELSE missing = where(finite(res) EQ 0)
   ENDIF ELSE missing = -1
-; we apply add_offset, scale_factor and missing_value
-  if scale_factor NE 1 then res = temporary(res)*scale_factor
-  if add_offset NE 0 then res = temporary(res)+add_offset
+  IF NOT keyword_set(addscl_before) THEN BEGIN
+    if scale_factor NE 1 then res = temporary(res)*scale_factor
+    if add_offset NE 0 then res = temporary(res)+add_offset
+  ENDIF
   if missing[0] NE -1 then res[temporary(missing)] = !values.f_nan
   if earth[0] NE -1 then res[temporary(earth)] = 1.e20
@@ -508,6 +374,6 @@
       ncdf_attget, cdfid, 'hc', hc, /global
 ; look for all variables names
-      allvarnames = strarr(contient.nvars)
-      FOR i = 0, contient.nvars-1 DO BEGIN
+      allvarnames = strarr(inq.nvars)
+      FOR i = 0, inq.nvars-1 DO BEGIN
         tmp = ncdf_varinq( cdfid, i)
         allvarnames[i] = tmp.name
Index: /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf_varget.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf_varget.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/LECTURE/read_ncdf_varget.pro	(revision 271)
@@ -97,5 +97,5 @@
 ;......................................................................
 ;......................................................................
-   varcontient.ndims eq 2:BEGIN ;xy array
+   varinq.ndims eq 2:BEGIN ;xy array
 ;......................................................................
 ;......................................................................
@@ -185,5 +185,5 @@
 ;......................................................................
 ;......................................................................
-   varcontient.ndims eq 3 AND (where(varcontient.dim EQ contient.recdim))[0] EQ -1:BEGIN ;xyz array
+   varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] EQ -1:BEGIN ;xyz array
 ;......................................................................
 ;......................................................................
@@ -276,5 +276,5 @@
 ;......................................................................
 ;......................................................................
-   varcontient.ndims eq 3 AND (where(varcontient.dim EQ contient.recdim))[0] NE -1:BEGIN ;xyt array
+   varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1:BEGIN ;xyt array
 ;......................................................................
 ;......................................................................
@@ -376,5 +376,5 @@
 ;......................................................................
 ;......................................................................
-   varcontient.ndims eq 4:BEGIN ;xyzt array
+   varinq.ndims eq 4:BEGIN ;xyzt array
 ;......................................................................
 ;......................................................................
@@ -481,10 +481,10 @@
 ; we apply reverse
   IF keyword_set(key_yreverse) AND ny NE 1 THEN BEGIN
-    IF varcontient.ndims - ((where(varcontient.dim EQ contient.recdim))[0] NE -1) EQ 2 THEN $
+    IF varinq.ndims - ((where(varinq.dim EQ inq.recdim))[0] NE -1) EQ 2 THEN $
        res = reverse(reform(res, nx, ny, jpt, /overwrite),  2) $
     ELSE res = reverse(reform(res, nx, ny, nz, jpt, /overwrite),  2)
   ENDIF
   if keyword_set(key_zreverse) AND nz NE 1 $
-     AND varcontient.ndims - ((where(varcontient.dim EQ contient.recdim))[0] NE -1) EQ 3 THEN $
+     AND varinq.ndims - ((where(varinq.dim EQ inq.recdim))[0] NE -1) EQ 3 THEN $
         res = reverse(reform(res, nx, ny, nz, jpt, /overwrite),  3)
 ;
Index: /trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro	(revision 271)
@@ -11,6 +11,6 @@
 ;
 ; @keyword _EXTRA
-; Used to pass keywords to <pro>isafile</pro> 
-; and <pro>ncdf_getaxis</pro>
+; Used to pass keywords to <pro>isafile</pro>, 
+; <pro>ncdf_getaxis</pro> and <pro>ncdf_gettime</pro>
 ;
 ; @returns
@@ -81,10 +81,10 @@
 ; What contains the file?
 ;------------------------------------------------------------
-  inside = ncdf_inquire(cdfid)  ;
+  inq = ncdf_inquire(cdfid)  ;
 ;------------------------------------------------------------
 ; name of all dimensions
 ;------------------------------------------------------------
-  namedim = strarr(inside.ndims)
-  for dimiq = 0, inside.ndims-1 do begin
+  namedim = strarr(inq.ndims)
+  for dimiq = 0, inq.ndims-1 do begin
     ncdf_diminq, cdfid, dimiq, tmpname, value
     namedim[dimiq] = strlowcase(tmpname)
@@ -98,11 +98,11 @@
 ;------------------------------------------------------------
 ; we keep only the variables containing at least x, y and time dimension (if existing...)
-  namevar = strarr(inside.nvars)
-  for varid = 0, inside.nvars-1 do begin
-    invar = ncdf_varinq(cdfid, varid) ; what contains the variable?
-    if (inter(invar.dim, dimidx))[0] NE -1 AND $
-       (inter(invar.dim, dimidy))[0] NE -1 AND $
-       ((where(invar.dim EQ inside.recdim))[0] NE -1 OR inside.recdim EQ -1) $
-    THEN namevar[varid] = invar.name
+  namevar = strarr(inq.nvars)
+  for varid = 0, inq.nvars-1 do begin
+    varinq = ncdf_varinq(cdfid, varid) ; what contains the variable?
+    if (inter(varinq.dim, dimidx))[0] NE -1 AND $
+       (inter(varinq.dim, dimidy))[0] NE -1 AND $
+       ((where(varinq.dim EQ inq.recdim))[0] NE -1 OR inq.recdim EQ -1) $
+    THEN namevar[varid] = varinq.name
   ENDFOR
   namevar = namevar[where(namevar NE '')]
@@ -117,9 +117,9 @@
 ; for each variable, look if we in one of the case corresponding to ROMS conventions?
     FOR i = 0, n_elements(namevar)-1 do begin
-      invar = ncdf_varinq(cdfid, namevar[i])
-      tmpnm = namedim[invar.dim]
+      varinq = ncdf_varinq(cdfid, namevar[i])
+      tmpnm = namedim[varinq.dim]
 ; are we in one of the case corresponding to ROMS conventions?
       CASE 1 OF
-        tmpnm[2 <(invar.ndims-1)] EQ 's_w':vargrid = 'W'
+        tmpnm[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W'
         tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T'
         tmpnm[0] EQ 'xi_u'   AND tmpnm[1] EQ 'eta_u'  :listgrid[i] = 'U'
@@ -152,130 +152,14 @@
 ; time axis
 ;------------------------------------------------------------
+  time = ncdf_gettime(fullname, cdfid, caller = 'scanfile', err = err, _extra = ex)
+  IF n_elements(err) NE 0 THEN BEGIN
+    dummy = report(err)
+    jpt = abs(time)
+    fakecal = 1
+  ENDIF ELSE jpt = n_elements(time) 
+; high frequency calendar: more than one element per day
+  IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0
   date0fk = date2jul(19000101)
-  IF inside.recdim EQ -1 THEN BEGIN
-    jpt = 1
-    time = date0fk
-    fakecal = 1
-  ENDIF ELSE BEGIN
-    ncdf_diminq, cdfid, inside.recdim, timedimname, jpt
-; we look for the variable containing the time axis
-; we look for the first variable having for only dimension inside.recdim
-    varid = 0
-    repeat BEGIN
-      IF varid LT inside.nvars THEN BEGIN
-        invar = ncdf_varinq(cdfid, varid)
-        varid = varid+1
-      ENDIF ELSE varid = 0
-    endrep until (n_elements(invar.dim) EQ 1 AND invar.dim[0] EQ inside.recdim) OR (varid EQ 0)
-    varid = varid-1
-;
-    CASE 1 OF
-      varid EQ -1:BEGIN
-        dummy = report('the file '+fullname+' has no time axis.!C we create a fake calendar ...')
-        fakecal = 1
-        time = date0fk + lindgen(1>jpt)
-      END
-      invar.natts EQ 0:BEGIN
-        dummy = report('the variable '+invar.name+' has no attribut.!C we create a fake calendar ...')
-        fakecal = 1
-        time = date0fk + lindgen(1>jpt)
-      END
-      ELSE:BEGIN
-;
-; we want to know which attributes are attached to the time variable...
-;
-        attnames = strarr(invar.natts)
-        for attiq = 0, invar.natts-1 do attnames[attiq] = ncdf_attname(cdfid, varid, attiq)
-        if (where(attnames EQ 'units'))[0] EQ -1 then BEGIN
-          dummy = report('Attribut ''units'' not found for the variable '+invar.name+'!C we create a fake calendar ...')
-          fakecal = 1
-          time = date0fk + lindgen(1>jpt)
-        ENDIF ELSE BEGIN
-; we read the time axis
-          ncdf_varget, cdfid, varid, time
-          time = double(time)
-          ncdf_attget, cdfid, varid, 'units', value
-; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
-; time_counter:units = "hours since 0001-01-01 00:00:00" ;
-; time_counter:units = "days since 1979-01-01 00:00:00" ;
-; time_counter:units = "months since 1979-01-01 00:00:00" ;
-; time_counter:units = "years since 1979-01-01 00:00:00" ;
-          value = strtrim(strcompress(string(value)), 2)
-          mots = str_sep(value, ' ')
-          unite = mots[0]
-          unite = strlowcase(unite)
-          IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1)
-          IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7)
-          err = 0
-          IF unite NE 'second' AND unite NE 'hour' AND unite NE 'day' $
-             AND unite NE 'month' AND unite NE 'year' THEN BEGIN
-            dummy = report('time units does not start with seconds/hours/days/months/years')
-            err = 1
-          ENDIF
-          IF stregex(value, '[^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*', /boolean) EQ 0 THEN BEGIN
-            dummy = report('attribut units of time has not the good format: [^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*')
-            err = 1
-          ENDIF
-          IF err GT 0 THEN BEGIN
-            fakecal = 1
-            time = date0fk + lindgen(1>jpt)
-          ENDIF ELSE BEGIN
-            debut = str_sep(mots[2], '-')
-;
-; now we try to find the attribut called calendar...
-; the attribute "calendar" exists?
-; If no, we suppose that the calendar is gregorian calendar
-;
-            if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN
-              ncdf_attget, cdfid, varid, 'calendar', value
-              value = string(value)
-              CASE value OF
-                'noleap':key_caltype = 'noleap'
-                '360d':key_caltype = '360d'
-                'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
-                ELSE:BEGIN
-;            notused = report('Unknown calendar: '+value+', we use greg calendar.')
-                  key_caltype = 'greg'
-                END
-              ENDCASE
-            ENDIF ELSE BEGIN
-;        notused = report('Unknown calendar, we use '+key_caltype+' calendar.')
-              IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'
-            ENDELSE
-;
-; BEWARE we have to get back the calendar attribute and ajust time by consequence...
-;
-;
-; We pass time in IDL julian days
-;
-            case unite of
-              'second':time = julday(debut[1], debut[2], debut[0])+time/86400.d
-              'hour':time = julday(debut[1], debut[2], debut[0])+time/24.d
-              'day':time = julday(debut[1], debut[2], debut[0])+time
-              'month':BEGIN
-                if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m
-                   time = julday(debut[1], debut[2], debut[0])+round(time*30) $
-                ELSE for t = 0, n_elements(time)-1 DO $
-                   time[t] = julday(debut[1]+time[t], debut[2], debut[0])
-              END
-              'year':BEGIN
-                if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y
-                   time = julday(debut[1], debut[2], debut[0])+round(time*365) $
-                ELSE for t = 0, n_elements(time)-1 do $
-                   time[t] = julday(debut[1], debut[2], debut[0]+time[t])
-              END
-            ENDCASE
-;
-; high frequency calendar: more than one element per day
-            IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0
-            date0fk = date2jul(19000101)
-            IF keyword_set(fakecal) THEN time = date0fk+lindgen(1>jpt) $
-            ELSE time = long(time)
-;
-          ENDELSE
-        ENDELSE
-      END
-    ENDCASE
-  ENDELSE
+  IF keyword_set(fakecal) THEN time = date0fk+lindgen(1 > jpt)
 ;------------------------------------------------------------
   ncdf_close, cdfid
Index: /trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro
===================================================================
--- /trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro	(revision 270)
+++ /trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro	(revision 271)
@@ -68,4 +68,5 @@
 ;
 @cm_4cal
+
 ; get back the calendar and its related informations
   winfo_id = widget_info(id, find_by_uname = 'infocal')
@@ -92,5 +93,5 @@
     day = value MOD 100L
 ; check that the date exists in the calendar
-  if (where(infowid.calendar EQ julday(month, day, year)))[0] EQ - 1 then return
+  if (where(abs(infowid.calendar - julday(month, day, year)) LT 1./86400.))[0] EQ - 1 then return
 ; update the value of infocal
     infowid.date = value
