- Timestamp:
- 03/20/08 22:36:46 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/LECTURE/read_ncdf.pro
r333 r336 77 77 ; For ROMS outputs. To define zeta to 0. instead of reading it 78 78 ; 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 ; 79 83 ; @keyword _EXTRA 80 84 ; Used to pass keywords to <pro>isafile</pro>, <pro>initncdf</pro>, … … 98 102 ;- 99 103 FUNCTION 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=ex104 , 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 107 111 ; 108 112 compile_opt idl2, strictarrsubs … … 129 133 ;------------------------------------------------------------ 130 134 IF size(filename, /type) NE 7 THEN $ 131 return, report('read_ncdf cancelled')135 return, report('read_ncdf cancelled') 132 136 IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+filename+' > /dev/null' 133 137 cdfid = ncdf_open(filename) … … 148 152 dimnames[i] = tmp 149 153 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 150 163 ;------------------------------------------------------------ 151 164 ; shall we redefine the grid parameters … … 175 188 date1 = date2jul(beginning[0]) 176 189 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] 190 firsttps = (where(abs(time - date1) LT 0.9d/86400.d))[0] ; beware of rounding errors... 178 191 lasttps = (where(abs(time - date2) LT 0.9d/86400.d))[0] 179 192 jpt = lasttps-firsttps+1 … … 218 231 ; are we in one of the case corresponding to ROMS conventions? 219 232 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' 221 234 dimnames[0] EQ 'xi_rho' AND dimnames[1] EQ 'eta_rho':vargrid = 'T' 222 235 dimnames[0] EQ 'xi_u' AND dimnames[1] EQ 'eta_u' :vargrid = 'U' … … 241 254 END 242 255 ENDCASE 243 256 ENDIF 244 257 ENDELSE 245 258 ;--------------------------------------------------------------- … … 264 277 endcase 265 278 ENDIF ELSE BEGIN 266 ifkeyword_set(boxzoom) then BEGIN267 C ase 1Of268 N_Elements(Boxzoom) Eq1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]]269 N_Elements(Boxzoom) Eq2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]]270 N_Elements(Boxzoom) Eq4:bte = [Boxzoom, vert1, vert2]271 N_Elements(Boxzoom) Eq5:bte = [Boxzoom[0:3], 0, Boxzoom[4]]272 N_Elements(Boxzoom) Eq6:bte = Boxzoom273 E lse: BEGIN279 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 274 287 ncdf_close, cdfid 275 288 return, report('Wrong Definition of Boxzoom') 276 end289 END 277 290 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 281 293 ENDIF 282 294 grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz … … 325 337 vardate = string(format = '(C(CMoA))', 31*(month-1))+' '+strtrim(day, 1)+', '+strtrim(year, 1) 326 338 varexp = file_basename(filename) 327 328 339 ; We apply the value valmask on land points. 329 340 if NOT keyword_set(cont_nofill) then begin … … 344 355 IF size(missing_value, /type) NE 7 THEN BEGIN 345 356 IF finite(missing_value) EQ 1 THEN BEGIN 346 347 348 349 350 351 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 352 363 ENDIF ELSE missing = where(finite(res) EQ 0) 353 364 ENDIF ELSE missing = -1 … … 358 369 IF missing[0] NE -1 THEN res[temporary(missing)] = !values.f_nan 359 370 IF earth[0] NE -1 THEN BEGIN 360 IF varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1 THEN $ 371 IF varinq.ndims eq 3 AND (where(varinq.dim EQ inq.recdim))[0] NE -1 THEN $ ;xyt array 361 372 earth = earth#replicate(1, jpt)+replicate(nx*ny, n_elements(earth))#lindgen(jpt) 362 373 IF varinq.ndims eq 4 THEN earth = earth#replicate(1, jpt)+replicate(nx*ny*nz, n_elements(earth))#lindgen(jpt) … … 405 416 ;--------------------------------------------------------------------- 406 417 ncdf_close, cdfid 407 408 IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4rdncdf.dat'409 410 418 IF keyword_set(nostruct) THEN return, res 411 419 IF keyword_set(key_forgetold) THEN BEGIN
Note: See TracChangeset
for help on using the changeset viewer.