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

Last change on this file since 244 was 240, checked in by pinsard, 17 years ago

replace some print by some report in some .pro (continuation)

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