Changeset 336 for trunk


Ignore:
Timestamp:
03/20/08 22:36:46 (16 years ago)
Author:
smasson
Message:

improve boxzoom usage in read_ncdf

File:
1 edited

Legend:

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

    r333 r336  
    7777; For ROMS outputs. To define zeta to 0. instead of reading it 
    7878; 
     79; @keyword ZINVAR {type=named variable} 
     80; Set this keyword to a named variable in which 1 is returned if a 
     81; vertical dimension is found in the variable. Returns 0 otherwise 
     82; 
    7983; @keyword _EXTRA 
    8084; Used to pass keywords to <pro>isafile</pro>, <pro>initncdf</pro>, 
     
    98102;- 
    99103FUNCTION read_ncdf, name, beginning, ending, compatibility $ 
    100                   , BOXZOOM=boxzoom, FILENAME=filename $ 
    101                   , PARENTIN=parentin, TIMESTEP=timestep $ 
    102                   , ADDSCL_BEFORE=addscl_before $ 
    103                   , TOUT=tout, NOSTRUCT=nostruct, CONT_NOFILL=CONT_NOFILL, INIT=init $ 
    104                   , GRID=grid, CALLITSELF=callitself, DIREC=direc $ 
    105                   , ZETAFILENAME=zetafilename, ZETAZERO=zetazero $ 
    106                   , _EXTRA=ex 
     104                    , BOXZOOM = boxzoom, FILENAME = filename $ 
     105                    , PARENTIN = parentin, TIMESTEP = timestep $ 
     106                    , ADDSCL_BEFORE = addscl_before $ 
     107                    , TOUT = tout, NOSTRUCT = nostruct, CONT_NOFILL = CONT_NOFILL, INIT = init $ 
     108                    , GRID = grid, CALLITSELF = callitself, DIREC = direc $ 
     109                    , ZETAFILENAME = zetafilename, ZETAZERO = zetazero $ 
     110                    , ZINVAR = zinvar, _EXTRA = ex 
    107111; 
    108112  compile_opt idl2, strictarrsubs 
     
    129133;------------------------------------------------------------ 
    130134  IF size(filename, /type) NE 7 THEN $ 
    131     return, report('read_ncdf cancelled') 
     135     return, report('read_ncdf cancelled') 
    132136  IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+filename+' > /dev/null' 
    133137  cdfid = ncdf_open(filename) 
     
    148152    dimnames[i] = tmp 
    149153  ENDFOR 
     154;------------------------------------------------------------ 
     155; we check if the variable has a vertical dimension and/or  
     156; a record dimension. This is useful to define boxzoom  
     157; keyword in domdef 
     158;------------------------------------------------------------ 
     159  dummy = where(varinq.dim EQ inq.recdim, tinvar)  
     160; check the presence of a vertical dimension according to the 
     161; number of dimensions and the presence of a record dimension 
     162  zinvar = (varinq.ndims EQ 3 AND tinvar NE 1) OR varinq.ndims EQ 4 
    150163;------------------------------------------------------------ 
    151164; shall we redefine the grid parameters 
     
    175188      date1 = date2jul(beginning[0]) 
    176189      if n_elements(ending) NE 0 then date2 = date2jul(ending[0]) ELSE date2 = date1 
    177       firsttps = (where(abs(time - date1) LT 0.9d/86400.d))[0]   ; beware of rounding errors... 
     190      firsttps = (where(abs(time - date1) LT 0.9d/86400.d))[0] ; beware of rounding errors... 
    178191      lasttps = (where(abs(time - date2) LT 0.9d/86400.d))[0] 
    179192      jpt = lasttps-firsttps+1 
     
    218231; are we in one of the case corresponding to ROMS conventions? 
    219232      CASE 1 OF 
    220         dimnames[2 <(varinq.ndims-1)] EQ 's_w':vargrid = 'W' 
     233        dimnames[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W' 
    221234        dimnames[0] EQ 'xi_rho' AND dimnames[1] EQ 'eta_rho':vargrid = 'T' 
    222235        dimnames[0] EQ 'xi_u'   AND dimnames[1] EQ 'eta_u'  :vargrid = 'U' 
     
    241254        END 
    242255      ENDCASE 
    243      ENDIF 
     256    ENDIF 
    244257  ENDELSE 
    245258;--------------------------------------------------------------- 
     
    264277    endcase 
    265278  ENDIF ELSE BEGIN 
    266     if keyword_set(boxzoom) then BEGIN 
    267       Case 1 Of 
    268         N_Elements(Boxzoom) Eq 1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]] 
    269         N_Elements(Boxzoom) Eq 2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]] 
    270         N_Elements(Boxzoom) Eq 4:bte = [Boxzoom, vert1, vert2] 
    271         N_Elements(Boxzoom) Eq 5:bte = [Boxzoom[0:3], 0, Boxzoom[4]] 
    272         N_Elements(Boxzoom) Eq 6:bte = Boxzoom 
    273         Else: BEGIN 
     279    IF keyword_set(boxzoom) then BEGIN 
     280      CASE N_Elements(Boxzoom) Of 
     281        1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]] 
     282        2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]] 
     283        4:bte = [Boxzoom, vert1, vert2] 
     284        5:bte = [Boxzoom[0:3], 0, Boxzoom[4]] 
     285        6:bte = Boxzoom 
     286        ELSE: BEGIN 
    274287          ncdf_close, cdfid 
    275288          return, report('Wrong Definition of Boxzoom') 
    276         end 
     289        END 
    277290      ENDCASE 
    278       savedbox = 1b 
    279       saveboxparam, 'boxparam4rdncdf.dat' 
    280       domdef, bte, GRIDTYPE = ['T', vargrid], _extra = ex 
     291      IF zinvar EQ 1 THEN domdef, bte, GRIDTYPE = ['T', vargrid], _extra = ex $ 
     292      ELSE domdef, bte[0:3], GRIDTYPE = ['T', vargrid], _extra = ex 
    281293    ENDIF 
    282294    grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz 
     
    325337  vardate = string(format = '(C(CMoA))', 31*(month-1))+' '+strtrim(day, 1)+', '+strtrim(year, 1) 
    326338  varexp = file_basename(filename) 
    327  
    328339; We apply the value valmask on land points. 
    329340  if NOT keyword_set(cont_nofill) then begin 
     
    344355  IF size(missing_value, /type) NE 7 THEN BEGIN 
    345356    IF finite(missing_value) EQ 1 THEN BEGIN 
    346         CASE 1 OF 
    347           missing_value GT 1.e6:missing = where(res GT missing_value/10.) 
    348           missing_value LT -1.e6:missing = where(res LT missing_value/10.) 
    349           abs(missing_value) LT 1.e-6:missing = where(abs(res) LT 1.e-6) 
    350           ELSE:missing = where(res EQ missing_value) 
    351         ENDCASE 
     357      CASE 1 OF 
     358        missing_value GT 1.e6:missing = where(res GT missing_value/10.) 
     359        missing_value LT -1.e6:missing = where(res LT missing_value/10.) 
     360        abs(missing_value) LT 1.e-6:missing = where(abs(res) LT 1.e-6) 
     361        ELSE:missing = where(res EQ missing_value) 
     362      ENDCASE 
    352363    ENDIF ELSE missing = where(finite(res) EQ 0) 
    353364  ENDIF ELSE missing = -1 
     
    358369  IF missing[0] NE -1 THEN res[temporary(missing)] = !values.f_nan 
    359370  IF earth[0] NE -1 THEN BEGIN  
    360     IF varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1 THEN $   ;xyt array     
     371    IF varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1 THEN $ ;xyt array     
    361372       earth = earth#replicate(1, jpt)+replicate(nx*ny, n_elements(earth))#lindgen(jpt) 
    362373    IF varinq.ndims eq 4 THEN earth = earth#replicate(1, jpt)+replicate(nx*ny*nz, n_elements(earth))#lindgen(jpt) 
     
    405416;--------------------------------------------------------------------- 
    406417  ncdf_close, cdfid 
    407  
    408   IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4rdncdf.dat' 
    409  
    410418  IF keyword_set(nostruct) THEN return, res 
    411419  IF keyword_set(key_forgetold) THEN BEGIN 
Note: See TracChangeset for help on using the changeset viewer.