1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; read NetCDF meshmask file created by OPA |
---|
5 | ; |
---|
6 | ; @categories |
---|
7 | ; Grid |
---|
8 | ; |
---|
9 | ; @examples |
---|
10 | ; IDL> ncdf_meshread [,' filename'] |
---|
11 | ; |
---|
12 | ; @param filename {in}{optional}{default='meshmask.nc'}{type=scalar string} |
---|
13 | ; Name of the meshmask file to read. If this name does not contain any "/" |
---|
14 | ; and if iodirectory keyword is not specified, then the common variable |
---|
15 | ; iodir will be used to define the mesh file path. |
---|
16 | ; |
---|
17 | ; @keyword GLAMBOUNDARY {default=those defined in the file}{type=2 elements vector} |
---|
18 | ; Longitude boundaries that should be used to visualize the data. |
---|
19 | ; lon2 > lon1 |
---|
20 | ; lon2 - lon1 le 360 |
---|
21 | ; By default, the common (cm_4mesh) variable key_shift will be automatically |
---|
22 | ; defined according to GLAMBOUNDARY. |
---|
23 | ; |
---|
24 | ; @keyword CHECKDAT |
---|
25 | ; Suppressed. Use <pro>micromeshmask</pro> to create an appropriate meshmask. |
---|
26 | ; |
---|
27 | ; @keyword ONEARTH {default=1}{type=scalar: 0 or 1} |
---|
28 | ; Force the manual definition of data localization on the earth or not |
---|
29 | ; 0) if the data are not on the earth |
---|
30 | ; 1) if the data are on earth (in that case we can for example use |
---|
31 | ; the labels 'longitude', 'latitude' in plots). |
---|
32 | ; The resulting value will be stored in the common (cm_4mesh) variable key_onearth |
---|
33 | ; ONEARTH=0 forces PERIODIC=0, SHIFT=0 and is cancelling GLAMBOUNDARY |
---|
34 | ; |
---|
35 | ; @keyword GETDIMENSIONS {default=0}{type=scalar: 0 or 1} |
---|
36 | ; Activate this keywords if you only want to know the dimension |
---|
37 | ; of the domain stored in the mesh file. This dimension will be |
---|
38 | ; defined in jpiglo, jpjglo, jpkglo (cm_4mesh common variables) |
---|
39 | ; |
---|
40 | ; @keyword PERIODIC {default=computed by using the first line of glamt}{type=scalar: 0 or 1} |
---|
41 | ; Force the manual definition of the grid zonal periodicity. |
---|
42 | ; The resulting value will be stored in the common (cm_4mesh) variable key_periodic |
---|
43 | ; PERIODIC=0 forces SHIFT=0 |
---|
44 | ; |
---|
45 | ; @keyword SHIFT {default=computed according to glamboundary}{type=scalar} |
---|
46 | ; Force the manual definition of the zonal shift that must be apply to the data. |
---|
47 | ; The resulting value will be stored in the common (cm_4mesh) variable key_shift |
---|
48 | ; Note that if key_periodic=0 then in any case key_shift = 0. |
---|
49 | ; |
---|
50 | ; @keyword STRCALLING {type=scalar string} |
---|
51 | ; the calling command used to call <pro>computegrid</pro> (this is used by <pro>xxx</pro>) |
---|
52 | ; |
---|
53 | ; @keyword STRIDE {default=[1, 1, 1]}{type=3 elements vector} |
---|
54 | ; Specify the stride in x, y and z direction. The resulting |
---|
55 | ; value will be stored in the common (cm_4mesh) variable key_stride |
---|
56 | ; |
---|
57 | ; @keyword _EXTRA |
---|
58 | ; Used to pass keywords to <pro>isafile</pro> |
---|
59 | ; |
---|
60 | ; @uses |
---|
61 | ; cm_4mesh |
---|
62 | ; cm_4data |
---|
63 | ; cm_4cal |
---|
64 | ; |
---|
65 | ; @restrictions |
---|
66 | ; ixminmesh, ixmaxmesh, iyminmesh, iymaxmesh, izminmesh, izmaxmesh must |
---|
67 | ; be defined before calling ncdf_meshread. If some of those values |
---|
68 | ; are equal to -1 they will be automatically defined |
---|
69 | ; |
---|
70 | ; @history |
---|
71 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
72 | ; 12/1999 |
---|
73 | ; July 2004, Sebastien Masson: Several modifications (micromeshmask, |
---|
74 | ; clean partial steps, clean use of key_stride, automatic definition |
---|
75 | ; of key_shift, ...) |
---|
76 | ; Oct. 2004, Sebastien Masson: add PERIODIC and SHIFT |
---|
77 | ; Aug. 2005, Sebastien Masson: some cleaning + english |
---|
78 | ; |
---|
79 | ; @version |
---|
80 | ; $Id$ |
---|
81 | ; |
---|
82 | ;- |
---|
83 | PRO ncdf_meshread, filename, GLAMBOUNDARY=glamboundary, CHECKDAT=checkdat $ |
---|
84 | , ONEARTH=onearth, GETDIMENSIONS=getdimensions $ |
---|
85 | , PERIODIC=periodic, SHIFT=shift, STRIDE=stride $ |
---|
86 | , STRCALLING=strcalling, _EXTRA=ex |
---|
87 | ; |
---|
88 | compile_opt idl2, strictarrsubs |
---|
89 | ; |
---|
90 | @cm_4mesh |
---|
91 | @cm_4data |
---|
92 | @cm_4cal |
---|
93 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
94 | @updatenew |
---|
95 | @updatekwd |
---|
96 | ENDIF |
---|
97 | ; |
---|
98 | tempsun = systime(1) ; for key_performance |
---|
99 | IF keyword_set(CHECKDAT) THEN BEGIN |
---|
100 | ras = report([' The keyword CHECKDAT has been suppressed (it could create bugs).', $ |
---|
101 | ' Remove it from the call of ncdf_meshread', $ |
---|
102 | ' Please use smallmeshmask.pro or micromeshmask.pro to create a', $ |
---|
103 | ' meshmask that has manageable size']) |
---|
104 | return |
---|
105 | ENDIF |
---|
106 | ;------------------------------------------------------- |
---|
107 | ; find meshfile name and open it! |
---|
108 | ;------------------------------------------------------- |
---|
109 | ; def of filename by default |
---|
110 | IF n_params() EQ 0 then filename = 'meshmask.nc' |
---|
111 | meshname = isafile(file = filename, iodirectory = iodir, _EXTRA = ex) |
---|
112 | meshname = meshname[0] |
---|
113 | ; |
---|
114 | noticebase = xnotice('Reading file !C '+meshname+'!C ...') |
---|
115 | ; if the meshmask is on tape archive ... get it back |
---|
116 | IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+meshname+' > /dev/null' |
---|
117 | cdfid = ncdf_open(meshname) |
---|
118 | inq = ncdf_inquire(cdfid) |
---|
119 | ;------------------------------------------------------------ |
---|
120 | ; dimensions |
---|
121 | ;------------------------------------------------------------ |
---|
122 | ncdf_diminq, cdfid, 'x', name, jpiglo |
---|
123 | ncdf_diminq, cdfid, 'y', name, jpjglo |
---|
124 | listdims = strlowcase(ncdf_listdims(cdfid)) |
---|
125 | IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpkglo ELSE BEGIN |
---|
126 | dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0] |
---|
127 | IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpkglo ELSE BEGIN |
---|
128 | dummy = report('We could not find the vertical dimension..., its name must be z or start with depth') |
---|
129 | stop |
---|
130 | ENDELSE |
---|
131 | ENDELSE |
---|
132 | ; |
---|
133 | if keyword_set(getdimensions) then begin |
---|
134 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
135 | ncdf_close, cdfid |
---|
136 | return |
---|
137 | endif |
---|
138 | ;------------------------------------------------------- |
---|
139 | ; check that all i[xyz]min[ax]mesh are well defined |
---|
140 | ;------------------------------------------------------- |
---|
141 | if n_elements(ixminmesh) EQ 0 THEN ixminmesh = 0 |
---|
142 | if n_elements(ixmaxmesh) EQ 0 then ixmaxmesh = jpiglo-1 |
---|
143 | if ixminmesh EQ -1 THEN ixminmesh = 0 |
---|
144 | IF ixmaxmesh EQ -1 then ixmaxmesh = jpiglo-1 |
---|
145 | if n_elements(iyminmesh) EQ 0 THEN iyminmesh = 0 |
---|
146 | IF n_elements(iymaxmesh) EQ 0 then iymaxmesh = jpjglo-1 |
---|
147 | if iyminmesh EQ -1 THEN iyminmesh = 0 |
---|
148 | IF iymaxmesh EQ -1 then iymaxmesh = jpjglo-1 |
---|
149 | if n_elements(izminmesh) EQ 0 THEN izminmesh = 0 |
---|
150 | IF n_elements(izmaxmesh) EQ 0 then izmaxmesh = jpkglo-1 |
---|
151 | if izminmesh EQ -1 THEN izminmesh = 0 |
---|
152 | IF izmaxmesh EQ -1 then izmaxmesh = jpkglo-1 |
---|
153 | ; definition of jpi,jpj,jpj |
---|
154 | jpi = long(ixmaxmesh-ixminmesh+1) |
---|
155 | jpj = long(iymaxmesh-iyminmesh+1) |
---|
156 | jpk = long(izmaxmesh-izminmesh+1) |
---|
157 | ;------------------------------------------------------- |
---|
158 | ; check onearth and its consequences |
---|
159 | ;------------------------------------------------------- |
---|
160 | IF n_elements(onearth) EQ 0 THEN key_onearth = 1 $ |
---|
161 | ELSE key_onearth = keyword_set(onearth) |
---|
162 | IF NOT key_onearth THEN BEGIN |
---|
163 | periodic = 0 |
---|
164 | shift = 0 |
---|
165 | ENDIF |
---|
166 | ;------------------------------------------------------- |
---|
167 | ; automatic definition of key_periodic |
---|
168 | ;------------------------------------------------------- |
---|
169 | IF n_elements(periodic) EQ 0 THEN BEGIN |
---|
170 | IF jpi GT 1 THEN BEGIN |
---|
171 | varinq = ncdf_varinq(cdfid, 'glamt') |
---|
172 | CASE varinq.ndims OF |
---|
173 | 2:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
174 | , offset = [ixminmesh, iyminmesh], count = [jpi, 1] |
---|
175 | 3:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
176 | , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1] |
---|
177 | 4:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
178 | , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1] |
---|
179 | ENDCASE |
---|
180 | xaxis = (xaxis+720) MOD 360 |
---|
181 | xaxis = xaxis[sort(xaxis)] |
---|
182 | key_periodic = (xaxis[jpi-1]+2*(xaxis[jpi-1]-xaxis[jpi-2])) $ |
---|
183 | GE (xaxis[0]+360) |
---|
184 | ENDIF ELSE key_periodic = 0 |
---|
185 | ENDIF ELSE key_periodic = keyword_set(periodic) |
---|
186 | ;------------------------------------------------------- |
---|
187 | ; automatic definition of key_shift |
---|
188 | ;------------------------------------------------------- |
---|
189 | IF n_elements(shift) EQ 0 THEN BEGIN |
---|
190 | key_shift = long(testvar(var = key_shift)) |
---|
191 | ; key_shift will be defined according to the first line of glamt. |
---|
192 | if keyword_set(glamboundary) AND jpi GT 1 AND key_periodic EQ 1 $ |
---|
193 | THEN BEGIN |
---|
194 | varinq = ncdf_varinq(cdfid, 'glamt') |
---|
195 | CASE varinq.ndims OF |
---|
196 | 2:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
197 | , offset = [ixminmesh, iyminmesh], count = [jpi, 1] |
---|
198 | 3:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
199 | , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1] |
---|
200 | 4:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
201 | , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1] |
---|
202 | ENDCASE |
---|
203 | ; xaxis between glamboundary[0] and glamboundary[1] |
---|
204 | xaxis = xaxis MOD 360 |
---|
205 | smaller = where(xaxis LT glamboundary[0]) |
---|
206 | if smaller[0] NE -1 then xaxis[smaller] = xaxis[smaller]+360 |
---|
207 | bigger = where(xaxis GE glamboundary[1]) |
---|
208 | if bigger[0] NE -1 then xaxis[bigger] = xaxis[bigger]-360 |
---|
209 | ; |
---|
210 | key_shift = (where(xaxis EQ min(xaxis)))[0] |
---|
211 | IF key_shift NE 0 THEN BEGIN |
---|
212 | key_shift = jpi-key_shift |
---|
213 | xaxis = shift(xaxis, key_shift) |
---|
214 | ENDIF |
---|
215 | ; |
---|
216 | IF array_equal(sort(xaxis), lindgen(jpi)) NE 1 THEN BEGIN |
---|
217 | ras = report(['the x axis (1st line of glamt) is not sorted in the increasing order after the automatic definition of key_shift', $ |
---|
218 | 'please use the keyword shift (and periodic) to suppress the automatic definition of key_shift (and key_periodic) and define by hand a more suitable value...']) |
---|
219 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
220 | return |
---|
221 | ENDIF |
---|
222 | ; |
---|
223 | ENDIF ELSE key_shift = 0 |
---|
224 | ENDIF ELSE key_shift = long(shift)*(key_periodic EQ 1) |
---|
225 | ;------------------------------------------------------- |
---|
226 | ; check key_stride and related things |
---|
227 | ;------------------------------------------------------- |
---|
228 | if n_elements(stride) eq 3 then key_stride = stride |
---|
229 | if n_elements(key_stride) LE 2 then key_stride = [1, 1, 1] |
---|
230 | key_stride = 1l > long(key_stride) |
---|
231 | IF total(key_stride) NE 3 THEN BEGIN |
---|
232 | IF key_shift NE 0 THEN BEGIN |
---|
233 | ; for explanation, see header of read_ncdf_varget.pro |
---|
234 | jpiright = key_shift |
---|
235 | jpileft = jpi - key_shift - ( (key_stride[0]-1)-((key_shift-1) MOD key_stride[0]) ) |
---|
236 | jpi = ((jpiright-1)/key_stride[0]+1) + ((jpileft-1)/key_stride[0]+1) |
---|
237 | ENDIF ELSE jpi = (jpi-1)/key_stride[0]+1 |
---|
238 | jpj = (jpj-1)/key_stride[1]+1 |
---|
239 | jpk = (jpk-1)/key_stride[2]+1 |
---|
240 | ENDIF |
---|
241 | ;------------------------------------------------------- |
---|
242 | ; default definitions to be able to use read_ncdf_varget |
---|
243 | ;------------------------------------------------------- |
---|
244 | ; default definitions to be able to use read_ncdf_varget |
---|
245 | ixmindtasauve = testvar(var = ixmindta) |
---|
246 | iymindtasauve = testvar(var = iymindta) |
---|
247 | izmindtasauve = testvar(var = izmindta) |
---|
248 | ; |
---|
249 | ixmindta = 0l |
---|
250 | iymindta = 0l |
---|
251 | izmindta = 0l |
---|
252 | ; |
---|
253 | jpt = 1 |
---|
254 | time = 1 |
---|
255 | firsttps = 0 |
---|
256 | ; |
---|
257 | firstx = 0 |
---|
258 | lastx = jpi-1 |
---|
259 | firsty = 0 |
---|
260 | lasty = jpj-1 |
---|
261 | firstz = 0 |
---|
262 | lastz = jpk-1 |
---|
263 | nx = jpi |
---|
264 | ny = jpj |
---|
265 | nz = 1 |
---|
266 | izminmeshsauve = izminmesh |
---|
267 | izminmesh = 0 |
---|
268 | ; |
---|
269 | key_yreverse = 0 |
---|
270 | key_zreverse = 0 |
---|
271 | key_gridtype = 'c' |
---|
272 | ;------------------------------------------------------- |
---|
273 | ; 2d arrays: |
---|
274 | ;------------------------------------------------------- |
---|
275 | ; list the 2d variables that must be read |
---|
276 | namevar = ['glamt', 'glamu', 'glamv', 'glamf' $ |
---|
277 | , 'gphit', 'gphiu', 'gphiv', 'gphif' $ |
---|
278 | , 'e1t', 'e1u', 'e1v', 'e1f' $ |
---|
279 | , 'e2t', 'e2u', 'e2v', 'e2f'] |
---|
280 | ; for the variables related to the partial steps |
---|
281 | allvarname = ncdf_listvars(cdfid) |
---|
282 | IF (where(allvarname EQ 'hdept'))[0] NE -1 THEN BEGIN |
---|
283 | key_partialstep = 1 |
---|
284 | namevar = [namevar, 'hdept', 'hdepw'] |
---|
285 | ENDIF ELSE BEGIN |
---|
286 | key_partialstep = 0 |
---|
287 | hdept = -1 |
---|
288 | hdepw = -1 |
---|
289 | ENDELSE |
---|
290 | ; for compatibility with old versions of meshmask/partial steps |
---|
291 | IF (where(allvarname EQ 'e3tp'))[0] NE -1 THEN $ |
---|
292 | namevar = [namevar, 'e3tp', 'e3wp'] ELSE BEGIN |
---|
293 | e3t_ps = -1 |
---|
294 | e3w_ps = -1 |
---|
295 | ENDELSE |
---|
296 | IF (where(allvarname EQ 'e3t_ps'))[0] NE -1 $ |
---|
297 | THEN namevar = [namevar, 'e3t_ps', 'e3w_ps' ]ELSE BEGIN |
---|
298 | e3t_ps = -1 |
---|
299 | e3w_ps = -1 |
---|
300 | ENDELSE |
---|
301 | IF (where(allvarname EQ 'e3u_ps'))[0] NE -1 $ |
---|
302 | THEN namevar = [namevar, 'e3u_ps', 'e3v_ps'] ELSE BEGIN |
---|
303 | e3u_ps = -1 |
---|
304 | e3v_ps = -1 |
---|
305 | ENDELSE |
---|
306 | ; |
---|
307 | ; read all the 2d variables |
---|
308 | ; |
---|
309 | for i = 0, n_elements(namevar)-1 do begin |
---|
310 | varinq = ncdf_varinq(cdfid, namevar[i]) |
---|
311 | name = varinq.name |
---|
312 | @read_ncdf_varget |
---|
313 | command = namevar[i]+'=float(temporary(res))' |
---|
314 | nothing = execute(command) |
---|
315 | ENDFOR |
---|
316 | ; for compatibility with old versions of meshmask/partial steps |
---|
317 | ; change e3[tw]p to e3[tw]_ps |
---|
318 | IF n_elements(e3tp) NE 0 THEN e3t_ps = temporary(e3tp) |
---|
319 | IF n_elements(e3wp) NE 0 THEN e3w_ps = temporary(e3wp) |
---|
320 | ; in the case of key_stride ne [1, 1, 1] redefine f points |
---|
321 | ; coordinates: they must be in the middle of 3 T points |
---|
322 | if key_stride[0] NE 1 OR key_stride[1] NE 1 then BEGIN |
---|
323 | ; we must recompute glamf and gphif... |
---|
324 | IF jpi GT 1 THEN BEGIN |
---|
325 | if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $ |
---|
326 | OR (keyword_set(key_periodic) AND key_irregular) then BEGIN |
---|
327 | stepxf = (glamt + 720) MOD 360 |
---|
328 | stepxf = shift(stepxf, -1, -1) - stepxf |
---|
329 | stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ] |
---|
330 | stepxf = min(abs(stepxf), dimension = 3) |
---|
331 | IF NOT keyword_set(key_periodic) THEN $ |
---|
332 | stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
333 | ENDIF ELSE BEGIN |
---|
334 | stepxf = shift(glamt, -1, -1) - glamt |
---|
335 | IF keyword_set(key_periodic) THEN $ |
---|
336 | stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $ |
---|
337 | ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
338 | ENDELSE |
---|
339 | IF jpj GT 1 THEN BEGIN |
---|
340 | stepxf[*, jpj-1] = stepxf[*, jpj-2] |
---|
341 | stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2] |
---|
342 | ENDIF |
---|
343 | glamf = glamt + 0.5 * stepxf |
---|
344 | ENDIF ELSE glamf = glamt + 0.5 |
---|
345 | IF jpj GT 1 THEN BEGIN |
---|
346 | ; we must compute stepyf: y distance between T(i,j) T(i+1,j+1) |
---|
347 | stepyf = shift(gphit, -1, -1) - gphit |
---|
348 | stepyf[*, jpj-1] = stepyf[*, jpj-2] |
---|
349 | IF jpi GT 1 THEN BEGIN |
---|
350 | if NOT keyword_set(key_periodic) THEN $ |
---|
351 | stepyf[jpi-1, *] = stepyf[jpi-2, *] |
---|
352 | stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2] |
---|
353 | ENDIF |
---|
354 | gphif = gphit + 0.5 * stepyf |
---|
355 | ENDIF ELSE gphif = gphit + 0.5 |
---|
356 | ENDIF |
---|
357 | ;------------------------------------------------------- |
---|
358 | ; 3d arrays: |
---|
359 | ;------------------------------------------------------- |
---|
360 | nz = jpk |
---|
361 | izminmesh = izminmeshsauve |
---|
362 | ; |
---|
363 | listdims = ncdf_listdims(cdfid) |
---|
364 | micromask = (where(listdims EQ 'y_m'))[0] |
---|
365 | ; |
---|
366 | varinq = ncdf_varinq(cdfid, 'tmask') |
---|
367 | name = varinq.name |
---|
368 | IF micromask NE -1 THEN BEGIN |
---|
369 | ; keep original values |
---|
370 | iyminmeshtrue = iyminmesh |
---|
371 | key_stridetrue = key_stride |
---|
372 | yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue |
---|
373 | yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue |
---|
374 | ; the mask is stored as the bit values of the byte array (along the y |
---|
375 | ; dimension, see micromeshmask.pro)... |
---|
376 | ; we must modify several parameters... |
---|
377 | iyminmesh = 0L |
---|
378 | firsty = yyy1/8 |
---|
379 | lasty = yyy2/8 |
---|
380 | ny = lasty-firsty+1 |
---|
381 | key_stride = [key_stride[0], 1, key_stride[2]] |
---|
382 | @read_ncdf_varget |
---|
383 | tmask = bytarr(jpi, jpj, jpk) |
---|
384 | ; now we must get back the mask |
---|
385 | ; loop on the level to save memory (the loop is short and, thus, |
---|
386 | ; should be fast enough) |
---|
387 | FOR k = 0, jpk-1 DO BEGIN |
---|
388 | zzz = transpose(res[*, *, k]) |
---|
389 | zzz = reform(binary(zzz), 8*ny, nx, /over) |
---|
390 | zzz = transpose(temporary(zzz)) |
---|
391 | zzz = zzz[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8] |
---|
392 | IF key_stridetrue[1] NE 1 THEN BEGIN |
---|
393 | ; IF float(strmid(!version.release,0,3)) LT 5.6 THEN BEGIN |
---|
394 | nnny = (size(zzz))[2] |
---|
395 | yind = key_stridetrue[1]*lindgen((nnny-1)/key_stridetrue[1]+1) |
---|
396 | tmask[*, *, k] = temporary(zzz[*, yind]) |
---|
397 | ; ENDIF ELSE tmask[*, *, k] = temporary(zzz[*, 0:*:key_stridetrue[1]]) |
---|
398 | ENDIF ELSE tmask[*, *, k] = temporary(zzz) |
---|
399 | ENDFOR |
---|
400 | ENDIF ELSE BEGIN |
---|
401 | @read_ncdf_varget |
---|
402 | tmask = byte(res) |
---|
403 | ENDELSE |
---|
404 | ; boundary conditions used to compute umask. |
---|
405 | varinq = ncdf_varinq(cdfid, 'umask') |
---|
406 | name = varinq.name |
---|
407 | nx = 1L |
---|
408 | firstx = jpi-1 |
---|
409 | lastx = jpi-1 |
---|
410 | IF micromask NE -1 THEN BEGIN |
---|
411 | @read_ncdf_varget |
---|
412 | umaskred = reform(binary(res), 8*ny, jpk, /over) |
---|
413 | umaskred = umaskred[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *] |
---|
414 | IF key_stridetrue[1] NE 1 THEN umaskred = temporary(umaskred[yind, *]) |
---|
415 | ENDIF ELSE BEGIN |
---|
416 | @read_ncdf_varget |
---|
417 | umaskred = reform(byte(res), /over) |
---|
418 | ENDELSE |
---|
419 | ; boundary conditions used to compute fmask (1). |
---|
420 | varinq = ncdf_varinq(cdfid, 'fmask') |
---|
421 | name = varinq.name |
---|
422 | IF micromask NE -1 THEN BEGIN |
---|
423 | @read_ncdf_varget |
---|
424 | fmaskredy = reform(binary(res), 8*ny, jpk, /over) |
---|
425 | fmaskredy = fmaskredy[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *] |
---|
426 | IF key_stridetrue[1] NE 1 THEN fmaskredy = temporary(fmaskredy[yind, *]) |
---|
427 | ENDIF ELSE BEGIN |
---|
428 | @read_ncdf_varget |
---|
429 | fmaskredy = reform(byte(res), /over) |
---|
430 | fmaskredy = temporary(fmaskredy) MOD 2 |
---|
431 | ENDELSE |
---|
432 | ; boundary conditions used to compute vmask |
---|
433 | varinq = ncdf_varinq(cdfid, 'vmask') |
---|
434 | name = varinq.name |
---|
435 | nx = jpi |
---|
436 | firstx = 0L |
---|
437 | lastx = jpi-1L |
---|
438 | ny = 1L |
---|
439 | firsty = jpj-1 |
---|
440 | lasty = jpj-1 |
---|
441 | IF micromask NE -1 THEN BEGIN |
---|
442 | yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue |
---|
443 | yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue |
---|
444 | iyminmesh = 0L |
---|
445 | firsty = yyy1/8 |
---|
446 | lasty = yyy2/8 |
---|
447 | ny = lasty-firsty+1 |
---|
448 | @read_ncdf_varget |
---|
449 | IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over) |
---|
450 | vmaskred = transpose(temporary(res), [1, 0, 2]) |
---|
451 | vmaskred = reform(binary(vmaskred), 8*ny, nx, nz, /over) |
---|
452 | vmaskred = transpose(temporary(vmaskred), [1, 0, 2]) |
---|
453 | vmaskred = reform(vmaskred[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]) |
---|
454 | ENDIF ELSE BEGIN |
---|
455 | @read_ncdf_varget |
---|
456 | vmaskred = reform(byte(res), /over) |
---|
457 | ENDELSE |
---|
458 | ; boundary conditions used to compute fmask (2). |
---|
459 | varinq = ncdf_varinq(cdfid, 'fmask') |
---|
460 | name = varinq.name |
---|
461 | IF micromask NE -1 THEN BEGIN |
---|
462 | @read_ncdf_varget |
---|
463 | IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over) |
---|
464 | fmaskredx = transpose(temporary(res), [1, 0, 2]) |
---|
465 | fmaskredx = reform(binary(fmaskredx), 8*ny, nx, nz, /over) |
---|
466 | fmaskredx = transpose(temporary(fmaskredx), [1, 0, 2]) |
---|
467 | fmaskredx = reform(fmaskredx[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]) |
---|
468 | ; |
---|
469 | iyminmesh = iyminmeshtrue |
---|
470 | key_stride = key_stridetrue |
---|
471 | ENDIF ELSE BEGIN |
---|
472 | @read_ncdf_varget |
---|
473 | fmaskredx = reform(byte(res), /over) |
---|
474 | fmaskredx = fmaskredx MOD 2 |
---|
475 | ENDELSE |
---|
476 | ;------------------------------------------------------- |
---|
477 | ; 1d arrays |
---|
478 | ;------------------------------------------------------- |
---|
479 | IF (where(allvarname EQ 'e3t_0'))[0] NE -1 THEN fnamevar = ['e3t_0', 'e3w_0', 'gdept_0', 'gdepw_0'] $ |
---|
480 | ELSE fnamevar = ['e3t', 'e3w', 'gdept', 'gdepw'] |
---|
481 | namevar = ['e3t', 'e3w', 'gdept', 'gdepw'] |
---|
482 | for i = 0, n_elements(namevar)-1 do begin |
---|
483 | varinq = ncdf_varinq(cdfid, fnamevar[i]) |
---|
484 | CASE n_elements(varinq.dim) OF |
---|
485 | 4:BEGIN |
---|
486 | command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $ |
---|
487 | +',offset = [0,0,izminmesh,0], count = [1,1,jpk,1]' |
---|
488 | if key_stride[2] NE 1 then command = command+', stride=[1,1,key_stride[2],1]' |
---|
489 | END |
---|
490 | 2:BEGIN |
---|
491 | command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $ |
---|
492 | +',offset = [izminmesh,0], count = [jpk,1]' |
---|
493 | if key_stride[2] NE 1 then command = command+', stride=key_stride[2]' |
---|
494 | END |
---|
495 | 1:BEGIN |
---|
496 | command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $ |
---|
497 | +',offset = [izminmesh], count = [jpk]' |
---|
498 | if key_stride[2] NE 1 then command = command+', stride=key_stride[2]' |
---|
499 | END |
---|
500 | ENDCASE |
---|
501 | nothing = execute(command) |
---|
502 | command = namevar[i]+'=float('+namevar[i]+')' |
---|
503 | nothing = execute(command) |
---|
504 | command = 'if size('+namevar[i]+', /n_dimension) gt 0 then '+namevar[i]+' = reform('+namevar[i]+', /over)' |
---|
505 | nothing = execute(command) |
---|
506 | ENDFOR |
---|
507 | ;------------------------------------------------------- |
---|
508 | ncdf_close, cdfid |
---|
509 | ;------------------------------------------------------- |
---|
510 | ; Apply Glamboundary |
---|
511 | ;------------------------------------------------------- |
---|
512 | if keyword_set(glamboundary) AND key_onearth then BEGIN |
---|
513 | if glamboundary[0] NE glamboundary[1] then BEGIN |
---|
514 | glamt = temporary(glamt) MOD 360 |
---|
515 | smaller = where(glamt LT glamboundary[0]) |
---|
516 | if smaller[0] NE -1 then glamt[smaller] = glamt[smaller]+360 |
---|
517 | bigger = where(glamt GE glamboundary[1]) |
---|
518 | if bigger[0] NE -1 then glamt[bigger] = glamt[bigger]-360 |
---|
519 | glamu = temporary(glamu) MOD 360 |
---|
520 | smaller = where(glamu LT glamboundary[0]) |
---|
521 | if smaller[0] NE -1 then glamu[smaller] = glamu[smaller]+360 |
---|
522 | bigger = where(glamu GE glamboundary[1]) |
---|
523 | if bigger[0] NE -1 then glamu[bigger] = glamu[bigger]-360 |
---|
524 | glamv = temporary(glamv) MOD 360 |
---|
525 | smaller = where(glamv LT glamboundary[0]) |
---|
526 | if smaller[0] NE -1 then glamv[smaller] = glamv[smaller]+360 |
---|
527 | bigger = where(glamv GE glamboundary[1]) |
---|
528 | if bigger[0] NE -1 then glamv[bigger] = glamv[bigger]-360 |
---|
529 | glamf = temporary(glamf) MOD 360 |
---|
530 | smaller = where(glamf LT glamboundary[0]) |
---|
531 | if smaller[0] NE -1 then glamf[smaller] = glamf[smaller]+360 |
---|
532 | bigger = where(glamf GE glamboundary[1]) |
---|
533 | if bigger[0] NE -1 then glamf[bigger] = glamf[bigger]-360 |
---|
534 | toosmall = where(glamu EQ glamboundary[0]) |
---|
535 | IF toosmall[0] NE -1 THEN glamu[toosmall] = glamu[toosmall] + 360 |
---|
536 | toosmall = where(glamf EQ glamboundary[0]) |
---|
537 | IF toosmall[0] NE -1 THEN glamf[toosmall] = glamf[toosmall] + 360 |
---|
538 | endif |
---|
539 | endif |
---|
540 | ;------------------------------------------------------- |
---|
541 | ; make sure we do have 2d arrays when jpj eq 1 |
---|
542 | ;------------------------------------------------------- |
---|
543 | IF jpj EQ 1 THEN BEGIN |
---|
544 | glamt = reform(glamt, jpi, jpj, /over) |
---|
545 | gphit = reform(gphit, jpi, jpj, /over) |
---|
546 | e1t = reform(e1t, jpi, jpj, /over) |
---|
547 | e2t = reform(e2t, jpi, jpj, /over) |
---|
548 | glamu = reform(glamu, jpi, jpj, /over) |
---|
549 | gphiu = reform(gphiu, jpi, jpj, /over) |
---|
550 | e1u = reform(e1u, jpi, jpj, /over) |
---|
551 | e2u = reform(e2u, jpi, jpj, /over) |
---|
552 | glamv = reform(glamv, jpi, jpj, /over) |
---|
553 | gphiv = reform(gphiv, jpi, jpj, /over) |
---|
554 | e1v = reform(e1v, jpi, jpj, /over) |
---|
555 | e2v = reform(e2v, jpi, jpj, /over) |
---|
556 | glamf = reform(glamf, jpi, jpj, /over) |
---|
557 | gphif = reform(gphif, jpi, jpj, /over) |
---|
558 | e1f = reform(e1f, jpi, jpj, /over) |
---|
559 | e2f = reform(e2f, jpi, jpj, /over) |
---|
560 | IF keyword_set(key_partialstep) THEN BEGIN |
---|
561 | hdept = reform(hdept, jpi, jpj, /over) |
---|
562 | hdepw = reform(hdepw, jpi, jpj, /over) |
---|
563 | e3t_ps = reform(e3t_ps, jpi, jpj, /over) |
---|
564 | e3w_ps = reform(e3w_ps, jpi, jpj, /over) |
---|
565 | ENDIF |
---|
566 | ENDIF |
---|
567 | ;------------------------------------------------------- |
---|
568 | ixmindta = ixmindtasauve |
---|
569 | iymindta = iymindtasauve |
---|
570 | izmindta = izmindtasauve |
---|
571 | ;------------------------------------------------------- |
---|
572 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
573 | ; |
---|
574 | ;==================================================== |
---|
575 | ; grid parameters used by xxx |
---|
576 | ;==================================================== |
---|
577 | ; |
---|
578 | IF NOT keyword_set(strcalling) THEN BEGIN |
---|
579 | IF n_elements(ccmeshparameters) EQ 0 THEN strcalling = 'ncdf_meshread' $ |
---|
580 | ELSE strcalling = ccmeshparameters.filename |
---|
581 | ENDIF |
---|
582 | IF n_elements(glamt) GE 2 THEN BEGIN |
---|
583 | glaminfo = moment(glamt) |
---|
584 | IF finite(glaminfo[2]) EQ 0 THEN glaminfo = glaminfo[0:1] |
---|
585 | gphiinfo = moment(gphit) |
---|
586 | IF finite(gphiinfo[2]) EQ 0 THEN gphiinfo = gphiinfo[0:1] |
---|
587 | ENDIF ELSE BEGIN |
---|
588 | glaminfo = glamt |
---|
589 | gphiinfo = gphit |
---|
590 | ENDELSE |
---|
591 | romszinfos = {h:-1, zeta:-1, theta_s:-1, theta_b:-1, hc:-1} |
---|
592 | ccmeshparameters = {filename:strcalling $ |
---|
593 | , glaminfo:float(string(glaminfo, format = '(E11.4)')) $ |
---|
594 | , gphiinfo:float(string(gphiinfo, format = '(E11.4)')) $ |
---|
595 | , jpiglo:jpiglo, jpjglo:jpjglo, jpkglo:jpkglo $ |
---|
596 | , jpi:jpi, jpj:jpj, jpk:jpk $ |
---|
597 | , ixminmesh:ixminmesh, ixmaxmesh:ixmaxmesh $ |
---|
598 | , iyminmesh:iyminmesh, iymaxmesh:iymaxmesh $ |
---|
599 | , izminmesh:izminmesh, izmaxmesh:izmaxmesh $ |
---|
600 | , key_shift:key_shift, key_periodic:key_periodic $ |
---|
601 | , key_stride:key_stride, key_gridtype:key_gridtype $ |
---|
602 | , key_yreverse:key_yreverse, key_zreverse:key_zreverse $ |
---|
603 | , key_partialstep:key_partialstep, key_onearth:key_onearth} |
---|
604 | ; |
---|
605 | if keyword_set(key_performance) THEN $ |
---|
606 | print, 'time ncdf_meshread', systime(1)-tempsun |
---|
607 | |
---|
608 | ;------------------------------------------------------- |
---|
609 | @updateold |
---|
610 | ;------------------------------------------------------- |
---|
611 | return |
---|
612 | end |
---|