Changeset 172 for trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro
- Timestamp:
- 09/11/06 09:11:26 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro
r167 r172 89 89 ;------------------------------------------------------------ 90 90 infile = ncdf_inquire(cdfid) ; 91 ; find vargrid ... 92 IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE BEGIN 93 vargrid = 'T' ; default definition 94 IF finite(glamu[0]) EQ 1 THEN BEGIN 91 ;------------------------------------------------------------ 92 ; name of all dimensions 93 ;------------------------------------------------------------ 94 namedim = strarr(infile.ndims) 95 for dimiq = 0, infile.ndims-1 do begin 96 ncdf_diminq, cdfid, dimiq, tmpname, value 97 namedim[dimiq] = strlowcase(tmpname) 98 ENDFOR 99 ; roms file? 100 dimidx = where(namedim EQ 'xi_rho' OR namedim EQ 'xi_u' OR namedim EQ 'xi_v' OR namedim EQ 'xi_psi') 101 IF dimidx[0] EQ -1 THEN BEGIN 102 ; we are looking for a x dimension with a name matching one of the following regular expression: 103 testname = ['longitude', 'lon', 'x', 'longitude*', 'lon*', 'x*', '*longitude*', '*lon*', '*x*'] 104 cnt = -1 105 ii = 0 106 WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 107 dimidx = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 108 ii = ii+1 109 ENDWHILE 110 CASE cnt OF 111 0:begin 112 dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 113 , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 114 , ' => we cannot find the x dimension']) 115 stop 116 END 117 1:dimidx = dimidx[0] 118 ELSE:begin 119 dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 120 , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 121 , ' => we cannot find the x dimension']) 122 stop 123 ENDELSE 124 ENDCASE 125 ENDIF 126 ; roms file? 127 dimidy = where(namedim EQ 'eta_rho' OR namedim EQ 'eta_u' OR namedim EQ 'eta_v' OR namedim EQ 'eta_psi') 128 IF dimidy[0] EQ -1 THEN BEGIN 129 ; we are looking for a y dimension with a name matching one of the following regular expression: 130 testname = ['latitude', 'lat', 'y', 'latitude*', 'lat*', 'y*', 'eta_*', '*latitude*', '*lat*', '*y*'] 131 cnt = -1 132 ii = 0 133 WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 134 dimidy = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 135 ii = ii+1 136 ENDWHILE 137 CASE cnt OF 138 0:begin 139 dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 140 , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 141 , ' => we cannot find the y dimension']) 142 stop 143 END 144 1:dimidy = dimidy[0] 145 ELSE:begin 146 dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 147 , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 148 , ' => we cannot find the x dimension']) 149 stop 150 ENDELSE 151 ENDCASE 152 ENDIF 153 ;------------------------------------------------------------ 154 ; name of all variables 155 ;------------------------------------------------------------ 156 ; we keep only the variables containing at least x, y and time dimension (if existing...) 157 namevar = strarr(infile.nvars) 158 for varid = 0, infile.nvars-1 do begin 159 invar = ncdf_varinq(cdfid, varid) ; what contains the variable? 160 if (inter(invar.dim, dimidx))[0] NE -1 AND $ 161 (inter(invar.dim, dimidy))[0] NE -1 AND $ 162 ((where(invar.dim EQ infile.recdim))[0] NE -1 OR infile.recdim EQ -1) $ 163 THEN namevar[varid] = invar.name 164 ENDFOR 165 namevar = namevar[where(namevar NE '')] 166 ;------------------------------------------------------------ 167 ; find vargrid for each selected variable... 168 ;------------------------------------------------------------ 169 listgrid = strarr(n_elements(namevar)) 170 ; default definitions 171 IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE vargrid = 'T' 172 ; look for values of vargrid for each variable 173 IF finite(glamu[0]) EQ 1 AND NOT keyword_set(grid) THEN BEGIN 174 ; for each variable, look if we in one of the case corresponding to ROMS conventions? 175 FOR i = 0, n_elements(namevar)-1 do begin 176 invar = ncdf_varinq(cdfid, namevar[i]) 177 tmpnm = namedim[invar.dim] 178 ; are we in one of the case corresponding to ROMS conventions? 179 CASE 1 OF 180 tmpnm[2 <(invar.ndims-1)] EQ 's_w':vargrid = 'W' 181 tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T' 182 tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_u' :listgrid[i] = 'U' 183 tmpnm[0] EQ 'xi_v' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' 184 tmpnm[0] EQ 'xi_psi' AND tmpnm[1] EQ 'eta_psi':listgrid[i] = 'F' 185 tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' 186 tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'U' 187 tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'F' 188 ELSE: 189 ENDCASE 190 ENDFOR 191 empty = where(listgrid EQ '') 192 IF empty[0] NE -1 THEN BEGIN 193 ; could we define the grid type from the file name?? 95 194 pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] 96 195 gdtype = ['T', 'U', 'V', 'W', 'F'] … … 104 203 ENDFOR 105 204 ENDFOR 106 ENDIF 107 ENDELSE 108 ;------------------------------------------------------------ 109 ; name of all dimensions 110 ;------------------------------------------------------------ 111 namedim = strarr(infile.ndims) 112 for dimiq = 0, infile.ndims-1 do begin 113 ncdf_diminq, cdfid, dimiq, tmpname, value 114 namedim[dimiq] = strlowcase(tmpname) 115 ENDFOR 116 ; we are looking for a x dimension with a name matching one of the following regular expression: 117 testname = ['longitude', 'lon', 'x', 'longitude*', 'lon*', 'x*', '*longitude*', '*lon*', '*x*'] 118 cnt = -1 119 ii = 0 120 WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 121 dimidx = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 122 ii = ii+1 123 ENDWHILE 124 CASE cnt OF 125 0:begin 126 dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 127 , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 128 , ' => we cannot find the x dimension']) 129 stop 130 END 131 1:dimidx = dimidx[0] 132 ELSE:begin 133 dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 134 , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 135 , ' => we cannot find the x dimension']) 136 stop 137 END 138 ENDCASE 139 ; we are looking for a y dimension with a name matching one of the following regular expression: 140 testname = ['latitude', 'lat', 'y', 'latitude*', 'lat*', 'y*', 'eta_*', '*latitude*', '*lat*', '*y*'] 141 cnt = -1 142 ii = 0 143 WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 144 dimidy = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 145 ii = ii+1 146 ENDWHILE 147 CASE cnt OF 148 0:begin 149 dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 150 , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 151 , ' => we cannot find the y dimension']) 152 stop 153 END 154 1:dimidy = dimidy[0] 155 ELSE:begin 156 dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 157 , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 158 , ' => we cannot find the x dimension']) 159 stop 160 END 161 ENDCASE 162 ;------------------------------------------------------------ 163 ; name of all variables 164 ;------------------------------------------------------------ 165 ; we keep only the variables containing at least x, y and time dimension (if existing...) 166 namevar = strarr(infile.nvars) 167 for varid = 0, infile.nvars-1 do begin 168 invar = ncdf_varinq(cdfid, varid) ; what contains the variable? 169 if (where(invar.dim EQ dimidx))[0] NE -1 AND $ 170 (where(invar.dim EQ dimidy))[0] NE -1 AND $ 171 ((where(invar.dim EQ infile.recdim))[0] NE -1 OR infile.recdim EQ -1) $ 172 THEN namevar[varid] = invar.name 173 ENDFOR 174 namevar = namevar[where(namevar NE '')] 175 listgrid = replicate(vargrid, n_elements(namevar)) 205 listgrid[empty] = vargrid 206 ENDIF 207 ENDIF ELSE listgrid[*] = vargrid 176 208 ;------------------------------------------------------------ 177 209 ; time axis … … 229 261 mots = str_sep(value, ' ') 230 262 unite = mots[0] 231 debut = str_sep(mots[2], '-') 263 err = 0 264 IF unite NE 'seconds' AND unite NE 'hours' AND unite NE 'days' $ 265 AND unite NE 'months' AND unite NE 'years' THEN BEGIN 266 dummy = report('time units does not start with seconds/hours/days/months/years') 267 err = 1 268 ENDIF 269 err = err + 1 - stregex(value, '[^ ]* since ([0-9]){4}-([0-9]){2}-([0-9]){2}.*', /boolean) 270 IF err GT 0 THEN BEGIN 271 dummy = report('attribut units of time has not the good format: [^ ]* since ([0-9]){4}-([0-9]){2}-([0-9]){2}.*') 272 fakecal = 1 273 time = date0fk + lindgen(jpt) 274 ENDIF ELSE BEGIN 275 debut = str_sep(mots[2], '-') 232 276 ; 233 277 ; now we try to find the attribut called calendar... … … 235 279 ; If no, we suppose that the calendar is gregorian calendar 236 280 ; 237 if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN238 ncdf_attget, cdfid, varid, 'calendar', value239 value = string(value)240 CASE value OF241 'noleap':key_caltype = 'noleap'242 '360d':key_caltype = '360d'243 'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg'244 ELSE:BEGIN281 if (where(attnames EQ 'calendar'))[0] NE -1 then BEGIN 282 ncdf_attget, cdfid, varid, 'calendar', value 283 value = string(value) 284 CASE value OF 285 'noleap':key_caltype = 'noleap' 286 '360d':key_caltype = '360d' 287 'greg':IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 288 ELSE:BEGIN 245 289 ; notused = report('Unknown calendar: '+value+', we use greg calendar.') 246 key_caltype = 'greg' 290 key_caltype = 'greg' 291 END 292 ENDCASE 293 ENDIF ELSE BEGIN 294 ; notused = report('Unknown calendar, we use '+key_caltype+' calendar.') 295 IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 296 ENDELSE 297 ; 298 ; BEWARE we have to get back the calendar attribute and ajust time by consequence... 299 ; 300 ; 301 ; We pass time in IDL julian days 302 ; 303 unite = strlowcase(unite) 304 IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1) 305 IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7) 306 case unite of 307 'second':time = julday(debut[1], debut[2], debut[0])+time/86400.d 308 'hour':time = julday(debut[1], debut[2], debut[0])+time/24.d 309 'day':time = julday(debut[1], debut[2], debut[0])+time 310 'month':BEGIN 311 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m 312 time = julday(debut[1], debut[2], debut[0])+round(time*30) $ 313 ELSE for t = 0, n_elements(time)-1 DO $ 314 time[t] = julday(debut[1]+time[t], debut[2], debut[0]) 315 END 316 'year':BEGIN 317 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y 318 time = julday(debut[1], debut[2], debut[0])+round(time*365) $ 319 ELSE for t = 0, n_elements(time)-1 do $ 320 time[t] = julday(debut[1], debut[2], debut[0]+time[t]) 247 321 END 248 322 ENDCASE 249 ENDIF ELSE BEGIN 250 ; notused = report('Unknown calendar, we use '+key_caltype+' calendar.') 251 IF n_elements(key_caltype) EQ 0 THEN key_caltype = 'greg' 323 ; 324 ; high frequency calendar: more than one element per day 325 IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0 326 date0fk = date2jul(19000101) 327 IF keyword_set(fakecal) THEN time = date0fk+lindgen(jpt) $ 328 ELSE time = long(time) 329 ; 252 330 ENDELSE 253 ;254 ; BEWARE we have to get back the calendar attribute and ajust time by consequence...255 ;256 ;257 ; We pass time in IDL julian days258 ;259 unite = strlowcase(unite)260 IF strpos(unite, 's', strlen(unite)-1) NE -1 THEN unite = strmid(unite, 0, strlen(unite)-1)261 IF strpos(unite, 'julian_') NE -1 THEN unite = strmid(unite, 7)262 case unite of263 'second':time = julday(debut[1], debut[2], debut[0])+time/86400.d264 'hour':time = julday(debut[1], debut[2], debut[0])+time/24.d265 'day':time = julday(debut[1], debut[2], debut[0])+time266 'month':BEGIN267 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 30d/m268 time = julday(debut[1], debut[2], debut[0])+round(time*30) $269 ELSE for t = 0, n_elements(time)-1 DO $270 time[t] = julday(debut[1]+time[t], debut[2], debut[0])271 END272 'year':BEGIN273 if total(fix(time) NE time) NE 0 then $ ; we switch to days with 365d/y274 time = julday(debut[1], debut[2], debut[0])+round(time*365) $275 ELSE for t = 0, n_elements(time)-1 do $276 time[t] = julday(debut[1], debut[2], debut[0]+time[t])277 END278 ENDCASE279 ;280 ; high frequency calendar: more than one element per day281 IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0282 date0fk = date2jul(19000101)283 IF keyword_set(fakecal) THEN time = date0fk+lindgen(jpt) $284 ELSE time = long(time)285 ;286 331 ENDELSE 287 332 END
Note: See TracChangeset
for help on using the changeset viewer.