1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; |
---|
6 | ; @file_comments compute the grid parameters from cm_4mesh common: |
---|
7 | ; |
---|
8 | ; computegrid, startx, starty, stepx, stepy, nx, ny |
---|
9 | ; computegrid, startx, starty, stepx, stepy |
---|
10 | ; computegrid, xaxis = xaxis, yaxis = yaxis |
---|
11 | ; or a suitable mix... |
---|
12 | ; |
---|
13 | ; glamt |
---|
14 | ; glamf |
---|
15 | ; gphit |
---|
16 | ; gphi |
---|
17 | ; e1t |
---|
18 | ; e2t |
---|
19 | ; horizontal parameters |
---|
20 | ; |
---|
21 | ; glamu {in} |
---|
22 | ; glamv {in} |
---|
23 | ; gphiu {in} |
---|
24 | ; gphiv {in} |
---|
25 | ; e1u {in} |
---|
26 | ; e1v {in} |
---|
27 | ; e1f {in} |
---|
28 | ; e2u {in} |
---|
29 | ; e2v {in} |
---|
30 | ; e2f {in} |
---|
31 | ; horizontal parameters if FULLCGRID keyword is defined |
---|
32 | ; |
---|
33 | ; gdept |
---|
34 | ; gdepw |
---|
35 | ; e3t |
---|
36 | ; e3w |
---|
37 | ; verticals parameters |
---|
38 | ; |
---|
39 | ; tmask |
---|
40 | ; masks |
---|
41 | ; |
---|
42 | ; umaskred {in} |
---|
43 | ; vmaskred {in} |
---|
44 | ; fmaskredx {in} |
---|
45 | ; fmaskredy {in} |
---|
46 | ; masks if FULLCGRID keyword is defined |
---|
47 | ; |
---|
48 | ; triangles_list |
---|
49 | ; triangulation |
---|
50 | ; |
---|
51 | ; @categories grid |
---|
52 | ; |
---|
53 | ; @param startx {in}{required} scalar, x starting point |
---|
54 | ; @param starty {in}{required} scalar, y starting point |
---|
55 | ; @param stepxin {in}{required} scalar or vector: x direction step, must be > 0 |
---|
56 | ; if vector nx is not used |
---|
57 | ; @param stepyin {in}{required} scalar or vector: y direction step, |
---|
58 | ; could be > 0 (south to north) or < 0 (north to south) |
---|
59 | ; if vector ny is not used |
---|
60 | ; @param nxin {in}{required} scalar, number of points in x direction |
---|
61 | ; @param nyin {in}{required} scalar, number of points in y direction |
---|
62 | ; |
---|
63 | ; @keyword FULLCGRID activate to specify that you want to compute |
---|
64 | ; all the paremeters of a C grid. Computation of glam[uv], |
---|
65 | ; gphi[uv], e1[uvf], e2[uvf], [uv]maskred and fmaskred[xy] |
---|
66 | ; will be add to the default computations |
---|
67 | ; |
---|
68 | ; @keyword GLAMBOUNDARY a 2 elements vector, [lon1,lon2], the longitude |
---|
69 | ; boundaries that should be used to visualize the data. |
---|
70 | ; we must have lon2 > lon1 and lon2 - lon1 le 360 |
---|
71 | ; key_shift will be defined automaticaly computed according to |
---|
72 | ; glamboundary by using the FIRST LINE of glamt but |
---|
73 | ; key_shift will /= 0 only if key_periodic = 1 |
---|
74 | ; |
---|
75 | ; @keyword MASK to specify the mask with a 2 or 3 dimension array |
---|
76 | ; |
---|
77 | ; @keyword ONEARTH = 0 or 1 to force the manual definition of |
---|
78 | ; key_onearth (to specify if the data are on earth -> use longitude |
---|
79 | ; /latitude etc...). By default, key_onearth = 1. |
---|
80 | ; note that ONEARTH = 0 forces PERIODIC = 0, SHIFT = 0, |
---|
81 | ; and is cancelling GLAMBOUNDARY |
---|
82 | ; |
---|
83 | ; @keyword PERIODIC = 0 or 1 to force the manual definition of |
---|
84 | ; key_periodic. By default, key_periodic is automaticaly |
---|
85 | ; computed by using the first line of glamt. |
---|
86 | ; |
---|
87 | ; @keyword PLAIN force PERIODIC = 0, SHIFT = 0, STRIDE = [1, 1, 1] and |
---|
88 | ; suppress the automatic redefinition of the domain in case of |
---|
89 | ; x periodicity overlap, y periodicity overlap (ORCA type only) |
---|
90 | ; and mask border to 0. |
---|
91 | ; |
---|
92 | ; @keyword SHIFT = scalar to force the manual definition of key_shift. By |
---|
93 | ; default, key_shift is automaticaly computed according to |
---|
94 | ; glamboundary (when defined) by using the FIRST LINE of glamt. if |
---|
95 | ; key_periodic=0 then in any case key_shift = 0. |
---|
96 | ; |
---|
97 | ; @keyword STRCALLING a string containing the calling command used to |
---|
98 | ; call computegrid (this is used by xxx.pro) |
---|
99 | ; |
---|
100 | ; @keyword STRIDE {default=[1, 1, 1]} a 3 elements vector to specify the stride in x, y, z |
---|
101 | ; direction. The resulting value |
---|
102 | ; will be stored in the common (cm_4mesh) variable key_stride |
---|
103 | ; |
---|
104 | ; @keyword XAXIS to specify longitude1 with a 1 or 2 dimension array, in |
---|
105 | ; this case startx, stepx and nx are not used but could be |
---|
106 | ; necessary if the y axis is not defined with yaxis. It must be |
---|
107 | ; possible to sort the first line of xaxis in the increasing |
---|
108 | ; order by shifting its elements. |
---|
109 | ; |
---|
110 | ; @keyword YAXIS to specify latitudes with a 1 or 2 dimension array, in |
---|
111 | ; this case starty, stepy and ny are not used but starty and |
---|
112 | ; stepy could be necessary if the x axis is not defined with xaxis. |
---|
113 | ; It must be sorted in the increasing or deceasing order |
---|
114 | ; (along each column if 2d array). |
---|
115 | ; |
---|
116 | ; @keyword XYINDEX activate to specify that the horizontal grid should |
---|
117 | ; be simply defined by using the index of the points |
---|
118 | ; (xaxis = findgen(nx) and yaxis = findgen(ny)) |
---|
119 | ; using this keyword forces key_onearth=0 |
---|
120 | ; |
---|
121 | ; @keyword XMINMESH {default=0L} |
---|
122 | ; @keyword YMINMESH {default=0L} |
---|
123 | ; @keyword ZMINMESH {default=0L} |
---|
124 | ; to define the common variables i[xyz]minmesh |
---|
125 | ; used to define the grid only in a zoomed part of the original |
---|
126 | ; grid. max value is [XYZ]MAXMESH |
---|
127 | ; |
---|
128 | ; @keyword XMAXMESH {default=jpiglo-1} |
---|
129 | ; @keyword YMAXMESH {default=jpjglo-1} |
---|
130 | ; @keyword ZMAXMESH {default=jpkglo-1} |
---|
131 | ; to define the common variables i[xyz]maxmesh |
---|
132 | ; used to define the grid only in a zoomed part of the original |
---|
133 | ; grid. max value is jp[ijk]glo-1. |
---|
134 | ; if [XYZ]MAXMESH is negative, then we define i[xyz]maxmesh as |
---|
135 | ; jp[ijk]glo - 1 + [XYZ]MAXMESH instead of [XYZ]MAXMESH |
---|
136 | ; |
---|
137 | ; @keyword FBASE2TBASE |
---|
138 | ; |
---|
139 | ; @keyword STRCALLING |
---|
140 | ; |
---|
141 | ; @keyword ZAXIS to specify the vertical axis with a 1 dimension |
---|
142 | ; array. Must be sorted in the increasing or deceasing order |
---|
143 | ; |
---|
144 | ; @keyword _EXTRA used to pass your keywords to the created function. |
---|
145 | ; |
---|
146 | ; @uses cm_4mesh cm_4data cm_4cal |
---|
147 | ; |
---|
148 | ; @restrictions if the grid has x/y periodicity orverlap and/or if |
---|
149 | ; the mask has 0 everywhere at the border (like a close sea) and |
---|
150 | ; if (we did not activate /plain and xminmesh, xmaxmesh, yminmesh, |
---|
151 | ; ymaxmesh keywords are defined to their default values), we redefine |
---|
152 | ; xminmesh, xmaxmesh, yminmesh, ymaxmesh in order to reove the |
---|
153 | ; overlapping part and/or to open the domain (avoid ti be forced |
---|
154 | ; to use cell_fill = 1). |
---|
155 | ; |
---|
156 | ; @restrictions FUV points definition... |
---|
157 | ; |
---|
158 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
159 | ; 2000-04-20 |
---|
160 | ; Sept 2004, several bug fixs to suit C grid type... |
---|
161 | ; Aug 2005, rewritte almost everything... |
---|
162 | ; |
---|
163 | ; @version $Id$ |
---|
164 | ; |
---|
165 | ;- |
---|
166 | ;------------------------------------------------------------ |
---|
167 | ;------------------------------------------------------------ |
---|
168 | ;------------------------------------------------------------ |
---|
169 | PRO computegrid, startx, starty, stepxin, stepyin, nxin, nyin $ |
---|
170 | , XAXIS = xaxis, YAXIS = yaxis, ZAXIS = zaxis $ |
---|
171 | , MASK = mask, GLAMBOUNDARY = glamboundary $ |
---|
172 | , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $ |
---|
173 | , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $ |
---|
174 | , ZMINMESH = zminmesh, ZMAXMESH = zmaxmesh $ |
---|
175 | , ONEARTH = onearth, PERIODIC = periodic $ |
---|
176 | , PLAIN = plain, SHIFT = shift, STRIDE = stride $ |
---|
177 | , FULLCGRID = fullcgrid, XYINDEX = xyindex $ |
---|
178 | , FBASE2TBASE = fbase2tbase, STRCALLING = strcalling $ |
---|
179 | , _extra = ex |
---|
180 | ;--------------------------------------------------------- |
---|
181 | ; |
---|
182 | compile_opt idl2, strictarrsubs |
---|
183 | ; |
---|
184 | @cm_4mesh |
---|
185 | @cm_4data |
---|
186 | @cm_4cal |
---|
187 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
188 | @updatenew |
---|
189 | @updatekwd |
---|
190 | ENDIF |
---|
191 | ;--------------------------------------------------------- |
---|
192 | ;------------------------------------------------------------ |
---|
193 | time1 = systime(1) ; for key_performance |
---|
194 | ;------------------------------------------------------------ |
---|
195 | ; |
---|
196 | ;==================================================== |
---|
197 | ; Check input parameters |
---|
198 | ;==================================================== |
---|
199 | ; |
---|
200 | ; xaxis related parameters |
---|
201 | ; |
---|
202 | if n_elements(xaxis) NE 0 then BEGIN |
---|
203 | CASE (size(xaxis))[0] OF |
---|
204 | 0:nx = 1L |
---|
205 | 1:nx = (size(xaxis))[1] |
---|
206 | 2:nx = (size(xaxis))[1] |
---|
207 | ENDCASE |
---|
208 | ENDIF ELSE BEGIN |
---|
209 | IF n_elements(startx) EQ 0 THEN BEGIN |
---|
210 | dummy = report('If xaxis is not given, startx must be defined') |
---|
211 | return |
---|
212 | ENDIF |
---|
213 | CASE n_elements(stepxin) OF |
---|
214 | 0:BEGIN |
---|
215 | dummy = report('If xaxis is not given, stepxin must be defined') |
---|
216 | return |
---|
217 | END |
---|
218 | 1:BEGIN |
---|
219 | IF n_elements(nxin) EQ 0 THEN BEGIN |
---|
220 | dummy = report('If xaxis is not given and stepxin has only one element, nx must be defined') |
---|
221 | return |
---|
222 | ENDIF ELSE nx = nxin |
---|
223 | END |
---|
224 | ELSE:nx = n_elements(stepxin) |
---|
225 | ENDCASE |
---|
226 | ENDELSE |
---|
227 | ; |
---|
228 | ; yaxis related parameters |
---|
229 | ; |
---|
230 | if n_elements(yaxis) NE 0 then BEGIN |
---|
231 | CASE (size(yaxis))[0] OF |
---|
232 | 0:ny = 1L |
---|
233 | 1:ny = (size(yaxis))[1] |
---|
234 | 2:ny = (size(yaxis))[2] |
---|
235 | ENDCASE |
---|
236 | ENDIF ELSE BEGIN |
---|
237 | IF n_elements(starty) EQ 0 THEN BEGIN |
---|
238 | dummy = report('If yaxis is not given, starty must be defined') |
---|
239 | return |
---|
240 | ENDIF |
---|
241 | CASE n_elements(stepyin) OF |
---|
242 | 0:BEGIN |
---|
243 | dummy = report('If yaxis is not given, stepyin must be defined') |
---|
244 | return |
---|
245 | END |
---|
246 | 1:BEGIN |
---|
247 | IF n_elements(nyin) EQ 0 THEN BEGIN |
---|
248 | dummy = report('If yaxis is not given and stepyin has only one element, ny must be defined') |
---|
249 | return |
---|
250 | ENDIF ELSE ny = nyin |
---|
251 | END |
---|
252 | ELSE:ny = n_elements(stepyin) |
---|
253 | ENDCASE |
---|
254 | ENDELSE |
---|
255 | ; |
---|
256 | ; zaxis related parameters |
---|
257 | ; |
---|
258 | if n_elements(zaxis) NE 0 then BEGIN |
---|
259 | CASE (size(zaxis))[0] OF |
---|
260 | 0:nz = 1L |
---|
261 | 1:nz = (size(zaxis))[1] |
---|
262 | ELSE:BEGIN |
---|
263 | print, 'not coded' |
---|
264 | stop |
---|
265 | END |
---|
266 | ENDCASE |
---|
267 | ENDIF ELSE nz = 1L |
---|
268 | ; |
---|
269 | ;==================================================== |
---|
270 | ; Others automatic definitions... |
---|
271 | ;==================================================== |
---|
272 | ; |
---|
273 | jpiglo = long(nx) |
---|
274 | jpjglo = long(ny) |
---|
275 | jpkglo = long(nz) |
---|
276 | ; |
---|
277 | ; impact of plain keyword: |
---|
278 | ; |
---|
279 | IF keyword_set(plain) THEN BEGIN |
---|
280 | periodic = 0 |
---|
281 | shift = 0 |
---|
282 | stride = [1, 1, 1] |
---|
283 | ENDIF |
---|
284 | ; |
---|
285 | IF n_elements(xminmesh) NE 0 THEN ixminmesh = long(xminmesh[0]) ELSE ixminmesh = 0l |
---|
286 | IF n_elements(xmaxmesh) NE 0 THEN ixmaxmesh = long(xmaxmesh[0]) ELSE ixmaxmesh = jpiglo-1 |
---|
287 | IF n_elements(yminmesh) NE 0 THEN iyminmesh = long(yminmesh[0]) ELSE iyminmesh = 0l |
---|
288 | IF n_elements(ymaxmesh) NE 0 THEN iymaxmesh = long(ymaxmesh[0]) ELSE iymaxmesh = jpjglo-1 |
---|
289 | IF n_elements(zminmesh) NE 0 THEN izminmesh = long(zminmesh[0]) ELSE izminmesh = 0l |
---|
290 | IF n_elements(zmaxmesh) NE 0 THEN izmaxmesh = long(zmaxmesh[0]) ELSE izmaxmesh = jpkglo-1 |
---|
291 | ; |
---|
292 | iymaxmesh = iymaxmesh-keyword_set(fbase2tbase) |
---|
293 | ; |
---|
294 | IF ixmaxmesh LT 0 THEN ixmaxmesh = jpiglo -1 + ixmaxmesh |
---|
295 | IF iymaxmesh LT 0 THEN iymaxmesh = jpjglo -1 + iymaxmesh |
---|
296 | IF izmaxmesh LT 0 THEN izmaxmesh = jpkglo -1 + izmaxmesh |
---|
297 | ; avoid basics errors... |
---|
298 | ixmaxmesh = 0 > ixmaxmesh < (jpiglo-1) |
---|
299 | ixminmesh = 0 > ixminmesh < ixmaxmesh |
---|
300 | iymaxmesh = 0 > iymaxmesh < (jpjglo-1) |
---|
301 | iyminmesh = 0 > iyminmesh < iymaxmesh |
---|
302 | izmaxmesh = 0 > izmaxmesh < (jpkglo-1) |
---|
303 | izminmesh = 0 > izminmesh < izmaxmesh |
---|
304 | ; |
---|
305 | jpi = ixmaxmesh-ixminmesh+1 |
---|
306 | jpj = iymaxmesh-iyminmesh+1 |
---|
307 | jpk = izmaxmesh-izminmesh+1 |
---|
308 | ; |
---|
309 | jpidta = jpiglo |
---|
310 | jpjdta = jpjglo |
---|
311 | jpkdta = jpkglo |
---|
312 | ixmindta = 0 |
---|
313 | ixmaxdta = jpidta-1 |
---|
314 | iymindta = 0 |
---|
315 | iymaxdta = jpjdta-1 |
---|
316 | izmindta = 0 |
---|
317 | izmaxdta = jpkdta-1 |
---|
318 | ; |
---|
319 | key_partialstep = 0 |
---|
320 | if n_elements(stride) eq 3 then key_stride = stride $ |
---|
321 | ELSE key_stride = [1, 1, 1] |
---|
322 | key_gridtype = 'c' |
---|
323 | ; |
---|
324 | ; check xyindex and its consequences |
---|
325 | ; |
---|
326 | if keyword_set(xyindex) then onearth = 0 |
---|
327 | ; |
---|
328 | ; check onearth and its consequences |
---|
329 | ; |
---|
330 | IF n_elements(onearth) EQ 0 THEN key_onearth = 1b $ |
---|
331 | ELSE key_onearth = keyword_set(onearth) |
---|
332 | IF NOT key_onearth THEN BEGIN |
---|
333 | periodic = 0 |
---|
334 | shift = 0 |
---|
335 | ENDIF |
---|
336 | |
---|
337 | r = 6371000. |
---|
338 | ; |
---|
339 | ;==================================================== |
---|
340 | ; X direction : glamt |
---|
341 | ;==================================================== |
---|
342 | ; |
---|
343 | ; def of glamt |
---|
344 | ; |
---|
345 | if n_elements(xaxis) NE 0 then BEGIN |
---|
346 | if keyword_set(xyindex) THEN glamt = findgen(jpiglo) ELSE glamt = xaxis |
---|
347 | ENDIF ELSE BEGIN |
---|
348 | if keyword_set(xyindex) THEN stepx = 1. ELSE stepx = stepxin |
---|
349 | CASE 1 OF |
---|
350 | n_elements(stepx):glamt = startx + findgen(jpiglo)*stepx |
---|
351 | size(stepx, /n_dimensions):glamt = startx + total(stepx, /cumulative) |
---|
352 | ELSE:BEGIN |
---|
353 | dummy = report('Wrong definition of stepx...') |
---|
354 | return |
---|
355 | END |
---|
356 | ENDCASE |
---|
357 | ENDELSE |
---|
358 | ; |
---|
359 | ; apply glamboundary |
---|
360 | ; |
---|
361 | IF keyword_set(glamboundary) AND key_onearth THEN BEGIN |
---|
362 | IF glamboundary[0] GE glamboundary[1] THEN stop |
---|
363 | IF glamboundary[1]-glamboundary[0] GT 360 THEN stop |
---|
364 | glamt = glamt MOD 360 |
---|
365 | smaller = where(glamt LT glamboundary[0]) |
---|
366 | if smaller[0] NE -1 then glamt[smaller] = glamt[smaller]+360. |
---|
367 | bigger = where(glamt GE glamboundary[1]) |
---|
368 | if bigger[0] NE -1 then glamt[bigger] = glamt[bigger]-360. |
---|
369 | ENDIF |
---|
370 | ; |
---|
371 | ; force glamt to have 2 dimensions |
---|
372 | ; |
---|
373 | CASE size(reform(glamt), /n_dimensions) OF |
---|
374 | 0:glamt = replicate(glamt, jpi, jpj) |
---|
375 | 1:glamt = glamt[ixminmesh:ixmaxmesh]#replicate(1, jpj) |
---|
376 | 2:glamt = glamt[ixminmesh:ixmaxmesh, iyminmesh:iymaxmesh] |
---|
377 | ENDCASE |
---|
378 | ; keep 2d array even with degenerated dimension |
---|
379 | IF jpj EQ 1 THEN glamt = reform(glamt, jpi, jpj, /over) |
---|
380 | ; |
---|
381 | ;==================================================== |
---|
382 | ; Y direction : gphit |
---|
383 | ;==================================================== |
---|
384 | ; |
---|
385 | ; def of gphit |
---|
386 | ; |
---|
387 | if n_elements(yaxis) NE 0 THEN BEGIN |
---|
388 | if keyword_set(xyindex) THEN gphit = findgen(jpjglo) ELSE gphit = yaxis |
---|
389 | ENDIF ELSE BEGIN |
---|
390 | if keyword_set(xyindex) THEN stepy = 1. ELSE stepy = stepyin |
---|
391 | CASE 1 OF |
---|
392 | n_elements(stepy):gphit = starty + findgen(jpjglo)*stepy |
---|
393 | size(stepy, /n_dimensions):gphit = starty + total(stepy, /cumulative) |
---|
394 | ELSE:BEGIN |
---|
395 | dummy = report('Wrong definition of stepy...') |
---|
396 | return |
---|
397 | END |
---|
398 | ENDCASE |
---|
399 | ENDELSE |
---|
400 | ; |
---|
401 | ; force gphit to have 2 dimensions |
---|
402 | ; |
---|
403 | CASE size(reform(gphit), /n_dimensions) OF |
---|
404 | 0:gphit = replicate(gphit, jpi, jpj) |
---|
405 | 1:gphit = replicate(1, jpi)#gphit[iyminmesh:iymaxmesh] |
---|
406 | 2:gphit = gphit[ixminmesh:ixmaxmesh, iyminmesh:iymaxmesh] |
---|
407 | ENDCASE |
---|
408 | ; keep 2d array even with degenerated dimension |
---|
409 | IF jpj EQ 1 THEN gphit = reform(gphit, jpi, jpj, /over) |
---|
410 | ; |
---|
411 | ;==================================================== |
---|
412 | ; check y periodicity... Only according to ORCA grid |
---|
413 | ;==================================================== |
---|
414 | ; check the peridicity if iyminmesh and iymaxmesh have the default definitions... |
---|
415 | IF NOT keyword_set(plain) AND key_onearth EQ 1 AND key_stride[1] EQ 1 $ |
---|
416 | AND iyminmesh EQ 0l AND iymaxmesh eq jpjglo-1 AND jpj GE 3 AND jpi GE 2 THEN BEGIN |
---|
417 | |
---|
418 | CASE 1 OF |
---|
419 | ixminmesh EQ 0l AND ixmaxmesh eq jpiglo-1 $ |
---|
420 | AND array_equal(gphit[1:*, jpj-1], reverse(gphit[1:*, jpj-3])) EQ 1:BEGIN |
---|
421 | ; T pivot |
---|
422 | ymaxmesh = -1 |
---|
423 | recall = 1 |
---|
424 | END |
---|
425 | ixminmesh EQ 1l AND ixmaxmesh eq jpiglo-2 $ |
---|
426 | AND array_equal(gphit[*, jpj-1], reverse(shift(gphit[*, jpj-3], -1))) EQ 1:BEGIN |
---|
427 | ; T pivot |
---|
428 | ymaxmesh = -1 |
---|
429 | recall = 1 |
---|
430 | END |
---|
431 | ixminmesh EQ 0l AND ixmaxmesh eq jpiglo-1 $ |
---|
432 | AND array_equal(gphit[*, jpj-1], reverse(gphit[*, jpj-2])) EQ 1:BEGIN |
---|
433 | ; F pivot |
---|
434 | ymaxmesh = -1 |
---|
435 | recall = 1 |
---|
436 | END |
---|
437 | ixminmesh EQ 1l AND ixmaxmesh eq jpiglo-2 $ |
---|
438 | AND array_equal(gphit[*, jpj-1], reverse(gphit[*, jpj-2])) EQ 1:BEGIN |
---|
439 | ; F pivot |
---|
440 | ymaxmesh = -1 |
---|
441 | recall = 1 |
---|
442 | END |
---|
443 | ELSE: |
---|
444 | ENDCASE |
---|
445 | ENDIF |
---|
446 | ; |
---|
447 | ;==================================================== |
---|
448 | ; check x periodicity... |
---|
449 | ;==================================================== |
---|
450 | IF n_elements(periodic) NE 0 THEN forcenoperio = 1 - keyword_set(periodic) |
---|
451 | ; check the peridicity if ixminmesh and ixmaxmesh have the default definitions... |
---|
452 | IF NOT keyword_set(plain) AND NOT keyword_set(forcenoperio) AND key_onearth EQ 1 $ |
---|
453 | AND key_stride[0] EQ 1 AND ixminmesh EQ 0l AND ixmaxmesh eq jpiglo-1 AND jpi GE 3 THEN BEGIN |
---|
454 | CASE 0 OF |
---|
455 | total((glamt[0, *] - glamt[jpi-2, *]) MOD 360) $ |
---|
456 | + total((glamt[1, *] - glamt[jpi-1, *]) MOD 360):BEGIN |
---|
457 | xminmesh = 1 |
---|
458 | xmaxmesh = -1 |
---|
459 | recall = 1 |
---|
460 | END |
---|
461 | total((glamt[0, *] - glamt[jpi-2, *]) MOD 360):BEGIN |
---|
462 | xminmesh = 1 |
---|
463 | recall = 1 |
---|
464 | END |
---|
465 | total((glamt[1, *] - glamt[jpi-1, *]) MOD 360):BEGIN |
---|
466 | xmaxmesh = -1 |
---|
467 | recall = 1 |
---|
468 | END |
---|
469 | ELSE: |
---|
470 | ENDCASE |
---|
471 | ENDIF |
---|
472 | ;==================================================== |
---|
473 | ; recall computegrid if needed... |
---|
474 | ;==================================================== |
---|
475 | IF keyword_set(recall) THEN BEGIN |
---|
476 | computegrid, XAXIS = glamt, YAXIS = gphit, ZAXIS = zaxis $ |
---|
477 | , MASK = mask, GLAMBOUNDARY = glamboundary $ |
---|
478 | , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $ |
---|
479 | , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $ |
---|
480 | , ZMINMESH = zminmesh, ZMAXMESH = zmaxmesh $ |
---|
481 | , PERIODIC = periodic, SHIFT = shift, STRIDE = stride $ |
---|
482 | , FULLCGRID = fullcgrid, XYINDEX = xyindex $ |
---|
483 | , FBASE2TBASE = fbase2tbase, STRCALLING = strcalling $ |
---|
484 | , _extra = ex |
---|
485 | return |
---|
486 | ENDIF |
---|
487 | ;==================================================== |
---|
488 | ; def of key_shift |
---|
489 | ;==================================================== |
---|
490 | ; |
---|
491 | ; definition of key_shift by shifting the array to have the min |
---|
492 | ; values of glamt[*, 0] in glamt[0, 0] |
---|
493 | ; |
---|
494 | IF n_elements(shift) EQ 0 THEN BEGIN |
---|
495 | IF jpi GT 1 then BEGIN |
---|
496 | xtest = glamt[*, 0] |
---|
497 | key_shift = (where(xtest EQ min(xtest)))[0] |
---|
498 | IF key_shift NE 0 THEN key_shift = jpi - key_shift |
---|
499 | ENDIF ELSE key_shift = 0 |
---|
500 | ENDIF ELSE key_shift = shift |
---|
501 | ; |
---|
502 | ;==================================================== |
---|
503 | ; def of key_periodic |
---|
504 | ;==================================================== |
---|
505 | ; |
---|
506 | IF n_elements(periodic) EQ 0 THEN BEGIN |
---|
507 | IF jpi GT 1 THEN BEGIN |
---|
508 | xtest = shift(glamt[*, 0], key_shift) |
---|
509 | ; check that xtest is now sorted in the increasing order |
---|
510 | IF array_equal(sort(xtest), lindgen(jpi)) EQ 0 THEN BEGIN |
---|
511 | print, 'WARNING: we cannot sort the xaxis with a simple shift...' |
---|
512 | print, 'we force key_periodic = 0 and key_shift = 0' |
---|
513 | print, 'only horizontal plot may be ok...' |
---|
514 | key_periodic = 0 |
---|
515 | xnotsorted = 1 |
---|
516 | ENDIF ELSE BEGIN |
---|
517 | key_periodic = (xtest[jpi-1]+2*(xtest[jpi-1]-xtest[jpi-2])) $ |
---|
518 | GE (xtest[0]+360) |
---|
519 | ENDELSE |
---|
520 | ENDIF ELSE key_periodic = 0 |
---|
521 | ENDIF ELSE key_periodic = keyword_set(periodic) |
---|
522 | ; |
---|
523 | ; update key_shift |
---|
524 | ; |
---|
525 | key_shift = key_shift * (key_periodic EQ 1) |
---|
526 | ; |
---|
527 | IF NOT keyword_set(key_periodic) AND keyword_set(fbase2tbase) THEN BEGIN |
---|
528 | ixmaxmesh = ixmaxmesh-1 |
---|
529 | jpi = jpi-1 |
---|
530 | ENDIF |
---|
531 | ; |
---|
532 | ;==================================================== |
---|
533 | ; apply key_shift |
---|
534 | ;==================================================== |
---|
535 | ; |
---|
536 | if keyword_set(key_shift) then BEGIN |
---|
537 | glamt = shift(glamt, key_shift, 0) |
---|
538 | gphit = shift(gphit, key_shift, 0) |
---|
539 | IF jpj EQ 1 THEN BEGIN |
---|
540 | glamt = reform(glamt, jpi, jpj, /over) |
---|
541 | gphit = reform(gphit, jpi, jpj, /over) |
---|
542 | ENDIF |
---|
543 | ENDIF |
---|
544 | ; |
---|
545 | ;==================================================== |
---|
546 | ; def key_yreverse |
---|
547 | ;==================================================== |
---|
548 | ; |
---|
549 | IF jpj GT 1 THEN BEGIN |
---|
550 | if gphit[0, 1] LT gphit[0, 0] then begin |
---|
551 | key_yreverse = 1 |
---|
552 | gphit = reverse(gphit, 2) |
---|
553 | glamt = reverse(glamt, 2) |
---|
554 | ENDIF ELSE key_yreverse = 0 |
---|
555 | ENDIF ELSE key_yreverse = 0 |
---|
556 | ; |
---|
557 | ;==================================================== |
---|
558 | ; Are we using a "regular" grid (that can be described |
---|
559 | ; with x vector and y vector)? |
---|
560 | ;==================================================== |
---|
561 | ; |
---|
562 | ; to get faster, we first test the most basic cases before |
---|
563 | ; testing the full array. |
---|
564 | ; |
---|
565 | CASE 1 OF |
---|
566 | keyword_set(xyindex):key_irregular = 0b |
---|
567 | jpi EQ 1 OR jpj EQ 1:key_irregular = 0b |
---|
568 | n_elements(xaxis) EQ 0 AND n_elements(yaxis) EQ 0:key_irregular = 0b |
---|
569 | size(reform(xaxis), /n_dimensions) EQ 1 AND size(reform(xaxis), /n_dimensions) EQ 1:key_irregular = 0b |
---|
570 | n_elements(xaxis) EQ 0 AND size(reform(yaxis), /n_dimensions) EQ 1:key_irregular = 0b |
---|
571 | n_elements(yaxis) EQ 0 AND size(reform(xaxis), /n_dimensions) EQ 1:key_irregular = 0b |
---|
572 | array_equal(glamt[*, 0], glamt[*, jpj-1]) EQ 0:key_irregular = 1b |
---|
573 | array_equal(gphit[0, *], gphit[jpi-1, *]) EQ 0:key_irregular = 1b |
---|
574 | array_equal(glamt, glamt[*, 0]#replicate(1, jpj)) EQ 0:key_irregular = 1b |
---|
575 | array_equal(gphit, replicate(1, jpi)#(gphit[0, *])[*]) EQ 0:key_irregular = 1b |
---|
576 | ELSE:key_irregular = 0b |
---|
577 | ENDCASE |
---|
578 | ; |
---|
579 | ;==================================================== |
---|
580 | ; def of glamf: defined as the middle of T(i,j) T(i+1,j+1) |
---|
581 | ;==================================================== |
---|
582 | ; |
---|
583 | IF jpi GT 1 THEN BEGIN |
---|
584 | ; we must compute stepxf: x distance between T(i,j) T(i+1,j+1) |
---|
585 | CASE 1 OF |
---|
586 | n_elements(stepx):stepxf = stepx |
---|
587 | size(stepx, /n_dimensions):stepxf = stepx#replicate(1, jpj) |
---|
588 | ELSE:BEGIN |
---|
589 | if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $ |
---|
590 | OR (keyword_set(key_periodic) AND key_irregular) then BEGIN |
---|
591 | stepxf = (glamt + 720) MOD 360 |
---|
592 | IF jpj EQ 1 THEN stepxf = reform(stepxf, jpi, jpj, /over) |
---|
593 | stepxf = shift(stepxf, -1, -1) - stepxf |
---|
594 | stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ] |
---|
595 | stepxf = min(abs(stepxf), dimension = 3) |
---|
596 | IF NOT keyword_set(key_periodic) THEN $ |
---|
597 | stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
598 | ENDIF ELSE BEGIN |
---|
599 | stepxf = shift(glamt, -1, -1) - glamt |
---|
600 | IF keyword_set(key_periodic) THEN $ |
---|
601 | stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $ |
---|
602 | ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
603 | ENDELSE |
---|
604 | IF jpj GT 1 THEN BEGIN |
---|
605 | stepxf[*, jpj-1] = stepxf[*, jpj-2] |
---|
606 | stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2] |
---|
607 | ENDIF |
---|
608 | END |
---|
609 | ENDCASE |
---|
610 | glamf = glamt + 0.5 * stepxf |
---|
611 | ENDIF ELSE glamf = glamt + 0.5 |
---|
612 | ; |
---|
613 | IF keyword_set(key_periodic) AND (max(glamf)-min(glamt)) GE 360 THEN BEGIN |
---|
614 | IF NOT keyword_set(glamboundary) THEN BEGIN |
---|
615 | bigger = where(glamf GE min(glamt)+360) |
---|
616 | glamf[bigger] = glamf[bigger]-360. |
---|
617 | ENDIF ELSE glamf = glamboundary[0] > temporary(glamf) < glamboundary[1] |
---|
618 | ENDIF |
---|
619 | ; |
---|
620 | IF jpj EQ 1 THEN glamf = reform(glamf, jpi, jpj, /over) |
---|
621 | ; |
---|
622 | ;==================================================== |
---|
623 | ; def of gphif: defined as the middle of T(i,j) T(i+1,j+1) |
---|
624 | ;==================================================== |
---|
625 | ; |
---|
626 | IF jpj GT 1 THEN BEGIN |
---|
627 | ; we must compute stepyf: y distance between T(i,j) T(i+1,j+1) |
---|
628 | CASE 1 OF |
---|
629 | n_elements(stepy):stepyf = stepy |
---|
630 | size(stepy, /n_dimensions):stepyf = replicate(1, jpi)#stepy |
---|
631 | ELSE:BEGIN |
---|
632 | stepyf = shift(gphit, -1, -1) - gphit |
---|
633 | stepyf[*, jpj-1] = stepyf[*, jpj-2] |
---|
634 | IF jpi GT 1 THEN BEGIN |
---|
635 | if NOT keyword_set(key_periodic) THEN $ |
---|
636 | stepyf[jpi-1, *] = stepyf[jpi-2, *] |
---|
637 | stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2] |
---|
638 | ENDIF |
---|
639 | END |
---|
640 | ENDCASE |
---|
641 | gphif = gphit + 0.5 * stepyf |
---|
642 | ENDIF ELSE gphif = gphit + 0.5 |
---|
643 | IF key_onearth THEN gphif = -90. > gphif < 90. |
---|
644 | ; |
---|
645 | IF jpj EQ 1 THEN gphif = reform(gphif, jpi, jpj, /over) |
---|
646 | ; |
---|
647 | ;==================================================== |
---|
648 | ; e1t: x distance between U(i-1,j) and U(i,j) |
---|
649 | ;==================================================== |
---|
650 | ; |
---|
651 | ; *-|-*---|---*---| |
---|
652 | ; |
---|
653 | IF jpi GT 1 THEN BEGIN |
---|
654 | IF n_elements(stepx) NE 1 THEN BEGIN |
---|
655 | IF keyword_set(irregular) THEN BEGIN |
---|
656 | ; we must compute stepxu: x distance between T(i,j) T(i+1,j) |
---|
657 | IF keyword_set(key_periodic) THEN BEGIN |
---|
658 | stepxu = (glamt + 720) MOD 360 |
---|
659 | stepxu = shift(stepxu, -1, 0) - stepxu |
---|
660 | stepxu = [ [[stepxu]], [[stepxu + 360]], [[stepxu - 360]] ] |
---|
661 | stepxu = min(abs(stepxu), dimension = 3) |
---|
662 | ENDIF ELSE BEGIN |
---|
663 | stepxu = shift(glamt, -1, 0) - glamt |
---|
664 | stepxu[jpi-1, *] = stepxf[jpi-2, *] |
---|
665 | ENDELSE |
---|
666 | ENDIF ELSE stepxu = stepxf |
---|
667 | IF jpj EQ 1 THEN stepxu = reform(stepxu, jpi, jpj, /over) |
---|
668 | e1t = 0.5*(stepxu+shift(stepxu, 1, 0)) |
---|
669 | IF NOT keyword_set(key_periodic) THEN $ |
---|
670 | e1t[0, *] = e1t[1, *] |
---|
671 | ENDIF ELSE e1t = replicate(stepx, jpi, jpj) |
---|
672 | ENDIF ELSE e1t = replicate(1b, jpi, jpj) |
---|
673 | ; |
---|
674 | IF jpj EQ 1 THEN e1t = reform(e1t, jpi, jpj, /over) |
---|
675 | ; |
---|
676 | ;==================================================== |
---|
677 | ; e2t: y distance between V(i,j-1) and V(i,j) |
---|
678 | ;==================================================== |
---|
679 | ; |
---|
680 | IF jpj GT 1 THEN BEGIN |
---|
681 | ; we must compute stepyv: y distance between T(i,j) T(i,j+1) |
---|
682 | IF n_elements(stepy) NE 1 THEN BEGIN |
---|
683 | IF keyword_set(key_irregular) THEN BEGIN |
---|
684 | stepyv = shift(gphit, 0, -1) - gphit |
---|
685 | stepyv[*, jpj-1] = stepyv[*, jpj-2] |
---|
686 | ENDIF ELSE stepyv = stepyf |
---|
687 | e2t = 0.5*(stepyv+shift(stepyv, 0, 1)) |
---|
688 | e2t[*, 0] = e2t[*, 1] |
---|
689 | ENDIF ELSE e2t = replicate(stepy, jpi, jpj) |
---|
690 | ENDIF ELSE e2t = replicate(1b, jpi, jpj) |
---|
691 | ; |
---|
692 | IF key_onearth THEN e2t = r * !pi/180. * temporary(e2t) |
---|
693 | ; |
---|
694 | IF jpj EQ 1 THEN e2t = reform(e2t, jpi, jpj, /over) |
---|
695 | ; |
---|
696 | ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
697 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
698 | ; |
---|
699 | ;==================================================== |
---|
700 | ; def of glamu: defined as the middle of T(i,j) T(i+1,j) |
---|
701 | ;==================================================== |
---|
702 | ; |
---|
703 | IF keyword_set(irregular) THEN BEGIN |
---|
704 | glamu = glamt + 0.5 * stepxu |
---|
705 | IF keyword_set(glamboundary) AND key_onearth THEN $ |
---|
706 | glamu = glamboundary[0] > temporary(glamu) < glamboundary[1] |
---|
707 | ENDIF ELSE glamu = glamf |
---|
708 | ; |
---|
709 | IF jpj EQ 1 THEN glamu = reform(glamu, jpi, jpj, /over) |
---|
710 | ; |
---|
711 | ;==================================================== |
---|
712 | ; def of gphiu: defined as the middle of T(i,j) T(i+1,j) |
---|
713 | ;==================================================== |
---|
714 | ; |
---|
715 | IF jpi GT 1 THEN BEGIN |
---|
716 | ; we must compute stepyu: y distance between T(i+1,j) T(i,j) |
---|
717 | IF keyword_set(key_irregular) THEN BEGIN |
---|
718 | stepyu = shift(gphit, -1, 0) - gphit |
---|
719 | IF NOT keyword_set(key_periodic) THEN $ |
---|
720 | stepyu[jpi-1, *] = stepyu[jpi-2, *] |
---|
721 | gphiu = gphit + 0.5 * stepyu |
---|
722 | ENDIF ELSE gphiu = gphit |
---|
723 | ENDIF ELSE gphiu = gphit |
---|
724 | IF key_onearth THEN gphiu = -90. > gphiu < 90. |
---|
725 | ; |
---|
726 | IF jpj EQ 1 THEN gphiu = reform(gphiu, jpi, jpj, /over) |
---|
727 | ; |
---|
728 | ;==================================================== |
---|
729 | ; def of glamv: defined as the middle of T(i,j) T(i,j+1) |
---|
730 | ;==================================================== |
---|
731 | ; |
---|
732 | IF jpj GT 1 THEN BEGIN |
---|
733 | ; we must compute stepxv: x distance between T(i,j) T(i,j+1) |
---|
734 | IF keyword_set(irregular) THEN BEGIN |
---|
735 | IF keyword_set(key_periodic) THEN BEGIN |
---|
736 | stepxv = (glamt + 720) MOD 360 |
---|
737 | stepxv = shift(stepxv, 0, -1) - stepxv |
---|
738 | stepxv = [ [[stepxv]], [[stepxv + 360]], [[stepxv - 360]] ] |
---|
739 | stepxv = min(abs(stepxv), dimension = 3) |
---|
740 | ENDIF ELSE stepxv = shift(glamt, 0, -1) - glamt |
---|
741 | stepxv[*, jpj-1] = stepxv[*, jpj-2] |
---|
742 | glamv = glamt + 0.5 * stepxv |
---|
743 | IF keyword_set(glamboundary) AND key_onearth THEN $ |
---|
744 | glamv = glamboundary[0] > temporary(glamv) < glamboundary[1] |
---|
745 | ENDIF ELSE glamv = glamt |
---|
746 | ENDIF ELSE glamv = glamt |
---|
747 | ; |
---|
748 | ;==================================================== |
---|
749 | ; def of gphiv: defined as the middle of T(i,j) T(i,j+1) |
---|
750 | ;==================================================== |
---|
751 | ; |
---|
752 | IF keyword_set(key_irregular) THEN $ |
---|
753 | gphiv = gphit + 0.5 * stepyv $ |
---|
754 | ELSE gphiv = gphif |
---|
755 | IF key_onearth THEN gphiv = -90. > gphiv < 90. |
---|
756 | ; |
---|
757 | IF jpj EQ 1 THEN gphiv = reform(gphiv, jpi, jpj, /over) |
---|
758 | ; |
---|
759 | ;==================================================== |
---|
760 | ; e1u: x distance between T(i,j) and T(i+1,j) |
---|
761 | ;==================================================== |
---|
762 | ; |
---|
763 | IF jpi GT 1 AND n_elements(stepx) NE 1 THEN $ |
---|
764 | e1u = stepxu ELSE e1u = e1t |
---|
765 | ; |
---|
766 | ;==================================================== |
---|
767 | ; e2u: y distance between F(i,j-1) and F(i,j) |
---|
768 | ;==================================================== |
---|
769 | ; |
---|
770 | IF keyword_set(key_irregular) THEN BEGIN |
---|
771 | e2u = gphif - shift(gphif, 0, 1) |
---|
772 | e2u[*, 0] = e2u[*, 1] |
---|
773 | IF key_onearth THEN e2u = r * !pi/180. * temporary(e2u) |
---|
774 | ENDIF ELSE e2u = e2t |
---|
775 | ; |
---|
776 | IF jpj EQ 1 THEN e2u = reform(e2u, jpi, jpj, /over) |
---|
777 | ; |
---|
778 | ;==================================================== |
---|
779 | ; e1v: x distance between F(i-1,j) and F(i,j) |
---|
780 | ;==================================================== |
---|
781 | ; |
---|
782 | IF keyword_set(irregular) THEN BEGIN |
---|
783 | IF keyword_set(key_periodic) THEN BEGIN |
---|
784 | e1v = (glamf + 720) MOD 360 |
---|
785 | e1v = e1v - shift(e1v, 1, 0) |
---|
786 | e1v = [ [[e1v]], [[e1v + 360]], [[e1v - 360]] ] |
---|
787 | e1v = min(abs(e1v), dimension = 3) |
---|
788 | ENDIF ELSE BEGIN |
---|
789 | e1v = glamf - shift(glamf, 1, 0) |
---|
790 | e1v[0, *] = stepxf[1, *] |
---|
791 | ENDELSE |
---|
792 | ENDIF ELSE e1v = e1t |
---|
793 | ; |
---|
794 | IF jpj EQ 1 THEN e1v = reform(e1v, jpi, jpj, /over) |
---|
795 | ; |
---|
796 | ;==================================================== |
---|
797 | ; e2v: y distance between T(i,j) and T(i+1,j) |
---|
798 | ;==================================================== |
---|
799 | ; |
---|
800 | IF jpj GT 1 and n_elements(stepy) NE 1 THEN BEGIN |
---|
801 | e2v = stepyv |
---|
802 | IF key_onearth THEN e2v = r * !pi/180. * temporary(e2v) |
---|
803 | ENDIF ELSE e2v = e2t |
---|
804 | ; |
---|
805 | ;==================================================== |
---|
806 | ; e1f: x distance between V(i,j) and V(i+1,j) |
---|
807 | ;==================================================== |
---|
808 | ; |
---|
809 | IF keyword_set(irregular) THEN BEGIN |
---|
810 | IF keyword_set(key_periodic) THEN BEGIN |
---|
811 | e1f = (glamv + 720) MOD 360 |
---|
812 | e1f = shift(e1f, -1, 0) - e1f |
---|
813 | e1f = [ [[e1f]], [[e1f + 360]], [[e1f - 360]] ] |
---|
814 | e1f = min(abs(e1f), dimension = 3) |
---|
815 | ENDIF ELSE BEGIN |
---|
816 | e1f = shift(glamv, -1, 0) - glamt |
---|
817 | e1f[jpi-1, *] = stepxf[jpi-2, *] |
---|
818 | ENDELSE |
---|
819 | ENDIF ELSE e1f = e1u |
---|
820 | ; |
---|
821 | IF jpj EQ 1 THEN e1f = reform(e1f, jpi, jpj, /over) |
---|
822 | ; |
---|
823 | ;==================================================== |
---|
824 | ; e2f: y distance between U(i,j) and U(i,j+1) |
---|
825 | ;==================================================== |
---|
826 | ; |
---|
827 | IF keyword_set(key_irregular) THEN BEGIN |
---|
828 | e2f = shift(gphiu, 0, -1) - gphiu |
---|
829 | e2f[*, jpj-1] = e2f[*, jpj-2] |
---|
830 | IF key_onearth THEN e2f = r * !pi/180. * temporary(e2f) |
---|
831 | ENDIF ELSE e2f = e2v |
---|
832 | ; |
---|
833 | IF jpj EQ 1 THEN e2f = reform(e2f, jpi, jpj, /over) |
---|
834 | ; |
---|
835 | ENDIF |
---|
836 | ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
837 | ; |
---|
838 | ; |
---|
839 | ;==================================================== |
---|
840 | ; e1[tuvf] from degree to meters |
---|
841 | ;==================================================== |
---|
842 | ; |
---|
843 | IF keyword_set(key_onearth) THEN BEGIN |
---|
844 | e1t = r * !pi/180. * temporary(e1t) * cos(!pi/180.*gphit) |
---|
845 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
846 | e1u = r * !pi/180. * temporary(e1u) * cos(!pi/180.*gphiu) |
---|
847 | e1v = r * !pi/180. * temporary(e1v) * cos(!pi/180.*gphiv) |
---|
848 | e1f = r * !pi/180. * temporary(e1f) * cos(!pi/180.*gphif) |
---|
849 | ENDIF |
---|
850 | ENDIF |
---|
851 | ; |
---|
852 | IF jpj EQ 1 THEN BEGIN |
---|
853 | e1t = reform(e1t, jpi, jpj, /over) |
---|
854 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
855 | e1u = reform(e1u, jpi, jpj, /over) |
---|
856 | e1v = reform(e1v, jpi, jpj, /over) |
---|
857 | e1f = reform(e1f, jpi, jpj, /over) |
---|
858 | ENDIF |
---|
859 | ENDIF |
---|
860 | ; |
---|
861 | ;==================================================== |
---|
862 | ; if not fullcgrid: make sure we don't use glam[uv], gphi[uv], e[12][uvf] |
---|
863 | ;==================================================== |
---|
864 | ; |
---|
865 | IF NOT keyword_set(fullcgrid) THEN BEGIN |
---|
866 | glamu = !values.f_nan & glamv = !values.f_nan |
---|
867 | gphiu = !values.f_nan & gphiv = !values.f_nan |
---|
868 | e1u = !values.f_nan & e1v = !values.f_nan & e1f = !values.f_nan |
---|
869 | e2u = !values.f_nan & e2v = !values.f_nan & e2f = !values.f_nan |
---|
870 | firstxu = !values.f_nan & lastxu = !values.f_nan & nxu = !values.f_nan |
---|
871 | firstyu = !values.f_nan & lastyu = !values.f_nan & nyu = !values.f_nan |
---|
872 | firstxv = !values.f_nan & lastxv = !values.f_nan & nxv = !values.f_nan |
---|
873 | firstyv = !values.f_nan & lastyv = !values.f_nan & nyv = !values.f_nan |
---|
874 | ENDIF |
---|
875 | ; |
---|
876 | ;==================================================== |
---|
877 | ; Z direction |
---|
878 | ;==================================================== |
---|
879 | ; |
---|
880 | ; z axis |
---|
881 | ; |
---|
882 | CASE n_elements(zaxis) OF |
---|
883 | 0:BEGIN |
---|
884 | gdept = 0. |
---|
885 | key_zreverse = 0 |
---|
886 | END |
---|
887 | 1:BEGIN |
---|
888 | gdept = zaxis |
---|
889 | key_zreverse = 0 |
---|
890 | END |
---|
891 | ELSE:BEGIN |
---|
892 | gdept = zaxis[izminmesh:izmaxmesh] |
---|
893 | IF jpk GT 1 THEN BEGIN |
---|
894 | if gdept[0] GT gdept[1] then begin |
---|
895 | gdept = reverse(gdept) |
---|
896 | key_zreverse = 1 |
---|
897 | ENDIF ELSE key_zreverse = 0 |
---|
898 | ENDIF ELSE key_zreverse = 0 |
---|
899 | END |
---|
900 | ENDCASE |
---|
901 | ; |
---|
902 | if n_elements(gdept) GT 1 then BEGIN |
---|
903 | stepz = shift(gdept, -1)-gdept |
---|
904 | stepz[jpk-1] = stepz[jpk-2] |
---|
905 | gdepw = 0. > (gdept-stepz/2.) |
---|
906 | ENDIF ELSE BEGIN |
---|
907 | stepz = 1. |
---|
908 | gdepw = gdept |
---|
909 | ENDELSE |
---|
910 | ; |
---|
911 | ;==================================================== |
---|
912 | ; e3[tw]: |
---|
913 | ;==================================================== |
---|
914 | ; |
---|
915 | e3t = stepz |
---|
916 | IF n_elements(stepz) GT 1 THEN BEGIN |
---|
917 | e3w = 0.5*(stepz+shift(stepz, 1)) |
---|
918 | e3w[0] = 0.5*e3t[0] |
---|
919 | ENDIF ELSE e3w = e3t |
---|
920 | ; |
---|
921 | ;==================================================== |
---|
922 | ; Mask |
---|
923 | ;==================================================== |
---|
924 | ; |
---|
925 | ; default mask eq 1 |
---|
926 | if NOT keyword_set(mask) then mask = -1 |
---|
927 | ; |
---|
928 | if mask[0] NE -1 then BEGIN |
---|
929 | tmask = byte(mask[ixminmesh:ixmaxmesh, iyminmesh:iymaxmesh, izminmesh:izmaxmesh]) |
---|
930 | tmask = reform(tmask, jpi, jpj, jpk, /over) |
---|
931 | if key_shift NE 0 then tmask = shift(tmask, key_shift, 0, 0) |
---|
932 | ; because tmask = reverse(tmask, 2) is not working if the 3rd |
---|
933 | ; dimension of tmask = 1, we call reform. |
---|
934 | IF jpk EQ 1 THEN tmask = reform(tmask, /over) |
---|
935 | IF key_yreverse EQ 1 THEN tmask = reverse(tmask, 2) |
---|
936 | IF jpk EQ 1 THEN tmask = reform(tmask, jpi, jpj, jpk, /over) |
---|
937 | IF key_zreverse EQ 1 THEN tmask = reverse(tmask, 3) |
---|
938 | IF jpk EQ 1 THEN tmask = reform(tmask, jpi, jpj, jpk, /over) |
---|
939 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
940 | IF keyword_set(key_periodic) THEN BEGIN |
---|
941 | msk = tmask*shift(tmask, -1, 0, 0) |
---|
942 | umaskred = msk[jpi-1, *, *] |
---|
943 | ENDIF ELSE umaskred = tmask[jpi-1, *, *] |
---|
944 | vmaskred = tmask[*, jpj-1, *] |
---|
945 | fmaskredy = tmask[jpi-1, *, *] |
---|
946 | fmaskredx = tmask[*, jpj-1, *] |
---|
947 | ENDIF |
---|
948 | ENDIF ELSE BEGIN |
---|
949 | tmask = replicate(1b, jpi, jpj, jpk) |
---|
950 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
951 | umaskred = replicate(1b, jpj, jpk) |
---|
952 | vmaskred = replicate(1b, jpi, jpk) |
---|
953 | fmaskredy = replicate(1b, jpj, jpk) |
---|
954 | fmaskredx = replicate(1b, jpi, jpk) |
---|
955 | ENDIF |
---|
956 | ENDELSE |
---|
957 | ; |
---|
958 | IF jpi GT 2 AND jpj GT 2 AND NOT keyword_set(plain) $ |
---|
959 | AND ixminmesh EQ 0l AND ixmaxmesh eq jpiglo-1 $ |
---|
960 | AND iyminmesh EQ 0l AND iymaxmesh eq jpjglo-1 $ |
---|
961 | AND total(tmask[*, 0, *]) EQ 0 AND total(tmask[*, jpj-1, *]) EQ 0 $ |
---|
962 | AND total(tmask[0, *, *]) EQ 0 AND total(tmask[jpi-1, *, *]) EQ 0 THEN BEGIN |
---|
963 | xminmesh = 1 |
---|
964 | xmaxmesh = -1 |
---|
965 | yminmesh = 1 |
---|
966 | ymaxmesh = -1 |
---|
967 | computegrid, XAXIS = glamt, YAXIS = gphit, ZAXIS = zaxis $ |
---|
968 | , MASK = mask, GLAMBOUNDARY = glamboundary $ |
---|
969 | , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $ |
---|
970 | , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $ |
---|
971 | , ZMINMESH = zminmesh, ZMAXMESH = zmaxmesh $ |
---|
972 | , ONEARTH = onearth, PERIODIC = periodic $ |
---|
973 | , PLAIN = plain, SHIFT = shift, STRIDE = stride $ |
---|
974 | , FULLCGRID = fullcgrid, XYINDEX = xyindex $ |
---|
975 | , FBASE2TBASE = fbase2tbase, STRCALLING = strcalling $ |
---|
976 | , _extra = ex |
---|
977 | return |
---|
978 | ENDIF |
---|
979 | ; |
---|
980 | IF NOT keyword_set(fullcgrid) THEN BEGIN |
---|
981 | umaskred = !values.f_nan |
---|
982 | vmaskred = !values.f_nan |
---|
983 | fmaskredy = !values.f_nan |
---|
984 | fmaskredx = !values.f_nan |
---|
985 | ENDIF |
---|
986 | ; |
---|
987 | ;==================================================== |
---|
988 | ; stride... |
---|
989 | ;==================================================== |
---|
990 | ; |
---|
991 | IF total(key_stride) GT 3 THEN BEGIN |
---|
992 | IF key_shift NE 0 THEN BEGIN |
---|
993 | ; for explanation, see header of read_ncdf_varget.pro |
---|
994 | jpiright = key_shift |
---|
995 | jpileft = jpi - key_shift - ( (key_stride[0]-1)-((key_shift-1) MOD key_stride[0]) ) |
---|
996 | jpi = ((jpiright-1)/key_stride[0]+1) + ((jpileft-1)/key_stride[0]+1) |
---|
997 | ENDIF ELSE jpi = (jpi-1)/key_stride[0]+1 |
---|
998 | jpj = (jpj-1)/key_stride[1]+1 |
---|
999 | jpk = (jpk-1)/key_stride[2]+1 |
---|
1000 | ; |
---|
1001 | glamt = (temporary(glamt))[0:*:stride[0], 0:*:stride[1]] |
---|
1002 | gphit = (temporary(gphit))[0:*:stride[0], 0:*:stride[1]] |
---|
1003 | e1t = (temporary(e1t))[0:*:stride[0], 0:*:stride[1]] |
---|
1004 | e2t = (temporary(e2t))[0:*:stride[0], 0:*:stride[1]] |
---|
1005 | tmask = (temporary(tmask))[0:*:stride[0], 0:*:stride[1], 0:*:stride[2]] |
---|
1006 | gdept = gdept[0:*:stride[2]] |
---|
1007 | gdepw = gdepw[0:*:stride[2]] |
---|
1008 | e3t = e3t[0:*:stride[2]] |
---|
1009 | e3w = e3w[0:*:stride[2]] |
---|
1010 | ; we must recompute glamf and gphif... |
---|
1011 | IF jpi GT 1 THEN BEGIN |
---|
1012 | if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $ |
---|
1013 | OR (keyword_set(key_periodic) AND key_irregular) then BEGIN |
---|
1014 | stepxf = (glamt + 720) MOD 360 |
---|
1015 | stepxf = shift(stepxf, -1, -1) - stepxf |
---|
1016 | stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ] |
---|
1017 | stepxf = min(abs(stepxf), dimension = 3) |
---|
1018 | IF NOT keyword_set(key_periodic) THEN $ |
---|
1019 | stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
1020 | ENDIF ELSE BEGIN |
---|
1021 | stepxf = shift(glamt, -1, -1) - glamt |
---|
1022 | IF keyword_set(key_periodic) THEN $ |
---|
1023 | stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $ |
---|
1024 | ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
1025 | ENDELSE |
---|
1026 | IF jpj GT 1 THEN BEGIN |
---|
1027 | stepxf[*, jpj-1] = stepxf[*, jpj-2] |
---|
1028 | stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2] |
---|
1029 | ENDIF |
---|
1030 | glamf = glamt + 0.5 * stepxf |
---|
1031 | ENDIF ELSE glamf = glamt + 0.5 |
---|
1032 | IF jpj GT 1 THEN BEGIN |
---|
1033 | ; we must compute stepyf: y distance between T(i,j) T(i+1,j+1) |
---|
1034 | stepyf = shift(gphit, -1, -1) - gphit |
---|
1035 | stepyf[*, jpj-1] = stepyf[*, jpj-2] |
---|
1036 | IF jpi GT 1 THEN BEGIN |
---|
1037 | if NOT keyword_set(key_periodic) THEN $ |
---|
1038 | stepyf[jpi-1, *] = stepyf[jpi-2, *] |
---|
1039 | stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2] |
---|
1040 | ENDIF |
---|
1041 | gphif = gphit + 0.5 * stepyf |
---|
1042 | ENDIF ELSE gphif = gphit + 0.5 |
---|
1043 | ; |
---|
1044 | IF jpj EQ 1 THEN BEGIN |
---|
1045 | glamt = reform(glamt, jpi, jpj, /over) |
---|
1046 | gphit = reform(gphit, jpi, jpj, /over) |
---|
1047 | glamf = reform(glamf, jpi, jpj, /over) |
---|
1048 | gphif = reform(gphif, jpi, jpj, /over) |
---|
1049 | e1t = reform(e1t, jpi, jpj, /over) |
---|
1050 | e2t = reform(e2t, jpi, jpj, /over) |
---|
1051 | ENDIF |
---|
1052 | ; |
---|
1053 | IF keyword_set(fullcgrid) THEN BEGIN |
---|
1054 | glamu = (temporary(glamu))[0:*:stride[0], 0:*:stride[1]] |
---|
1055 | gphiu = (temporary(gphiu))[0:*:stride[0], 0:*:stride[1]] |
---|
1056 | e1u = (temporary(e1u))[0:*:stride[0], 0:*:stride[1]] |
---|
1057 | e2u = (temporary(e2u))[0:*:stride[0], 0:*:stride[1]] |
---|
1058 | glamv = (temporary(glamv))[0:*:stride[0], 0:*:stride[1]] |
---|
1059 | gphiv = (temporary(gphiv))[0:*:stride[0], 0:*:stride[1]] |
---|
1060 | e1v = (temporary(e1v))[0:*:stride[0], 0:*:stride[1]] |
---|
1061 | e2v = (temporary(e2v))[0:*:stride[0], 0:*:stride[1]] |
---|
1062 | e1f = (temporary(e1f))[0:*:stride[0], 0:*:stride[1]] |
---|
1063 | e2f = (temporary(e2f))[0:*:stride[0], 0:*:stride[1]] |
---|
1064 | umaskred = (temporary(umaskred))[0, 0:*:stride[1], 0:*:stride[2]] |
---|
1065 | vmaskred = (temporary(vmaskred))[0:*:stride[0], 0, 0:*:stride[2]] |
---|
1066 | fmaskredy = (temporary(fmaskredy))[0, 0:*:stride[1], 0:*:stride[2]] |
---|
1067 | fmaskredx = (temporary(fmaskredx))[0:*:stride[0], 0, 0:*:stride[2]] |
---|
1068 | IF jpj EQ 1 THEN BEGIN |
---|
1069 | glamu = reform(glamu, jpi, jpj, /over) |
---|
1070 | gphiu = reform(gphiu, jpi, jpj, /over) |
---|
1071 | e1u = reform(e1u, jpi, jpj, /over) |
---|
1072 | e2u = reform(e2u, jpi, jpj, /over) |
---|
1073 | glamv = reform(glamv, jpi, jpj, /over) |
---|
1074 | gphiv = reform(gphiv, jpi, jpj, /over) |
---|
1075 | e1v = reform(e1v, jpi, jpj, /over) |
---|
1076 | e2v = reform(e2v, jpi, jpj, /over) |
---|
1077 | e1f = reform(e1f, jpi, jpj, /over) |
---|
1078 | e2f = reform(e2f, jpi, jpj, /over) |
---|
1079 | ENDIF |
---|
1080 | ENDIF |
---|
1081 | ENDIF |
---|
1082 | ; |
---|
1083 | ;==================================================== |
---|
1084 | ; apply all the grid parameters |
---|
1085 | ;==================================================== |
---|
1086 | ; |
---|
1087 | @updateold |
---|
1088 | domdef |
---|
1089 | ; |
---|
1090 | ;==================================================== |
---|
1091 | ; Triangulation |
---|
1092 | ;==================================================== |
---|
1093 | ; |
---|
1094 | IF total(tmask) EQ jpi*jpj*jpk $ |
---|
1095 | AND NOT keyword_set(key_irregular) THEN triangles_list = -1 $ |
---|
1096 | ELSE BEGIN |
---|
1097 | ; are we using ORCA2 ? |
---|
1098 | IF jpiglo EQ 182 AND jpi EQ 181 AND jpjglo EQ 149 AND jpj EQ 148 THEN $ |
---|
1099 | triangles_list = triangule() ELSE triangles_list = triangule(/keep_cont) |
---|
1100 | ENDELSE |
---|
1101 | ; |
---|
1102 | ;==================================================== |
---|
1103 | ; time axis (default definition) |
---|
1104 | ;==================================================== |
---|
1105 | ; |
---|
1106 | IF n_elements(time) EQ 0 OR n_elements(jpt) EQ 0 THEN BEGIN |
---|
1107 | jpt = 1 |
---|
1108 | time = 0 |
---|
1109 | ENDIF |
---|
1110 | ; |
---|
1111 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
1112 | @updateold |
---|
1113 | ENDIF |
---|
1114 | ;==================================================== |
---|
1115 | ; grid parameters used by xxx |
---|
1116 | ;==================================================== |
---|
1117 | ; |
---|
1118 | IF NOT keyword_set(strcalling) THEN BEGIN |
---|
1119 | IF n_elements(ccmeshparameters) EQ 0 THEN strcalling = 'computegrid' $ |
---|
1120 | ELSE strcalling = ccmeshparameters.filename |
---|
1121 | ENDIF |
---|
1122 | IF n_elements(glamt) GE 2 THEN BEGIN |
---|
1123 | glaminfo = moment(glamt) |
---|
1124 | IF finite(glaminfo[2]) EQ 0 THEN glaminfo = glaminfo[0:1] |
---|
1125 | gphiinfo = moment(gphit) |
---|
1126 | IF finite(gphiinfo[2]) EQ 0 THEN gphiinfo = gphiinfo[0:1] |
---|
1127 | ENDIF ELSE BEGIN |
---|
1128 | glaminfo = glamt |
---|
1129 | gphiinfo = gphit |
---|
1130 | ENDELSE |
---|
1131 | ccmeshparameters = {filename:strcalling $ |
---|
1132 | , glaminfo:float(string(glaminfo, format = '(E11.4)')) $ |
---|
1133 | , gphiinfo:float(string(gphiinfo, format = '(E11.4)')) $ |
---|
1134 | , jpiglo:jpiglo, jpjglo:jpjglo, jpkglo:jpkglo $ |
---|
1135 | , jpi:jpi, jpj:jpj, jpk:jpk $ |
---|
1136 | , ixminmesh:ixminmesh, ixmaxmesh:ixmaxmesh $ |
---|
1137 | , iyminmesh:iyminmesh, iymaxmesh:iymaxmesh $ |
---|
1138 | , izminmesh:izminmesh, izmaxmesh:izmaxmesh $ |
---|
1139 | , key_shift:key_shift, key_periodic:key_periodic $ |
---|
1140 | , key_stride:key_stride, key_gridtype:key_gridtype $ |
---|
1141 | , key_yreverse:key_yreverse, key_zreverse:key_zreverse $ |
---|
1142 | , key_partialstep:key_partialstep, key_onearth:key_onearth} |
---|
1143 | |
---|
1144 | ccreadparameters = {funclec_name:'read_ncdf' $ |
---|
1145 | , jpidta:jpidta, jpjdta:jpjdta, jpkdta:jpkdta $ |
---|
1146 | , ixmindta:ixmindta, ixmaxdta:ixmaxdta $ |
---|
1147 | , iymindta:iymindta, iymaxdta:iymaxdta $ |
---|
1148 | , izmindta:izmindta, izmaxdta:izmaxdta} |
---|
1149 | ;------------------------------------------------------------ |
---|
1150 | IF keyword_set(key_performance) EQ 1 THEN $ |
---|
1151 | print, 'time computegrid', systime(1)-time1 |
---|
1152 | ;------------------------------------------------------------ |
---|
1153 | return |
---|
1154 | end |
---|