source: trunk/SRC/Grid/ncdf_meshread.pro @ 371

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:keywords set to Id
File size: 24.1 KB
Line 
1;+
2;
3; @file_comments
4; read NetCDF meshmask file created by OPA
5;
6; @categories
7; Grid
8;
9; @examples
10;
11;   IDL> ncdf_meshread [,' filename']
12;
13; @param filename {in}{optional}{default='meshmask.nc'}{type=scalar string}
14;    Name of the meshmask file to read. If this name does not contain any "/"
15;    and if iodirectory keyword is not specified, then the common variable
16;    iodir will be used to define the mesh file path.
17;
18; @keyword GLAMBOUNDARY {default=those defined in the file}{type=2 elements vector}
19;    Longitude boundaries that should be used to visualize the data.
20;      lon2 > lon1
21;      lon2 - lon1 le 360
22;    By default, the common (cm_4mesh) variable key_shift will be automatically
23;    defined according to GLAMBOUNDARY.
24;
25; @keyword CHECKDAT
26; Suppressed. Use <pro>micromeshmask</pro> to create an appropriate meshmask.
27;
28; @keyword ONEARTH {default=1}{type=scalar: 0 or 1}
29;    Force the manual definition of data localization on the earth or not
30;       0) if the data are not on the earth
31;       1) if the data are on earth (in that case we can for example use
32;          the labels 'longitude', 'latitude' in plots).
33;    The resulting value will be stored in the common (cm_4mesh) variable key_onearth
34;    ONEARTH=0 forces PERIODIC=0, SHIFT=0 and is cancelling GLAMBOUNDARY
35;
36; @keyword GETDIMENSIONS {default=0}{type=scalar: 0 or 1}
37;    Activate this keywords if you only want to know the dimension
38;    of the domain stored in the mesh file. This dimension will be
39;    defined in jpiglo, jpjglo, jpkglo (cm_4mesh common variables)
40;
41; @keyword PERIODIC {default=computed by using the first line of glamt}{type=scalar: 0 or 1}
42;    Force the manual definition of the grid zonal periodicity.
43;    The resulting value will be stored in the common (cm_4mesh) variable key_periodic
44;    PERIODIC=0 forces SHIFT=0
45;
46; @keyword SHIFT {default=computed according to glamboundary}{type=scalar}
47;    Force the manual definition of the zonal shift that must be apply to the data.
48;    The resulting value will be stored in the common (cm_4mesh) variable key_shift
49;    Note that if key_periodic=0 then in any case key_shift = 0.
50;
51; @keyword STRCALLING {type=scalar string}
52;    the calling command used to call <pro>computegrid</pro> (this is used by <pro>xxx</pro>)
53;
54; @keyword STRIDE {default=[1, 1, 1]}{type=3 elements vector}
55;    Specify the stride in x, y and z direction. The resulting
56;    value will be stored in the common (cm_4mesh) variable key_stride
57;
58; @keyword _EXTRA
59; Used to pass keywords to <pro>isafile</pro>
60;
61; @uses
62; <pro>cm_4mesh</pro>
63; <pro>cm_4data</pro>
64; <pro>cm_4cal</pro>
65;
66; @restrictions
67; ixminmesh, ixmaxmesh, iyminmesh, iymaxmesh, izminmesh, izmaxmesh must
68; be defined before calling ncdf_meshread. If some of those values
69; are equal to -1 they will be automatically defined
70;
71; @history
72; Sebastien Masson (smasson\@lodyc.jussieu.fr)
73;                      12/1999
74; July 2004, Sebastien Masson: Several modifications (micromeshmask,
75; clean partial steps, clean use of key_stride, automatic definition
76; of key_shift, ...)
77; Oct. 2004, Sebastien Masson: add PERIODIC and SHIFT
78; Aug. 2005, Sebastien Masson: some cleaning + english
79;
80; @version
81; $Id$
82;
83;-
84PRO ncdf_meshread, filename, GLAMBOUNDARY=glamboundary, CHECKDAT=checkdat $
85                  , ONEARTH=onearth, GETDIMENSIONS=getdimensions $
86                  , PERIODIC=periodic, SHIFT=shift, STRIDE=stride $
87                  , STRCALLING=strcalling, _EXTRA=ex
88;
89  compile_opt idl2, strictarrsubs
90;
91@cm_4mesh
92@cm_4data
93@cm_4cal
94  IF NOT keyword_set(key_forgetold) THEN BEGIN
95@updatenew
96@updatekwd
97  ENDIF
98;
99  tempsun = systime(1)          ; for key_performance
100  IF keyword_set(CHECKDAT) THEN BEGIN
101    ras = report([' The keyword CHECKDAT has been suppressed (it could create bugs).', $
102    ' Remove it from the call of ncdf_meshread', $
103    ' Please use smallmeshmask.pro or micromeshmask.pro to create a', $
104    ' meshmask that has manageable size'])
105    return
106  ENDIF
107;-------------------------------------------------------
108; find meshfile name and open it!
109;-------------------------------------------------------
110; def of filename by default
111  IF n_params() EQ 0 then filename = 'meshmask.nc'
112  meshname = isafile(file = filename, iodirectory = iodir, _EXTRA = ex)
113  meshname = meshname[0]
114;
115  noticebase = xnotice('Reading file !C '+meshname+'!C ...')
116; if the meshmask is on tape archive ... get it back
117  IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+meshname+' > /dev/null'
118  cdfid = ncdf_open(meshname)
119  inq = ncdf_inquire(cdfid)
120;------------------------------------------------------------
121; dimensions
122;------------------------------------------------------------
123  ncdf_diminq, cdfid, 'x', name, jpiglo
124  ncdf_diminq, cdfid, 'y', name, jpjglo
125  listdims = strlowcase(ncdf_listdims(cdfid))
126  IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpkglo ELSE BEGIN
127    dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0]
128    IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpkglo ELSE BEGIN
129      dummy = report('We could not find the vertical dimension..., its name must be z or start with depth')
130      stop
131    ENDELSE
132  ENDELSE
133;
134  if keyword_set(getdimensions) then begin
135    widget_control, noticebase, bad_id = nothing, /destroy
136    ncdf_close,  cdfid
137    return
138  endif
139;-------------------------------------------------------
140; check that all i[xyz]min[ax]mesh are well defined
141;-------------------------------------------------------
142  if n_elements(ixminmesh) EQ 0 THEN ixminmesh = 0
143  if n_elements(ixmaxmesh) EQ 0 then ixmaxmesh = jpiglo-1
144  if ixminmesh EQ -1 THEN ixminmesh = 0
145  IF ixmaxmesh EQ -1 then ixmaxmesh = jpiglo-1
146  if n_elements(iyminmesh) EQ 0 THEN iyminmesh = 0
147  IF n_elements(iymaxmesh) EQ 0 then iymaxmesh = jpjglo-1
148  if iyminmesh EQ -1 THEN iyminmesh = 0
149  IF iymaxmesh EQ -1 then iymaxmesh = jpjglo-1
150  if n_elements(izminmesh) EQ 0 THEN izminmesh = 0
151  IF n_elements(izmaxmesh) EQ 0 then izmaxmesh = jpkglo-1
152  if izminmesh EQ -1 THEN izminmesh = 0
153  IF izmaxmesh EQ -1 then izmaxmesh = jpkglo-1
154; definition of jpi,jpj,jpj
155  jpi = long(ixmaxmesh-ixminmesh+1)
156  jpj = long(iymaxmesh-iyminmesh+1)
157  jpk = long(izmaxmesh-izminmesh+1)
158;-------------------------------------------------------
159; check onearth and its consequences
160;-------------------------------------------------------
161  IF n_elements(onearth) EQ 0 THEN key_onearth = 1 $
162  ELSE key_onearth = keyword_set(onearth)
163  IF NOT key_onearth THEN BEGIN
164    periodic = 0
165    shift = 0
166  ENDIF
167;-------------------------------------------------------
168; automatic definition of key_periodic
169;-------------------------------------------------------
170  IF n_elements(periodic) EQ 0 THEN BEGIN
171    IF jpi GT 1 THEN BEGIN
172      varinq = ncdf_varinq(cdfid, 'glamt')
173      CASE varinq.ndims OF
174        2:ncdf_varget, cdfid, 'glamt', xaxis $
175                       , offset = [ixminmesh, iyminmesh], count = [jpi, 1]
176        3:ncdf_varget, cdfid, 'glamt', xaxis $
177                       , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1]
178        4:ncdf_varget, cdfid, 'glamt', xaxis $
179                       , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1]
180      ENDCASE
181      xaxis = (xaxis+720) MOD 360
182      xaxis = xaxis[sort(xaxis)]
183      key_periodic = (xaxis[jpi-1]+2*(xaxis[jpi-1]-xaxis[jpi-2])) $
184                     GE (xaxis[0]+360)
185    ENDIF ELSE key_periodic = 0
186  ENDIF ELSE key_periodic = keyword_set(periodic)
187;-------------------------------------------------------
188; automatic definition of key_shift
189;-------------------------------------------------------
190  IF n_elements(shift) EQ 0 THEN BEGIN
191    key_shift = long(testvar(var = key_shift))
192;  key_shift will be defined according to the first line of glamt.
193    if keyword_set(glamboundary) AND jpi GT 1 AND key_periodic EQ 1 $
194    THEN BEGIN
195      varinq = ncdf_varinq(cdfid, 'glamt')
196      CASE varinq.ndims OF
197        2:ncdf_varget, cdfid, 'glamt', xaxis $
198                       , offset = [ixminmesh, iyminmesh], count = [jpi, 1]
199        3:ncdf_varget, cdfid, 'glamt', xaxis $
200                       , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1]
201        4:ncdf_varget, cdfid, 'glamt', xaxis $
202                       , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1]
203      ENDCASE
204; xaxis between glamboundary[0] and glamboundary[1]
205      xaxis = xaxis MOD 360
206      smaller = where(xaxis LT glamboundary[0])
207      if smaller[0] NE -1 then xaxis[smaller] = xaxis[smaller]+360
208      bigger = where(xaxis GE glamboundary[1])
209      if bigger[0] NE -1 then xaxis[bigger] = xaxis[bigger]-360
210;
211      key_shift = (where(xaxis EQ min(xaxis)))[0]
212      IF key_shift NE 0 THEN BEGIN
213        key_shift = jpi-key_shift
214        xaxis = shift(xaxis, key_shift)
215      ENDIF
216;
217      IF array_equal(sort(xaxis), lindgen(jpi)) NE 1 THEN BEGIN
218        ras = report(['the x axis (1st line of glamt) is not sorted in the increasing order after the automatic definition of key_shift', $
219        'please use the keyword shift (and periodic) to suppress the automatic definition of key_shift (and key_periodic) and define by hand a more suitable value...'])
220        widget_control, noticebase, bad_id = nothing, /destroy
221        return
222      ENDIF
223;
224    ENDIF ELSE key_shift = 0
225  ENDIF ELSE key_shift = long(shift)*(key_periodic EQ 1)
226;-------------------------------------------------------
227; check key_stride and related things
228;-------------------------------------------------------
229  if n_elements(stride) eq 3 then key_stride = stride
230  if n_elements(key_stride) LE 2 then key_stride = [1, 1, 1]
231  key_stride = 1l > long(key_stride)
232  IF total(key_stride) NE 3  THEN BEGIN
233    IF key_shift NE 0 THEN BEGIN
234; for explanation, see header of read_ncdf_varget.pro
235      jpiright = key_shift
236      jpileft = jpi - key_shift - ( (key_stride[0]-1)-((key_shift-1) MOD key_stride[0]) )
237      jpi = ((jpiright-1)/key_stride[0]+1) + ((jpileft-1)/key_stride[0]+1)
238    ENDIF ELSE jpi = (jpi-1)/key_stride[0]+1
239    jpj = (jpj-1)/key_stride[1]+1
240    jpk = (jpk-1)/key_stride[2]+1
241  ENDIF
242;-------------------------------------------------------
243; default definitions to be able to use read_ncdf_varget
244;-------------------------------------------------------
245; default definitions to be able to use read_ncdf_varget
246  ixmindtasauve = testvar(var = ixmindta)
247  iymindtasauve = testvar(var = iymindta)
248  izmindtasauve = testvar(var = izmindta)
249;
250  ixmindta = 0l
251  iymindta = 0l
252  izmindta = 0l
253;
254  jpt = 1
255  time = 1
256  firsttps = 0
257;
258  firstx = 0
259  lastx = jpi-1
260  firsty = 0
261  lasty = jpj-1
262  firstz = 0
263  lastz = jpk-1
264  nx = jpi
265  ny = jpj
266  nz = 1
267  izminmeshsauve = izminmesh
268  izminmesh = 0
269;
270  key_yreverse = 0
271  key_zreverse = 0
272  key_gridtype = 'c'
273;-------------------------------------------------------
274; 2d arrays:
275;-------------------------------------------------------
276; list the 2d variables that must be read
277  namevar = ['glamt', 'glamu', 'glamv', 'glamf' $
278             , 'gphit', 'gphiu', 'gphiv', 'gphif' $
279             , 'e1t', 'e1u', 'e1v', 'e1f' $
280             , 'e2t', 'e2u', 'e2v', 'e2f']
281; for the variables related to the partial steps
282  allvarname =  ncdf_listvars(cdfid)
283  IF (where(allvarname EQ 'hdept'))[0] NE -1 THEN BEGIN
284    key_partialstep = 1
285    namevar = [namevar, 'hdept', 'hdepw']
286  ENDIF ELSE BEGIN
287    key_partialstep = 0
288    hdept = -1
289    hdepw = -1
290  ENDELSE
291; for compatibility with old versions of meshmask/partial steps
292  IF (where(allvarname EQ 'e3tp'))[0] NE -1 THEN $
293    namevar = [namevar, 'e3tp', 'e3wp'] ELSE BEGIN
294    e3t_ps = -1
295    e3w_ps = -1
296  ENDELSE
297  IF (where(allvarname EQ 'e3t_ps'))[0] NE -1 $
298  THEN namevar = [namevar, 'e3t_ps', 'e3w_ps' ]ELSE BEGIN
299    e3t_ps = -1
300    e3w_ps = -1
301  ENDELSE
302  IF (where(allvarname EQ 'e3u_ps'))[0] NE -1 $
303  THEN namevar = [namevar, 'e3u_ps', 'e3v_ps'] ELSE BEGIN
304    e3u_ps = -1
305    e3v_ps = -1
306  ENDELSE
307;
308; read all the 2d variables
309;
310  for i = 0, n_elements(namevar)-1 do begin
311    varinq = ncdf_varinq(cdfid, namevar[i])
312    name = varinq.name
313@read_ncdf_varget
314    command = namevar[i]+'=float(temporary(res))'
315    nothing = execute(command)
316  ENDFOR
317; for compatibility with old versions of meshmask/partial steps
318; change e3[tw]p to e3[tw]_ps
319  IF n_elements(e3tp) NE 0 THEN e3t_ps = temporary(e3tp)
320  IF n_elements(e3wp) NE 0 THEN e3w_ps = temporary(e3wp)
321; in the case of key_stride ne [1, 1, 1] redefine f points
322; coordinates: they must be in the middle of 3 T points
323  if key_stride[0] NE 1 OR key_stride[1] NE 1 then BEGIN
324; we must recompute glamf and gphif...
325    IF jpi GT 1 THEN BEGIN
326      if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $
327        OR (keyword_set(key_periodic) AND key_irregular) then BEGIN
328        stepxf = (glamt + 720) MOD 360
329        stepxf = shift(stepxf, -1, -1) - stepxf
330        stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ]
331        stepxf = min(abs(stepxf), dimension = 3)
332        IF NOT keyword_set(key_periodic) THEN $
333          stepxf[jpi-1, *] = stepxf[jpi-2, *]
334      ENDIF ELSE BEGIN
335        stepxf = shift(glamt, -1, -1) - glamt
336        IF keyword_set(key_periodic) THEN $
337          stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $
338        ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *]
339      ENDELSE
340      IF jpj GT 1 THEN BEGIN
341        stepxf[*, jpj-1] = stepxf[*, jpj-2]
342        stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2]
343      ENDIF
344      glamf = glamt + 0.5 * stepxf
345    ENDIF ELSE glamf = glamt + 0.5
346    IF jpj GT 1 THEN BEGIN
347; we must compute stepyf: y distance between T(i,j) T(i+1,j+1)
348      stepyf = shift(gphit, -1, -1) - gphit
349      stepyf[*, jpj-1] = stepyf[*, jpj-2]
350      IF jpi GT 1 THEN BEGIN
351        if NOT keyword_set(key_periodic) THEN $
352          stepyf[jpi-1, *] = stepyf[jpi-2, *]
353        stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2]
354      ENDIF
355      gphif = gphit + 0.5 * stepyf
356    ENDIF ELSE gphif = gphit + 0.5
357  ENDIF
358;-------------------------------------------------------
359; 3d arrays:
360;-------------------------------------------------------
361  nz = jpk
362  izminmesh = izminmeshsauve
363;
364  listdims = ncdf_listdims(cdfid)
365  micromask = (where(listdims EQ 'y_m'))[0]
366;
367  varinq = ncdf_varinq(cdfid, 'tmask')
368  name = varinq.name
369  IF micromask NE -1 THEN BEGIN
370; keep original values
371    iyminmeshtrue = iyminmesh
372    key_stridetrue = key_stride
373    yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue
374    yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue
375; the mask is stored as the bit values of the byte array (along the y
376; dimension, see micromeshmask.pro)...
377; we must modify several parameters...
378    iyminmesh = 0L
379    firsty = yyy1/8
380    lasty = yyy2/8
381    ny = lasty-firsty+1
382    key_stride = [key_stride[0], 1, key_stride[2]]
383@read_ncdf_varget
384    tmask = bytarr(jpi, jpj, jpk)
385; now we must get back the mask
386; loop on the level to save memory (the loop is short and, thus,
387; should be fast enough)
388    FOR k = 0, jpk-1 DO BEGIN
389      zzz = transpose(res[*, *, k])
390      zzz = reform(binary(zzz), 8*ny, nx, /over)
391      zzz = transpose(temporary(zzz))
392      zzz = zzz[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8]
393      IF key_stridetrue[1] NE 1 THEN BEGIN
394;        IF float(strmid(!version.release,0,3)) LT 5.6 THEN BEGIN
395        nnny = (size(zzz))[2]
396        yind = key_stridetrue[1]*lindgen((nnny-1)/key_stridetrue[1]+1)
397        tmask[*, *, k] = temporary(zzz[*, yind])
398;        ENDIF ELSE tmask[*, *, k] = temporary(zzz[*, 0:*:key_stridetrue[1]])
399      ENDIF ELSE tmask[*, *, k] = temporary(zzz)
400    ENDFOR
401  ENDIF ELSE BEGIN
402@read_ncdf_varget
403    tmask = byte(res)
404  ENDELSE
405; boundary conditions used to compute umask.
406  IF ncdf_varid(cdfid, 'umask') NE -1 THEN BEGIN
407     varinq = ncdf_varinq(cdfid, 'umask')
408     name = varinq.name
409     nx = 1L
410     firstx = jpi-1
411     lastx = jpi-1
412     IF micromask NE -1 THEN BEGIN
413@read_ncdf_varget
414        umaskred = reform(binary(res), 8*ny, jpk, /over)
415        umaskred = umaskred[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]
416        IF key_stridetrue[1] NE 1 THEN umaskred = temporary(umaskred[yind, *])
417     ENDIF ELSE BEGIN
418@read_ncdf_varget
419        umaskred = reform(byte(res), /over)
420     ENDELSE
421  ENDIF ELSE umaskred = bytarr(jpj, jpk)
422; boundary conditions used to compute fmask (1).
423  IF ncdf_varid(cdfid, 'fmask') NE -1 THEN BEGIN
424     varinq = ncdf_varinq(cdfid, 'fmask')
425     name = varinq.name
426     IF micromask NE -1 THEN BEGIN
427@read_ncdf_varget
428        fmaskredy = reform(binary(res), 8*ny, jpk, /over)
429        fmaskredy = fmaskredy[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]
430        IF key_stridetrue[1] NE 1 THEN fmaskredy = temporary(fmaskredy[yind, *])
431     ENDIF ELSE BEGIN
432@read_ncdf_varget
433        fmaskredy = reform(byte(res), /over)
434        fmaskredy = temporary(fmaskredy) MOD 2
435     ENDELSE
436  ENDIF ELSE fmaskredy = bytarr(jpj, jpk)
437; boundary conditions used to compute vmask
438  IF ncdf_varid(cdfid, 'vmask') NE -1 THEN BEGIN
439     varinq = ncdf_varinq(cdfid, 'vmask')
440     name = varinq.name
441     nx = jpi
442     firstx = 0L
443     lastx = jpi-1L
444     ny = 1L
445     firsty = jpj-1
446     lasty = jpj-1
447     IF micromask NE -1 THEN BEGIN
448        yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue
449        yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue
450        iyminmesh = 0L
451        firsty = yyy1/8
452        lasty = yyy2/8
453        ny = lasty-firsty+1
454@read_ncdf_varget
455        IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over)
456        vmaskred = transpose(temporary(res), [1, 0, 2])
457        vmaskred = reform(binary(vmaskred), 8*ny, nx, nz, /over)
458        vmaskred = transpose(temporary(vmaskred), [1, 0, 2])
459        vmaskred = reform(vmaskred[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *])
460     ENDIF ELSE BEGIN
461@read_ncdf_varget
462        vmaskred = reform(byte(res), /over)
463     ENDELSE
464  ENDIF ELSE vmaskred = bytarr(jpi, jpk)
465; boundary conditions used to compute fmask (2).
466  IF ncdf_varid(cdfid, 'fmask') NE -1 THEN BEGIN
467     varinq = ncdf_varinq(cdfid, 'fmask')
468     name = varinq.name
469     IF micromask NE -1 THEN BEGIN
470@read_ncdf_varget
471        IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over)
472        fmaskredx = transpose(temporary(res), [1, 0, 2])
473        fmaskredx = reform(binary(fmaskredx), 8*ny, nx, nz, /over)
474        fmaskredx = transpose(temporary(fmaskredx), [1, 0, 2])
475        fmaskredx = reform(fmaskredx[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *])
476;
477        iyminmesh = iyminmeshtrue
478        key_stride = key_stridetrue
479     ENDIF ELSE BEGIN
480@read_ncdf_varget
481        fmaskredx = reform(byte(res), /over)
482        fmaskredx = fmaskredx MOD 2
483     ENDELSE
484  ENDIF ELSE fmaskredx = bytarr(jpi, jpk)
485;-------------------------------------------------------
486; 1d arrays
487;-------------------------------------------------------
488  IF (where(allvarname EQ 'e3t_0'))[0] NE -1 THEN fnamevar = ['e3t_0', 'e3w_0', 'gdept_0', 'gdepw_0'] $
489  ELSE                                            fnamevar = ['e3t', 'e3w', 'gdept', 'gdepw']
490  namevar = ['e3t', 'e3w', 'gdept', 'gdepw']
491  for i = 0, n_elements(namevar)-1 do begin
492    varinq = ncdf_varinq(cdfid, fnamevar[i])
493    CASE n_elements(varinq.dim) OF
494      4:BEGIN
495        command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $
496                   +',offset = [0,0,izminmesh,0], count = [1,1,jpk,1]'
497        if key_stride[2] NE 1 then command = command+', stride=[1,1,key_stride[2],1]'
498      END
499      2:BEGIN
500        command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $
501                   +',offset = [izminmesh,0], count = [jpk,1]'
502        if key_stride[2] NE 1 then command = command+', stride=key_stride[2]'
503      END
504      1:BEGIN
505        command = 'ncdf_varget,cdfid,fnamevar[i],'+namevar[i] $
506                   +',offset = [izminmesh], count = [jpk]'
507        if key_stride[2] NE 1 then command = command+', stride=key_stride[2]'
508      END
509    ENDCASE
510    nothing = execute(command)
511    command = namevar[i]+'=float('+namevar[i]+')'
512    nothing = execute(command)
513    command = 'if size('+namevar[i]+', /n_dimension) gt 0 then '+namevar[i]+' = reform('+namevar[i]+', /over)'
514    nothing = execute(command)
515  ENDFOR
516;-------------------------------------------------------
517  ncdf_close,  cdfid
518;-------------------------------------------------------
519; Apply Glamboundary
520;-------------------------------------------------------
521  if keyword_set(glamboundary) AND key_onearth then BEGIN
522    if glamboundary[0] NE glamboundary[1] then BEGIN
523      glamt = temporary(glamt) MOD 360
524      smaller = where(glamt LT glamboundary[0])
525      if smaller[0] NE -1 then glamt[smaller] = glamt[smaller]+360
526      bigger = where(glamt GE glamboundary[1])
527      if bigger[0] NE -1 then glamt[bigger] = glamt[bigger]-360
528      glamu = temporary(glamu) MOD 360
529      smaller = where(glamu LT glamboundary[0])
530      if smaller[0] NE -1 then glamu[smaller] = glamu[smaller]+360
531      bigger = where(glamu GE glamboundary[1])
532      if bigger[0] NE -1 then glamu[bigger] = glamu[bigger]-360
533      glamv = temporary(glamv) MOD 360
534      smaller = where(glamv LT glamboundary[0])
535      if smaller[0] NE -1 then glamv[smaller] = glamv[smaller]+360
536      bigger = where(glamv GE glamboundary[1])
537      if bigger[0] NE -1 then glamv[bigger] = glamv[bigger]-360
538      glamf = temporary(glamf) MOD 360
539      smaller = where(glamf LT glamboundary[0])
540      if smaller[0] NE -1 then glamf[smaller] = glamf[smaller]+360
541      bigger = where(glamf GE glamboundary[1])
542      if bigger[0] NE -1 then glamf[bigger] = glamf[bigger]-360
543      toosmall = where(glamu EQ glamboundary[0])
544      IF toosmall[0] NE -1 THEN glamu[toosmall] = glamu[toosmall] + 360
545      toosmall = where(glamf EQ glamboundary[0])
546      IF toosmall[0] NE -1 THEN glamf[toosmall] = glamf[toosmall] + 360
547    endif
548  endif
549;-------------------------------------------------------
550; make sure we do have 2d arrays when jpj eq 1
551;-------------------------------------------------------
552  IF jpj EQ 1 THEN BEGIN
553    glamt = reform(glamt, jpi, jpj, /over)
554    gphit = reform(gphit, jpi, jpj, /over)
555    e1t = reform(e1t, jpi, jpj, /over)
556    e2t = reform(e2t, jpi, jpj, /over)
557    glamu = reform(glamu, jpi, jpj, /over)
558    gphiu = reform(gphiu, jpi, jpj, /over)
559    e1u = reform(e1u, jpi, jpj, /over)
560    e2u = reform(e2u, jpi, jpj, /over)
561    glamv = reform(glamv, jpi, jpj, /over)
562    gphiv = reform(gphiv, jpi, jpj, /over)
563    e1v = reform(e1v, jpi, jpj, /over)
564    e2v = reform(e2v, jpi, jpj, /over)
565    glamf = reform(glamf, jpi, jpj, /over)
566    gphif = reform(gphif, jpi, jpj, /over)
567    e1f = reform(e1f, jpi, jpj, /over)
568    e2f = reform(e2f, jpi, jpj, /over)
569    IF keyword_set(key_partialstep) THEN BEGIN
570      hdept = reform(hdept, jpi, jpj, /over)
571      hdepw = reform(hdepw, jpi, jpj, /over)
572      e3t_ps = reform(e3t_ps, jpi, jpj, /over)
573      e3w_ps = reform(e3w_ps, jpi, jpj, /over)
574    ENDIF
575  ENDIF
576;-------------------------------------------------------
577  ixmindta = ixmindtasauve
578  iymindta = iymindtasauve
579  izmindta = izmindtasauve
580;-------------------------------------------------------
581  widget_control, noticebase, bad_id = nothing, /destroy
582;
583;====================================================
584; grid parameters used by xxx
585;====================================================
586;
587  IF NOT keyword_set(strcalling) THEN BEGIN
588    IF n_elements(ccmeshparameters) EQ 0 THEN strcalling = 'ncdf_meshread' $
589    ELSE strcalling = ccmeshparameters.filename
590  ENDIF
591  IF n_elements(glamt) GE 2 THEN BEGIN
592    glaminfo = moment(glamt)
593    IF finite(glaminfo[2]) EQ 0 THEN glaminfo = glaminfo[0:1]
594    gphiinfo = moment(gphit)
595    IF finite(gphiinfo[2]) EQ 0 THEN gphiinfo = gphiinfo[0:1]
596  ENDIF ELSE BEGIN
597    glaminfo = glamt
598    gphiinfo = gphit
599  ENDELSE
600  romszinfos = {h:-1, zeta:-1, theta_s:-1, theta_b:-1, hc:-1}
601  ccmeshparameters = {filename:strcalling  $
602          , glaminfo:float(string(glaminfo, format = '(E11.4)')) $
603          , gphiinfo:float(string(gphiinfo, format = '(E11.4)')) $
604          , jpiglo:jpiglo, jpjglo:jpjglo, jpkglo:jpkglo $
605          , jpi:jpi, jpj:jpj, jpk:jpk $
606          , ixminmesh:ixminmesh, ixmaxmesh:ixmaxmesh $
607          , iyminmesh:iyminmesh, iymaxmesh:iymaxmesh $
608          , izminmesh:izminmesh, izmaxmesh:izmaxmesh $
609          , key_shift:key_shift, key_periodic:key_periodic $
610          , key_stride:key_stride, key_gridtype:key_gridtype $
611          , key_yreverse:key_yreverse, key_zreverse:key_zreverse $
612          , key_partialstep:key_partialstep, key_onearth:key_onearth}
613;
614  if keyword_set(key_performance) THEN $
615    print, 'time ncdf_meshread', systime(1)-tempsun
616
617;-------------------------------------------------------
618   @updateold
619;-------------------------------------------------------
620   return
621 end
Note: See TracBrowser for help on using the repository browser.