source: trunk/SRC/Grid/computegrid.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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