Ignore:
Timestamp:
09/11/06 09:11:26 (18 years ago)
Author:
smasson
Message:

bugfix + manage roms outputs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro

    r163 r172  
    9191                    , PARENTIN = parentin, TIMESTEP = timestep, TIMEVAR = timevar $ 
    9292                    , TOUT = tout, NOSTRUCT = nostruct, CONT_NOFILL = CONT_NOFILL, INIT = init $ 
    93                     , GRID = grid, FBASE2TBASE = fbase2tbase, _EXTRA = ex 
     93                    , GRID = grid, FBASE2TBASE = fbase2tbase, _EXTRA = ex, CALLITSELF = callitself 
    9494;--------------------------------------------------------- 
    9595; 
     
    129129  ENDIF 
    130130  varcontient = ncdf_varinq(cdfid, name) 
     131  IF varcontient.ndims LT 2 THEN return, report('read_ncdf cannot read scalar or 1D data') 
     132; look for the dimension names 
     133  dimnames = strarr(varcontient.ndims) 
     134  FOR i = 0, varcontient.ndims-1 DO BEGIN 
     135    ncdf_diminq, cdfid, varcontient.dim[i], tmp, dimsize 
     136    dimnames[i] = tmp 
     137  ENDFOR  
    131138;------------------------------------------------------------ 
    132139; shall we redefine the grid parameters 
     
    144151    if n_elements(ending) NE 0 then lasttps = ending[0] ELSE lasttps = firsttps 
    145152    jpt = lasttps-firsttps+1 
    146     time = julday(1, 1, 1) + lindgen(jpt) 
     153    IF NOT keyword_set(callitself) then time = julday(1, 1, 1) + lindgen(jpt) 
    147154  ENDIF ELSE BEGIN 
    148155    if keyword_set(parent) then BEGIN 
     
    236243      mots = str_sep(value, ' ') 
    237244      unite = mots[0] 
     245      IF unite NE 'seconds' AND unite NE 'hours' AND unite NE 'days' $ 
     246         AND unite NE 'months' AND unite NE 'years' THEN BEGIN 
     247        ncdf_close, cdfid 
     248        return, report('time units does not start with seconds/hours/days/months/years') 
     249      ENDIF 
     250      IF stregex(value, '[^ ]* since ([0-9]){4}-([0-9]){2}-([0-9]){2}.*', /boolean) EQ 0 THEN BEGIN 
     251        ncdf_close, cdfid 
     252        return, report('attribut units of time has not the good format: [^ ]* since ([0-9]){4}-([0-9]){2}-([0-9]){2}.*') 
     253      ENDIF 
    238254      depart = str_sep(mots[2], '-') 
    239255      ncdf_varget, cdfid, timeid, time 
     
    260276        ELSE:BEGIN 
    261277          ncdf_close, cdfid 
    262           return, report('The "units" attribu 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 ..."') 
     278          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 ..."') 
    263279        end 
    264280      ENDCASE 
     
    291307    vargrid = 'T'               ; default definition 
    292308    IF finite(glamu[0]) EQ 1 THEN BEGIN 
    293       pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] 
    294       gdtype = ['T', 'U', 'V', 'W', 'F'] 
    295       fnametest = strupcase(filename) 
    296       FOR i = 0, n_elements(pattern)-1 DO BEGIN 
    297         FOR j = 0, n_elements(gdtype)-1 DO BEGIN 
    298           substr = pattern[i]+gdtype[j] 
    299           pos = strpos(fnametest, substr) 
    300           IF pos NE -1 THEN $ 
    301              vargrid = strmid(fnametest, pos+strlen(substr)-1, 1) 
    302         ENDFOR 
    303       ENDFOR 
    304     ENDIF 
     309; are we in one of the case corresponding to ROMS conventions? 
     310      CASE 1 OF 
     311        dimnames[2 <(varcontient.ndims-1)] EQ 's_w':vargrid = 'W' 
     312        dimnames[0] EQ 'xi_rho' AND dimnames[1] EQ 'eta_rho':vargrid = 'T' 
     313        dimnames[0] EQ 'xi_u'   AND dimnames[1] EQ 'eta_u'  :vargrid = 'U' 
     314        dimnames[0] EQ 'xi_v'   AND dimnames[1] EQ 'eta_v'  :vargrid = 'V' 
     315        dimnames[0] EQ 'xi_psi' AND dimnames[1] EQ 'eta_psi':vargrid = 'F' 
     316        dimnames[0] EQ 'xi_rho' AND dimnames[1] EQ 'eta_v'  :vargrid = 'V' 
     317        dimnames[0] EQ 'xi_u'   AND dimnames[1] EQ 'eta_rho':vargrid = 'U' 
     318        dimnames[0] EQ 'xi_u'   AND dimnames[1] EQ 'eta_v'  :vargrid = 'F' 
     319        ELSE:BEGIN  
     320; could we define the grid type from the file name?? 
     321          pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] 
     322          gdtype = ['T', 'U', 'V', 'W', 'F'] 
     323          fnametest = strupcase(filename) 
     324          FOR i = 0, n_elements(pattern)-1 DO BEGIN 
     325            FOR j = 0, n_elements(gdtype)-1 DO BEGIN 
     326              substr = pattern[i]+gdtype[j] 
     327              pos = strpos(fnametest, substr) 
     328              IF pos NE -1 THEN $ 
     329                 vargrid = strmid(fnametest, pos+strlen(substr)-1, 1) 
     330            ENDFOR 
     331          ENDFOR 
     332        END 
     333      ENDCASE 
     334     ENDIF 
    305335  ENDELSE 
    306336;--------------------------------------------------------------- 
     
    380410  ENDIF 
    381411; 
     412  IF n_elements(key_zreverse) EQ 0 THEN key_zreverse = 0 
     413  IF keyword_set(key_zreverse) THEN BEGIN 
     414    tmp = jpk-1-firstz 
     415    firstz = jpk-1-lastz 
     416    lastz = tmp 
     417  ENDIF 
     418; 
    382419  IF keyword_set(fbase2tbase) THEN BEGIN 
    383420    case strupcase(vargrid) of 
     
    419456;--------------------------------------------------------------------- 
    420457; varname 
    421   varname = name 
     458  IF NOT keyword_set(callitself) THEN varname = name 
    422459; varunit 
    423460  if varcontient.natts NE 0 then begin 
     
    428465    found = (where(lowattnames EQ 'units'))[0] 
    429466    IF found NE -1 then ncdf_attget, cdfid, name, attnames[found], value ELSE value = '' 
    430     varunit = strtrim(string(value), 2) 
     467    IF NOT keyword_set(callitself) THEN varunit = strtrim(string(value), 2) 
    431468; 
    432469    found = (where(lowattnames EQ 'add_offset'))[0] 
     
    443480; 
    444481  ENDIF ELSE BEGIN  
    445     varunit = '' 
     482    IF NOT keyword_set(callitself) THEN varunit = '' 
    446483    add_offset = 0. 
    447484    scale_factor = 1. 
     
    457494 
    458495; we apply reverse 
    459   if keyword_set(key_yreverse) then res = reverse(temporary(res),  2) 
    460   if keyword_set(key_zreverse) AND (size(res))[0] EQ 3 AND jpt EQ 1 then res = reverse(temporary(res), 3) 
    461   if keyword_set(key_zreverse) AND (size(res))[0] EQ 4 THEN res = reverse(temporary(res), 3) 
    462  
     496  if keyword_set(key_yreverse) AND ny NE 1 THEN $ 
     497     res = reverse(reform(res, nx, ny, nz, jpt, /overwrite),  2) 
     498  if keyword_set(key_zreverse) AND nz NE 1 $ 
     499     AND varcontient.ndims - ((where(varcontient.dim EQ contient.recdim))[0] NE -1) EQ 3 THEN $ 
     500        res = reverse(reform(res, nx, ny, nz, jpt, /overwrite),  3) 
    463501; We apply the value valmask on land points. 
    464502  if NOT keyword_set(cont_nofill) then begin 
     
    501539  if add_offset NE 0 then res = temporary(res)+add_offset 
    502540  if missing[0] NE -1 then res[temporary(missing)] = !values.f_nan 
    503   if earth[0] NE -1 then res[temporary(earth)] = 1e20 
     541  if earth[0] NE -1 then res[temporary(earth)] = 1.e20 
     542;--------------------------------------------------------------------- 
     543; if it is roms outputs, we need to get additionals infos... 
     544  IF NOT keyword_set(callitself) THEN BEGIN 
     545    IF strmid(dimnames[0], 0, 3) EQ 'xi_' AND strmid(dimnames[1], 0, 4) EQ 'eta_' THEN BEGIN 
     546      ncdf_attget, cdfid, 'theta_s', theta_s, /global 
     547      ncdf_attget, cdfid, 'theta_b', theta_b, /global 
     548      ncdf_attget, cdfid, 'hc', hc, /global 
     549; +++ binder l'exsitance de h et zeta... 
     550; +++ mettre zeta a 0 par defaut 
     551      hroms = read_ncdf('h', 0, 0, FILENAME = filename $ 
     552                        , /TIMESTEP, /NOSTRUCT, CONT_NOFILL = CONT_NOFILL $ 
     553                        , GRID = vargrid, /CALLITSELF, _EXTRA = ex) 
     554      zeta = read_ncdf('zeta', firsttps, lasttps, FILENAME = filename $ 
     555                       , /TIMESTEP, /NOSTRUCT, CONT_NOFILL = CONT_NOFILL $ 
     556                       , GRID = vargrid, /CALLITSELF, _EXTRA = ex) 
     557      romszinfos = {h:temporary(hroms), zeta:temporary(zeta), theta_s:theta_s, theta_b:theta_b, hc:hc} 
     558    ENDIF ELSE romszinfos = {h:-1, zeta:-1, theta_s:-1, theta_b:-1, hc:-1} 
     559  ENDIF 
    504560;--------------------------------------------------------------------- 
    505561  ncdf_close, cdfid 
    506 ;--------------------------------------------------------------------- 
    507   if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4rdncdf.dat' 
    508   if keyword_set(nostruct) then return, res $ 
    509   ELSE BEGIN  
    510     IF keyword_set(key_forgetold) THEN BEGIN 
    511       return, {arr:res, grid:vargrid, unit:varunit, experiment:varexp, name:varname}  
    512     ENDIF ELSE BEGIN  
    513       return, {tab:res, grille:vargrid, unite:varunit, experience:varexp, nom:varname} 
    514     ENDELSE  
    515   ENDELSE  
     562 
     563  IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4rdncdf.dat' 
     564 
     565  IF keyword_set(nostruct) THEN return, res 
     566  IF keyword_set(key_forgetold) THEN BEGIN 
     567    return, {arr:temporary(res), grid:vargrid, unit:varunit, experiment:varexp, name:varname}  
     568  ENDIF ELSE BEGIN  
     569    return, {tab:temporary(res), grille:vargrid, unite:varunit, experience:varexp, nom:varname} 
     570  ENDELSE 
     571 
    516572END 
    517573 
Note: See TracChangeset for help on using the changeset viewer.