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

Last change on this file since 103 was 103, checked in by pinsard, 18 years ago

start to modify headers of Grid .pro files for better idldoc output

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