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

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

header improvements + xxx doc

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