Index: trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro
===================================================================
--- trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro	(revision 267)
+++ 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
