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