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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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