Ignore:
Timestamp:
08/30/07 14:44:23 (17 years ago)
Author:
smasson
Message:

bugfix for interpolation from ORCA2 without mask

Location:
trunk/SRC/ToBeReviewed/WIDGET
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro

    r238 r271  
    1111; 
    1212; @keyword _EXTRA 
    13 ; Used to pass keywords to <pro>isafile</pro>  
    14 ; and <pro>ncdf_getaxis</pro> 
     13; Used to pass keywords to <pro>isafile</pro>,  
     14; <pro>ncdf_getaxis</pro> and <pro>ncdf_gettime</pro> 
    1515; 
    1616; @returns 
     
    8181; What contains the file? 
    8282;------------------------------------------------------------ 
    83   inside = ncdf_inquire(cdfid)  ; 
     83  inq = ncdf_inquire(cdfid)  ; 
    8484;------------------------------------------------------------ 
    8585; name of all dimensions 
    8686;------------------------------------------------------------ 
    87   namedim = strarr(inside.ndims) 
    88   for dimiq = 0, inside.ndims-1 do begin 
     87  namedim = strarr(inq.ndims) 
     88  for dimiq = 0, inq.ndims-1 do begin 
    8989    ncdf_diminq, cdfid, dimiq, tmpname, value 
    9090    namedim[dimiq] = strlowcase(tmpname) 
     
    9898;------------------------------------------------------------ 
    9999; we keep only the variables containing at least x, y and time dimension (if existing...) 
    100   namevar = strarr(inside.nvars) 
    101   for varid = 0, inside.nvars-1 do begin 
    102     invar = ncdf_varinq(cdfid, varid) ; what contains the variable? 
    103     if (inter(invar.dim, dimidx))[0] NE -1 AND $ 
    104        (inter(invar.dim, dimidy))[0] NE -1 AND $ 
    105        ((where(invar.dim EQ inside.recdim))[0] NE -1 OR inside.recdim EQ -1) $ 
    106     THEN namevar[varid] = invar.name 
     100  namevar = strarr(inq.nvars) 
     101  for varid = 0, inq.nvars-1 do begin 
     102    varinq = ncdf_varinq(cdfid, varid) ; what contains the variable? 
     103    if (inter(varinq.dim, dimidx))[0] NE -1 AND $ 
     104       (inter(varinq.dim, dimidy))[0] NE -1 AND $ 
     105       ((where(varinq.dim EQ inq.recdim))[0] NE -1 OR inq.recdim EQ -1) $ 
     106    THEN namevar[varid] = varinq.name 
    107107  ENDFOR 
    108108  namevar = namevar[where(namevar NE '')] 
     
    117117; for each variable, look if we in one of the case corresponding to ROMS conventions? 
    118118    FOR i = 0, n_elements(namevar)-1 do begin 
    119       invar = ncdf_varinq(cdfid, namevar[i]) 
    120       tmpnm = namedim[invar.dim] 
     119      varinq = ncdf_varinq(cdfid, namevar[i]) 
     120      tmpnm = namedim[varinq.dim] 
    121121; are we in one of the case corresponding to ROMS conventions? 
    122122      CASE 1 OF 
    123         tmpnm[2 <(invar.ndims-1)] EQ 's_w':vargrid = 'W' 
     123        tmpnm[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W' 
    124124        tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T' 
    125125        tmpnm[0] EQ 'xi_u'   AND tmpnm[1] EQ 'eta_u'  :listgrid[i] = 'U' 
     
    152152; time axis 
    153153;------------------------------------------------------------ 
     154  time = ncdf_gettime(fullname, cdfid, caller = 'scanfile', err = err, _extra = ex) 
     155  IF n_elements(err) NE 0 THEN BEGIN 
     156    dummy = report(err) 
     157    jpt = abs(time) 
     158    fakecal = 1 
     159  ENDIF ELSE jpt = n_elements(time)  
     160; high frequency calendar: more than one element per day 
     161  IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0 
    154162  date0fk = date2jul(19000101) 
    155   IF inside.recdim EQ -1 THEN BEGIN 
    156     jpt = 1 
    157     time = date0fk 
    158     fakecal = 1 
    159   ENDIF ELSE BEGIN 
    160     ncdf_diminq, cdfid, inside.recdim, timedimname, jpt 
    161 ; we look for the variable containing the time axis 
    162 ; we look for the first variable having for only dimension inside.recdim 
    163     varid = 0 
    164     repeat BEGIN 
    165       IF varid LT inside.nvars THEN BEGIN 
    166         invar = ncdf_varinq(cdfid, varid) 
    167         varid = varid+1 
    168       ENDIF ELSE varid = 0 
    169     endrep until (n_elements(invar.dim) EQ 1 AND invar.dim[0] EQ inside.recdim) OR (varid EQ 0) 
    170     varid = varid-1 
    171 ; 
    172     CASE 1 OF 
    173       varid EQ -1:BEGIN 
    174         dummy = report('the file '+fullname+' has no time axis.!C we create a fake calendar ...') 
    175         fakecal = 1 
    176         time = date0fk + lindgen(1>jpt) 
    177       END 
    178       invar.natts EQ 0:BEGIN 
    179         dummy = report('the variable '+invar.name+' has no attribut.!C we create a fake calendar ...') 
    180         fakecal = 1 
    181         time = date0fk + lindgen(1>jpt) 
    182       END 
    183       ELSE:BEGIN 
    184 ; 
    185 ; we want to know which attributes are attached to the time variable... 
    186 ; 
    187         attnames = strarr(invar.natts) 
    188         for attiq = 0, invar.natts-1 do attnames[attiq] = ncdf_attname(cdfid, varid, attiq) 
    189         if (where(attnames EQ 'units'))[0] EQ -1 then BEGIN 
    190           dummy = report('Attribut ''units'' not found for the variable '+invar.name+'!C we create a fake calendar ...') 
    191           fakecal = 1 
    192           time = date0fk + lindgen(1>jpt) 
    193         ENDIF ELSE BEGIN 
    194 ; we read the time axis 
    195           ncdf_varget, cdfid, varid, time 
    196           time = double(time) 
    197           ncdf_attget, cdfid, varid, 'units', value 
    198 ; time_counter:units = "seconds since 0001-01-01 00:00:00" ; 
    199 ; time_counter:units = "hours since 0001-01-01 00:00:00" ; 
    200 ; time_counter:units = "days since 1979-01-01 00:00:00" ; 
    201 ; time_counter:units = "months since 1979-01-01 00:00:00" ; 
    202 ; time_counter:units = "years since 1979-01-01 00:00:00" ; 
    203           value = strtrim(strcompress(string(value)), 2) 
    204           mots = str_sep(value, ' ') 
    205           unite = mots[0] 
    206           unite = strlowcase(unite) 
    207           IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1) 
    208           IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7) 
    209           err = 0 
    210           IF unite NE 'second' AND unite NE 'hour' AND unite NE 'day' $ 
    211              AND unite NE 'month' AND unite NE 'year' THEN BEGIN 
    212             dummy = report('time units does not start with seconds/hours/days/months/years') 
    213             err = 1 
    214           ENDIF 
    215           IF stregex(value, '[^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*', /boolean) EQ 0 THEN BEGIN 
    216             dummy = report('attribut units of time has not the good format: [^ ]* since ([0-9]){1,4}-([0-9]){1,2}-([0-9]){1,2}.*') 
    217             err = 1 
    218           ENDIF 
    219           IF err GT 0 THEN BEGIN 
    220             fakecal = 1 
    221             time = date0fk + lindgen(1>jpt) 
    222           ENDIF ELSE BEGIN 
    223             debut = str_sep(mots[2], '-') 
    224 ; 
    225 ; now we try to find the attribut called calendar... 
    226 ; the attribute "calendar" exists? 
    227 ; If no, we suppose that the calendar is gregorian calendar 
    228 ; 
    229             if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN 
    230               ncdf_attget, cdfid, varid, 'calendar', value 
    231               value = string(value) 
    232               CASE value OF 
    233                 'noleap':key_caltype = 'noleap' 
    234                 '360d':key_caltype = '360d' 
    235                 'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 
    236                 ELSE:BEGIN 
    237 ;            notused = report('Unknown calendar: '+value+', we use greg calendar.') 
    238                   key_caltype = 'greg' 
    239                 END 
    240               ENDCASE 
    241             ENDIF ELSE BEGIN 
    242 ;        notused = report('Unknown calendar, we use '+key_caltype+' calendar.') 
    243               IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 
    244             ENDELSE 
    245 ; 
    246 ; BEWARE we have to get back the calendar attribute and ajust time by consequence... 
    247 ; 
    248 ; 
    249 ; We pass time in IDL julian days 
    250 ; 
    251             case unite of 
    252               'second':time = julday(debut[1], debut[2], debut[0])+time/86400.d 
    253               'hour':time = julday(debut[1], debut[2], debut[0])+time/24.d 
    254               'day':time = julday(debut[1], debut[2], debut[0])+time 
    255               'month':BEGIN 
    256                 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m 
    257                    time = julday(debut[1], debut[2], debut[0])+round(time*30) $ 
    258                 ELSE for t = 0, n_elements(time)-1 DO $ 
    259                    time[t] = julday(debut[1]+time[t], debut[2], debut[0]) 
    260               END 
    261               'year':BEGIN 
    262                 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y 
    263                    time = julday(debut[1], debut[2], debut[0])+round(time*365) $ 
    264                 ELSE for t = 0, n_elements(time)-1 do $ 
    265                    time[t] = julday(debut[1], debut[2], debut[0]+time[t]) 
    266               END 
    267             ENDCASE 
    268 ; 
    269 ; high frequency calendar: more than one element per day 
    270             IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0 
    271             date0fk = date2jul(19000101) 
    272             IF keyword_set(fakecal) THEN time = date0fk+lindgen(1>jpt) $ 
    273             ELSE time = long(time) 
    274 ; 
    275           ENDELSE 
    276         ENDELSE 
    277       END 
    278     ENDCASE 
    279   ENDELSE 
     163  IF keyword_set(fakecal) THEN time = date0fk+lindgen(1 > jpt) 
    280164;------------------------------------------------------------ 
    281165  ncdf_close, cdfid 
  • trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro

    r262 r271  
    6868; 
    6969@cm_4cal 
     70 
    7071; get back the calendar and its related informations 
    7172  winfo_id = widget_info(id, find_by_uname = 'infocal') 
     
    9293    day = value MOD 100L 
    9394; check that the date exists in the calendar 
    94   if (where(infowid.calendar EQ julday(month, day, year)))[0] EQ - 1 then return 
     95  if (where(abs(infowid.calendar - julday(month, day, year)) LT 1./86400.))[0] EQ - 1 then return 
    9596; update the value of infocal 
    9697    infowid.date = value 
Note: See TracChangeset for help on using the changeset viewer.