Changeset 231 for trunk/SRC/ToBeReviewed/INIT
- Timestamp:
- 03/19/07 18:15:51 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/INIT/initncdf.pro
r226 r231 1 ;------------------------------------------------------------2 ;------------------------------------------------------------3 ;------------------------------------------------------------4 1 ;+ 5 2 ; … … 10 7 ; @categories 11 8 ; Grid 12 ; 9 ; 13 10 ; @param NCFILEIN {in}{required}{type=scalar string} 14 11 ; A string giving the name of the NetCdf file … … 18 15 ; 19 16 ; @keyword MASKNAME {type=string} 20 ; A string giving the name of the variable in the file 17 ; A string giving the name of the variable in the file 21 18 ; that contains the land/sea mask 22 19 ; … … 31 28 ; 32 29 ; @keyword USEASMASK {type=scalar string} 33 ; A string giving the name of the variable in the file 30 ; A string giving the name of the variable in the file 34 31 ; that will be used to build the land/sea mask. In this case the 35 32 ; mask is based on the first record (if record dimension … … 40 37 ; 41 38 ; @keyword ZAXISNAME {default='z', 'level', 'lev', 'depth...'}{type=scalar string} 42 ; A string giving the name of the variable in the file 43 ; that contains the [xyz]axis. 39 ; A string giving the name of the variable in the file 40 ; that contains the [xyz]axis. 44 41 ; 45 42 ; @keyword XYINDEX {default=0}{type=scalar: 0 or 1} 46 43 ; To define the x/y axis with index instead of using 47 ; the values contained in X/YAXISNAME. 48 ; x/yaxis = keyword_set(start1) + findgen(jpi/jpj) 44 ; the values contained in X/YAXISNAME. 45 ; x/yaxis = keyword_set(start1) + findgen(jpi/jpj) 49 46 ; this forces key_onearth = 0 50 47 ; 51 48 ; @keyword ZINDEX {default=0}{type=scalar: 0 or 1} 52 49 ; To define the z axis with index instead of using 53 ; the values contained in ZAXISNAME. 54 ; zaxis = keyword_set(start1) + findgen(jpk) 55 ; 50 ; the values contained in ZAXISNAME. 51 ; zaxis = keyword_set(start1) + findgen(jpk) 52 ; 56 53 ; @keyword _EXTRA 57 ; Used to pass keywords to computegrid and ncdf_getaxis54 ; Used to pass keywords to <pro>computegrid</pro> and <pro>ncdf_getaxis</pro> 58 55 ; 59 56 ; @uses … … 61 58 ; 62 59 ; @restrictions 63 ; Change the grid parameters (see computegrid)60 ; Change the grid parameters (see <pro>computegrid</pro>) 64 61 ; 65 62 ; @restrictions … … 67 64 ; 68 65 ; @examples 69 ; 66 ; IDL> initncdf,'toto.nc',glam=[-180,180] 70 67 ; 71 68 ; @history … … 77 74 ; 78 75 ;- 79 ;------------------------------------------------------------ 80 ;------------------------------------------------------------ 81 ;------------------------------------------------------------ 76 ; 82 77 PRO initncdf, ncfilein $ 83 78 , ZAXISNAME = zaxisname, MASKNAME = maskname $ … … 86 81 , XYINDEX = xyindex, ZINDEX = zindex $ 87 82 , _EXTRA = ex 88 ;89 83 ; 90 84 compile_opt idl2, strictarrsubs … … 99 93 endif 100 94 ; if the file is stored on tape 101 if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null' 95 if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null' 102 96 ;---------------------------------------------------------- 103 97 ; open the file … … 109 103 namedim = strarr(inside.ndims) 110 104 for dimiq = 0, inside.ndims-1 do begin 111 ncdf_diminq, cdfid, dimiq, tmpname, value 105 ncdf_diminq, cdfid, dimiq, tmpname, value 112 106 namedim[dimiq] = strlowcase(tmpname) 113 107 ENDFOR … … 126 120 ; find the zaxis 127 121 IF keyword_set(romsgrid) THEN BEGIN 128 FOR i = 0, inside.ndims-1 DO BEGIN 122 FOR i = 0, inside.ndims-1 DO BEGIN 129 123 ncdf_diminq, cdfid, i, name, size 130 124 CASE strlowcase(name) OF … … 136 130 ELSE: 137 131 ENDCASE 138 ENDFOR 132 ENDFOR 139 133 IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN 140 134 ncdf_varget, cdfid, 'h', romsh 141 135 ENDIF ELSE romsh = -1 142 ENDIF ELSE BEGIN 136 ENDIF ELSE BEGIN 143 137 if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z' 144 138 zvarid = (where(namevar EQ 'nav_lev' or namevar EQ zaxisname OR namevar EQ 'level' OR namevar EQ 'lev' OR strmid(namevar, 0, 5) EQ 'depth'))[0] … … 149 143 ; read the zaxis 150 144 if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis 151 ENDELSE 145 ENDELSE 152 146 IF keyword_set(zindex) AND keyword_set(zaxis) THEN $ 153 147 zaxis = keyword_set(start1) + findgen(n_elements(zaxis)) … … 158 152 keyword_set(maskname):BEGIN 159 153 mskid = (where(namevar EQ strlowcase(maskname)))[0] 160 if mskid NE -1 THEN BEGIN 154 if mskid NE -1 THEN BEGIN 161 155 mskinq = ncdf_varinq(cdfid, mskid) 162 156 ; is the mask variable containing the record dimension? 163 157 withrcd = (where(mskinq.dim EQ inside.recdim))[0] 164 158 IF withrcd NE -1 THEN BEGIN 165 ; in order to read only the first record 159 ; in order to read only the first record 166 160 ; we need to get the size of each dimension 167 161 count = replicate(1L, mskinq.ndims) … … 172 166 ENDIF 173 167 ENDFOR 174 ; read the variable for the first record 168 ; read the variable for the first record 175 169 ncdf_varget, cdfid, mskid, tmask, count = count 176 170 ENDIF ELSE ncdf_varget, cdfid, mskid, tmask 177 ; check if we need to applay add_offset and scale factor 171 ; check if we need to applay add_offset and scale factor 178 172 FOR a = 0, mskinq.natts-1 DO BEGIN 179 attname = ncdf_attname(cdfid, mskid, a) 173 attname = ncdf_attname(cdfid, mskid, a) 180 174 CASE strlowcase(attname) OF 181 175 'add_offset':ncdf_attget, cdfid, mskid, attname, add_offset … … 188 182 if keyword_set(invmask) then tmask = 1-tmask 189 183 tmask = byte(round(tmask)) 190 ENDIF ELSE tmask = -1 184 ENDIF ELSE tmask = -1 191 185 END 192 186 ;.................. 193 187 keyword_set(useasmask):BEGIN 194 188 mskid = (where(namevar EQ strlowcase(useasmask)))[0] 195 if mskid NE -1 THEN BEGIN 189 if mskid NE -1 THEN BEGIN 196 190 mskinq = ncdf_varinq(cdfid, mskid) 197 191 ; is the mask variable containing the record dimension? 198 192 withrcd = (where(mskinq.dim EQ inside.recdim))[0] 199 193 IF withrcd NE -1 THEN BEGIN 200 ; in order to read only the first record 194 ; in order to read only the first record 201 195 ; we need to get the size of each dimension 202 196 count = replicate(1L, mskinq.ndims) … … 207 201 ENDIF 208 202 ENDFOR 209 ; read the variable for the first record 203 ; read the variable for the first record 210 204 ncdf_varget, cdfid, mskid, tmask, count = count 211 205 ENDIF ELSE ncdf_varget, cdfid, mskid, tmask 212 ; check if we need to applay add_offset and scale factor 206 ; check if we need to applay add_offset and scale factor 213 207 FOR a = 0, mskinq.natts-1 DO BEGIN 214 attname = ncdf_attname(cdfid, mskid, a) 208 attname = ncdf_attname(cdfid, mskid, a) 215 209 CASE strlowcase(attname) OF 216 210 'add_offset':ncdf_attget, cdfid, mskid, attname, add_offset … … 236 230 IF min(tmask) EQ 1 THEN BEGIN 237 231 print, 'missing or nan values not found...' 238 tmask = -1 232 tmask = -1 239 233 ENDIF 240 234 ENDELSE 241 ENDIF ELSE tmask = -1 235 ENDIF ELSE tmask = -1 242 236 END 243 237 ;.................. … … 248 242 ; 249 243 ; compute the grid 250 if NOT keyword_set(zaxis) then BEGIN 244 if NOT keyword_set(zaxis) then BEGIN 251 245 computegrid, xaxis = xaxis, yaxis = yaxis $ 252 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex 253 ENDIF ELSE BEGIN 246 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex 247 ENDIF ELSE BEGIN 254 248 computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $ 255 249 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex 256 ENDELSE 250 ENDELSE 257 251 IF n_elements(time) EQ 0 THEN time = 0 258 jpt = n_elements(time) 252 jpt = n_elements(time) 259 253 ;---------------------------------------------------------- 260 254
Note: See TracChangeset
for help on using the changeset viewer.