Ignore:
Timestamp:
05/09/06 11:47:44 (18 years ago)
Author:
pinsard
Message:

upgrade of AUTOUR_de_XXX according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/ : files

File:
1 copied

Legend:

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

    r47 r49  
    2828; 
    2929;------------------------------------------------------------ 
    30 FUNCTION scanfile, nomficher, IODIRECTORY = iodirectory 
     30FUNCTION scanfile, nomficher, _extra = ex 
    3131@common 
    3232;------------------------------------------------------------ 
     
    3434; declarees ds un common) 
    3535;------------------------------------------------------------ 
    36    res = -1 
     36  res = -1 
    3737;------------------------------------------------------------ 
    3838; choix du nom du fichier 
    3939;------------------------------------------------------------ 
    40    if NOT keyword_set(iodirectory) then iodirectory = iodir 
    41    nom = isafile(filename = nomficher, IODIRECTORY = iodirectory) 
     40  nom = isafile(filename = nomficher, IODIRECTORY = iodir, _extra = ex) 
    4241;------------------------------------------------------------ 
    4342; ouverture du fichier nom 
    4443;------------------------------------------------------------ 
    45    cdfid=ncdf_open(nom) 
     44  cdfid = ncdf_open(nom) 
    4645;------------------------------------------------------------ 
    4746; que contient le fichier?? 
    4847;------------------------------------------------------------ 
    49    contient=ncdf_inquire(cdfid) 
    50    vargrid = strupcase(strmid(nom, strlen(nom)-9)) 
    51    if vargrid EQ 'GRID.T.NC' OR vargrid EQ 'GRID.U.NC' $ 
    52     OR vargrid EQ 'GRID.V.NC' OR vargrid EQ 'GRID.F.NC' $ 
    53     OR vargrid eq 'GRID.W.NC' $ 
    54     OR vargrid EQ 'GRID_T.NC' OR vargrid EQ 'GRID_U.NC' $ 
    55     OR vargrid EQ 'GRID_V.NC' OR vargrid EQ 'GRID_F.NC' $ 
    56     OR vargrid eq 'GRID_W.NC' then $ 
    57     vargrid = strupcase(strmid(nom, strlen(nom)-4, 1)) ELSE vargrid='T' 
     48  contient = ncdf_inquire(cdfid); 
     49; find vargrid ... 
     50  vargrid = 'T'                 ; default definition 
     51  pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] 
     52  gdtype = ['T', 'U', 'V', 'W', 'F'] 
     53  fnametest = strupcase(nom) 
     54  FOR i = 0, n_elements(pattern)-1 DO BEGIN 
     55    FOR j = 0, n_elements(gdtype)-1 DO BEGIN 
     56      substr = pattern[i]+gdtype[j] 
     57      pos = strpos(fnametest, substr) 
     58      IF pos NE -1 THEN $ 
     59        vargrid = strmid(fnametest, pos+strlen(substr)-1, 1) 
     60    ENDFOR 
     61  ENDFOR 
    5862;------------------------------------------------------------ 
    5963; nom des differentes variables 
     
    6266; contient au moins les dimensions qui doivent etre appelles x et y 
    6367; et la dimension infinie 
    64    nomdim   =strarr(contient.ndims) 
    65    for dimiq=0,contient.ndims-1 do begin 
    66       ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension 
    67       nomdim[dimiq]=strlowcase(name) 
    68    ENDFOR 
    69    indexdimx = where(nomdim EQ 'x' OR nomdim EQ 'lon' OR nomdim EQ 'longitude') 
    70    indexdimx = indexdimx[0] 
    71    if indexdimx EQ -1 then begin 
    72       print, 'one of the dimensions must have the name: ''x'' or ''lon'' or ''longitude''' 
    73       stop 
    74    endif 
    75    indexdimy = where(nomdim EQ 'y' OR nomdim EQ 'lat' OR nomdim EQ 'latitude') 
    76    indexdimy = indexdimy[0] 
    77    if indexdimy EQ -1 then begin 
    78       print, 'one of the dimensions must have the name: ''y'' or ''lat'' or ''latitude''' 
    79       stop 
    80    endif 
     68  nomdim   = strarr(contient.ndims) 
     69  for dimiq = 0, contient.ndims-1 do begin 
     70    ncdf_diminq, cdfid, dimiq, name, value ; nom et valeur de la dimension 
     71    nomdim[dimiq] = strlowcase(name) 
     72  ENDFOR 
     73  indexdimx = where(nomdim EQ 'x' OR nomdim EQ 'lon' OR nomdim EQ 'longitude' OR nomdim EQ 'xt_i7_156' OR nomdim EQ 'xi_rho' OR nomdim EQ 'xi_u' OR nomdim EQ 'xi_v' OR nomdim EQ 'xi_psi') 
     74  indexdimx = indexdimx[0] 
     75  if indexdimx EQ -1 then begin 
     76    print, 'one of the dimensions must have the name: ''x'' or ''lon'' or ''longitude'' or ''xt_i7_156''' 
     77    stop 
     78  endif 
     79  indexdimy = where(nomdim EQ 'y' OR nomdim EQ 'lat' OR nomdim EQ 'latitude' OR nomdim EQ 'yt_j6_75' OR nomdim EQ 'eta_rho' OR nomdim EQ 'eta_u' OR nomdim EQ 'eta_v' OR nomdim EQ 'eta_psi') 
     80  indexdimy = indexdimy[0] 
     81  if indexdimy EQ -1 then begin 
     82    print, 'one of the dimensions must have the name: ''y'' or ''lat'' or ''latitude'' or ''yt_j6_75''' 
     83    stop 
     84  endif 
    8185; 
    82    namevar = strarr(contient.nvars) 
    83    for varid=0,contient.nvars-1 do begin 
    84       varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable 
    85       if (where(varcontient.dim EQ indexdimx))[0] NE -1 AND $ 
    86        (where(varcontient.dim EQ indexdimy))[0] NE -1 AND $ 
    87        (where(varcontient.dim EQ contient.recdim))[0] NE -1 THEN namevar[varid]=varcontient.name  
    88    ENDFOR 
    89    namevar = namevar[where(namevar NE '')] 
    90    listgrid = replicate(vargrid,  n_elements(namevar)) 
     86  namevar = strarr(contient.nvars) 
     87  for varid = 0, contient.nvars-1 do begin 
     88    varcontient = ncdf_varinq(cdfid, varid) ; que contient la variable 
     89    if (where(varcontient.dim EQ indexdimx))[0] NE -1 AND $ 
     90      (where(varcontient.dim EQ indexdimy))[0] NE -1 AND $ 
     91      (where(varcontient.dim EQ contient.recdim))[0] NE -1 THEN namevar[varid] = varcontient.name  
     92  ENDFOR 
     93  namevar = namevar[where(namevar NE '')] 
     94  listgrid = replicate(vargrid,  n_elements(namevar)) 
    9195;------------------------------------------------------------ 
    9296; on recupere l''axe des temps 
    9397;------------------------------------------------------------ 
    9498; on recupere le nom de la variable contenant l''axe des temps 
    95    varid = 0 
    96    repeat BEGIN                ; tant que l''on a pas trouve une variable qui n''a qu'' 
     99  varid = 0 
     100  repeat BEGIN ; tant que l''on a pas trouve une variable qui n''a qu'' 
    97101                                ; une dimension: la dimension infinie 
    98       varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable 
    99       varid = varid+1 
    100    endrep until n_elements(varcontient.dim) EQ 1 AND varcontient.dim[0] EQ contient.recdim 
     102    varcontient = ncdf_varinq(cdfid, varid) ; que contient la variable 
     103    varid = varid+1 
     104  endrep until n_elements(varcontient.dim) EQ 1 AND varcontient.dim[0] EQ contient.recdim ; 
     105  varid = varid-1 
     106; 
     107; we want to know which attrributes are attached to the time variable... 
     108; 
     109  if varcontient.natts EQ 0 then BEGIN 
     110    ncdf_close, cdfid 
     111    return, report('the variable '+varcontient.name+' has no attribut.!C we need attribut ''units'' for the calendar ...') 
     112  endif 
     113  attnames = strarr(varcontient.natts) 
     114  for attiq = 0, varcontient.natts-1 do attnames[attiq] = ncdf_attname(cdfid, varid, attiq) 
     115  if (where(attnames EQ 'units'))[0] EQ -1 then BEGIN 
     116    ncdf_close, cdfid 
     117    return, report('Attribut ''units'' not found for the variable '+varid.name+'we need it for the calendar...') 
     118  endif 
    101119; on lit l''axe des temps 
    102    varid = varid-1 
    103    ncdf_varget, cdfid, varid, time 
    104    time = long(time) 
    105    ncdf_attget,cdfid,varid,'units',value 
     120  ncdf_varget, cdfid, varid, time 
     121  time = double(time) 
     122  ncdf_attget, cdfid, varid, 'units', value 
    106123; time_counter:units = "seconds since 0001-01-01 00:00:00" ; 
    107124; time_counter:units = "hours since 0001-01-01 00:00:00" ; 
     
    109126; time_counter:units = "months since 1979-01-01 00:00:00" ; 
    110127; time_counter:units = "years since 1979-01-01 00:00:00" ; 
    111    value = strtrim(strcompress(string(value)), 2) 
    112    mots = str_sep(value, ' ') 
    113    unite = mots[0] 
    114    debut = str_sep(mots[2], '-') 
     128  value = strtrim(strcompress(string(value)), 2) 
     129  mots = str_sep(value, ' ') 
     130  unite = mots[0] 
     131  debut = str_sep(mots[2], '-') 
    115132; 
     133; now we try to find the attribut called calendar... 
     134; the the attribute "calendar" exists? 
     135; If no, we suppose that the calendar is gregorian calendar 
    116136; 
    117 ; ATTENTION il faut recuperer l''atribut calendar et ajuster time en 
     137  if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN 
     138      ncdf_attget, cdfid, varid, 'calendar', value 
     139      value = string(value) 
     140        CASE value OF 
     141          '360d':key_caltype = '360d' 
     142          'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 
     143          ELSE:BEGIN 
     144;            notused = report('Unknown calendar: '+value+', we use greg calendar.')  
     145            key_caltype = 'greg' 
     146          END 
     147        ENDCASE 
     148      ENDIF ELSE BEGIN 
     149;        notused = report('Unknown calendar, we use '+key_caltype+' calendar.')  
     150        IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 
     151      ENDELSE 
     152; 
     153; ATTENTION il faut recuperer l''attribut calendar et ajuster time en 
    118154; consequense... 
    119155; 
     
    122158; on suppose qu''on utilise le vrai calendrier. 
    123159; 
    124    case strlowcase(unite) of 
    125       'seconds':time = julday(debut[1], debut[2], debut[0])+time/(long(24)*3600) 
    126       'hours':time = julday(debut[1], debut[2], debut[0])+time/(long(24)) 
    127       'days':time = julday(debut[1], debut[2], debut[0])+time 
    128       'months':BEGIN  
    129          for t = 0, n_elements(time)-1  do begin 
    130             time[t] = julday(debut[1]+time[t], debut[2], debut[0]) 
    131          endfor 
    132       END 
    133       'years':BEGIN 
    134          for t = 0, n_elements(time)-1  do begin 
    135             time[t] = julday(debut[1], debut[2], debut[0]+time[t]) 
    136          endfor 
    137       END 
    138    ENDCASE 
     160  unite = strlowcase(unite) 
     161  IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1) 
     162  IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7) 
     163  case unite of 
     164    'second':time = julday(debut[1], debut[2], debut[0])+time/(long(24)*3600) 
     165    'hour':time = julday(debut[1], debut[2], debut[0])+time/(long(24)) 
     166    'day':time = julday(debut[1], debut[2], debut[0])+time 
     167    'month':BEGIN  
     168      if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m 
     169        time = julday(debut[1], debut[2], debut[0])+round(time*30) $ 
     170      ELSE for t = 0, n_elements(time)-1 DO $ 
     171        time[t] = julday(debut[1]+time[t], debut[2], debut[0]) 
     172    END 
     173    'year':BEGIN 
     174      if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y 
     175        time = julday(debut[1], debut[2], debut[0])+round(time*365) $ 
     176      ELSE for t = 0, n_elements(time)-1 do $ 
     177        time[t] = julday(debut[1], debut[2], debut[0]+time[t]) 
     178    END 
     179  ENDCASE 
     180  time = long(time) 
    139181;------------------------------------------------------------ 
    140    return, {filename:nom, time_counter:time, listvar:namevar, listgrid:strupcase(listgrid)} 
     182  return, {filename:nom, time_counter:time, listvar:namevar, listgrid:strupcase(listgrid), calendartype:key_caltype} 
    141183end 
Note: See TracChangeset for help on using the changeset viewer.