source: trunk/SRC/Grid/ncdf_meshread.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 26.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    IF NOT keyword_set(key_batch) then 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        IF NOT keyword_set(key_batch) then 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;
284  key_partialstep = 0
285  hdept = -1
286  hdepw = -1
287  IF (where(allvarname EQ 'hdept'))[0] NE -1 AND jpk EQ jpkglo THEN BEGIN
288    key_partialstep = 1
289    namevar = [namevar, 'hdept', 'hdepw']
290  ENDIF
291; is gdept a real 3D array?
292  IF (where(allvarname EQ 'gdept' ))[0] NE -1 AND jpk EQ jpkglo THEN BEGIN
293    varinq = ncdf_varinq(cdfid, 'gdept')
294    if varinq.ndims GE 3 THEN BEGIN
295      ncdf_diminq, cdfid, varinq.dim[0], name, iii
296      ncdf_diminq, cdfid, varinq.dim[1], name, jjj
297      ncdf_diminq, cdfid, varinq.dim[2], name, kkk
298      IF iii EQ jpiglo AND jjj EQ jpjglo AND kkk EQ jpkglo THEN key_gdep_3d = 1
299    ENDIF
300  ENDIF
301; for compatibility with old versions of meshmask/partial steps
302  e3t_ps = -1
303  e3w_ps = -1
304  IF (where(allvarname EQ 'e3tp'  ))[0] NE -1 THEN namevar = [namevar, 'e3tp', 'e3wp']
305  IF (where(allvarname EQ 'e3t_ps'))[0] NE -1 THEN namevar = [namevar, 'e3t_ps', 'e3w_ps' ]
306; is e3t a real 3D array?
307  IF (where(allvarname EQ 'e3t'   ))[0] NE -1 AND jpk EQ jpkglo THEN BEGIN
308    varinq = ncdf_varinq(cdfid, 'e3t')
309    if varinq.ndims GE 3 THEN BEGIN
310      ncdf_diminq, cdfid, varinq.dim[0], name, iii
311      ncdf_diminq, cdfid, varinq.dim[1], name, jjj
312      ncdf_diminq, cdfid, varinq.dim[2], name, kkk
313      IF iii EQ jpiglo AND jjj EQ jpjglo AND kkk EQ jpkglo THEN BEGIN
314        key_e3_3d = 1
315        key_partialstep = 1
316      ENDIF
317    ENDIF
318  ENDIF
319;
320; read all the 2d variables
321;
322  for i = 0, n_elements(namevar)-1 do begin
323    varinq = ncdf_varinq(cdfid, namevar[i])
324    name = varinq.name
325@read_ncdf_varget
326    CASE namevar[i] OF
327      'glamt':glamt = float(temporary(res))
328      'glamu':glamu = float(temporary(res))
329      'glamv':glamv = float(temporary(res))
330      'glamf':glamf = float(temporary(res))
331      'gphit':gphit = float(temporary(res))
332      'gphiu':gphiu = float(temporary(res))
333      'gphiv':gphiv = float(temporary(res))
334      'gphif':gphif = float(temporary(res))
335      'e1t':e1t = float(temporary(res))
336      'e1u':e1u = float(temporary(res))
337      'e1v':e1v = float(temporary(res))
338      'e1f':e1f = float(temporary(res))
339      'e2t':e2t = float(temporary(res))
340      'e2u':e2u = float(temporary(res))
341      'e2v':e2v = float(temporary(res))
342      'e2f':e2f = float(temporary(res))
343      'hdept':hdept = float(temporary(res))
344      'hdepw':hdepw = float(temporary(res))
345      'e3t_ps':e3t_ps = temporary(res)
346      'e3tp':e3t_ps = temporary(res)
347      'e3w_ps':e3w_ps = temporary(res)
348      'e3wp':e3w_ps = temporary(res)
349    ENDCASE
350  ENDFOR
351; in the case of key_stride ne [1, 1, 1] redefine f points
352; coordinates: they must be in the middle of 3 T points
353  if key_stride[0] NE 1 OR key_stride[1] NE 1 then BEGIN
354; we must recompute glamf and gphif...
355    IF jpi GT 1 THEN BEGIN
356      if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $
357        OR (keyword_set(key_periodic) AND key_irregular) then BEGIN
358        stepxf = (glamt + 720) MOD 360
359        stepxf = shift(stepxf, -1, -1) - stepxf
360        stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ]
361        stepxf = min(abs(stepxf), dimension = 3)
362        IF NOT keyword_set(key_periodic) THEN $
363          stepxf[jpi-1, *] = stepxf[jpi-2, *]
364      ENDIF ELSE BEGIN
365        stepxf = shift(glamt, -1, -1) - glamt
366        IF keyword_set(key_periodic) THEN $
367          stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $
368        ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *]
369      ENDELSE
370      IF jpj GT 1 THEN BEGIN
371        stepxf[*, jpj-1] = stepxf[*, jpj-2]
372        stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2]
373      ENDIF
374      glamf = glamt + 0.5 * stepxf
375    ENDIF ELSE glamf = glamt + 0.5
376    IF jpj GT 1 THEN BEGIN
377; we must compute stepyf: y distance between T(i,j) T(i+1,j+1)
378      stepyf = shift(gphit, -1, -1) - gphit
379      stepyf[*, jpj-1] = stepyf[*, jpj-2]
380      IF jpi GT 1 THEN BEGIN
381        if NOT keyword_set(key_periodic) THEN $
382          stepyf[jpi-1, *] = stepyf[jpi-2, *]
383        stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2]
384      ENDIF
385      gphif = gphit + 0.5 * stepyf
386    ENDIF ELSE gphif = gphit + 0.5
387  ENDIF
388;-------------------------------------------------------
389; 3d arrays:
390;-------------------------------------------------------
391  nz = jpk
392  izminmesh = izminmeshsauve
393;
394  listdims = ncdf_listdims(cdfid)
395  micromask = (where(listdims EQ 'y_m'))[0]
396;
397  varinq = ncdf_varinq(cdfid, 'tmask')
398  name = varinq.name
399  IF micromask NE -1 THEN BEGIN
400; keep original values
401    iyminmeshtrue = iyminmesh
402    key_stridetrue = key_stride
403    yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue
404    yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue
405; the mask is stored as the bit values of the byte array (along the y
406; dimension, see micromeshmask.pro)...
407; we must modify several parameters...
408    iyminmesh = 0L
409    firsty = yyy1/8
410    lasty = yyy2/8
411    ny = lasty-firsty+1
412    key_stride = [key_stride[0], 1, key_stride[2]]
413@read_ncdf_varget
414    tmask = bytarr(jpi, jpj, jpk)
415; now we must get back the mask
416; loop on the level to save memory (the loop is short and, thus,
417; should be fast enough)
418    FOR k = 0, jpk-1 DO BEGIN
419      zzz = transpose(res[*, *, k])
420      zzz = reform(binary(zzz), 8*ny, nx, /over)
421      zzz = transpose(temporary(zzz))
422      zzz = zzz[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8]
423      IF key_stridetrue[1] NE 1 THEN BEGIN
424;        IF float(strmid(!version.release,0,3)) LT 5.6 THEN BEGIN
425        nnny = (size(zzz))[2]
426        yind = key_stridetrue[1]*lindgen((nnny-1)/key_stridetrue[1]+1)
427        tmask[*, *, k] = temporary(zzz[*, yind])
428;        ENDIF ELSE tmask[*, *, k] = temporary(zzz[*, 0:*:key_stridetrue[1]])
429      ENDIF ELSE tmask[*, *, k] = temporary(zzz)
430    ENDFOR
431  ENDIF ELSE BEGIN
432@read_ncdf_varget
433    tmask = byte(res)
434  ENDELSE
435; if e3t is true 3D array...
436  IF keyword_set(key_e3_3d)  THEN BEGIN
437    bottom = 0 > ( total(tmask, 3)-1 )
438    bottom = lindgen(jpi, jpj) + jpi*jpj*temporary(bottom)
439;
440    varinq = ncdf_varinq(cdfid, 'e3t')
441    name = varinq.name
442@read_ncdf_varget
443    e3t_ps = (temporary(res))[bottom] * tmask[*, *, 0]
444;
445    varinq = ncdf_varinq(cdfid, 'e3w')
446    name = varinq.name
447@read_ncdf_varget
448    e3w_ps = (temporary(res))[bottom] * tmask[*, *, 0]
449  ENDIF
450; if gdep is true 3D array...
451  IF keyword_set(key_gdep_3d) THEN BEGIN
452    bottom = 0 > ( total(tmask, 3)-1 )
453    bottom = lindgen(jpi, jpj) + jpi*jpj*temporary(bottom)
454;
455    varinq = ncdf_varinq(cdfid, 'gdept')
456    name = varinq.name
457@read_ncdf_varget
458    hdept = (temporary(res))[bottom] * tmask[*, *, 0]
459;
460    bottom = jpi*jpj + temporary(bottom)
461    varinq = ncdf_varinq(cdfid, 'gdepw')
462    name = varinq.name
463@read_ncdf_varget
464    hdepw = (temporary(res))[bottom] * tmask[*, *, 0]
465  ENDIF
466; boundary conditions used to compute umask.
467  IF ncdf_varid(cdfid, 'umask') NE -1 THEN BEGIN
468     varinq = ncdf_varinq(cdfid, 'umask')
469     name = varinq.name
470     nx = 1L
471     firstx = jpi-1
472     lastx = jpi-1
473     IF micromask NE -1 THEN BEGIN
474@read_ncdf_varget
475        umaskred = reform(binary(res), 8*ny, jpk, /over)
476        umaskred = umaskred[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]
477        IF key_stridetrue[1] NE 1 THEN umaskred = temporary(umaskred[yind, *])
478     ENDIF ELSE BEGIN
479@read_ncdf_varget
480        umaskred = reform(byte(res), /over)
481     ENDELSE
482  ENDIF ELSE umaskred = bytarr(jpj, jpk)
483; boundary conditions used to compute fmask (1).
484  IF ncdf_varid(cdfid, 'fmask') NE -1 THEN BEGIN
485     varinq = ncdf_varinq(cdfid, 'fmask')
486     name = varinq.name
487     IF micromask NE -1 THEN BEGIN
488@read_ncdf_varget
489        fmaskredy = reform(binary(res), 8*ny, jpk, /over)
490        fmaskredy = fmaskredy[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]
491        IF key_stridetrue[1] NE 1 THEN fmaskredy = temporary(fmaskredy[yind, *])
492     ENDIF ELSE BEGIN
493@read_ncdf_varget
494        fmaskredy = reform(byte(res), /over)
495        fmaskredy = temporary(fmaskredy) MOD 2
496     ENDELSE
497  ENDIF ELSE fmaskredy = bytarr(jpj, jpk)
498; boundary conditions used to compute vmask
499  IF ncdf_varid(cdfid, 'vmask') NE -1 THEN BEGIN
500     varinq = ncdf_varinq(cdfid, 'vmask')
501     name = varinq.name
502     nx = jpi
503     firstx = 0L
504     lastx = jpi-1L
505     ny = 1L
506     firsty = jpj-1
507     lasty = jpj-1
508     IF micromask NE -1 THEN BEGIN
509        yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue
510        yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue
511        iyminmesh = 0L
512        firsty = yyy1/8
513        lasty = yyy2/8
514        ny = lasty-firsty+1
515@read_ncdf_varget
516        IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over)
517        vmaskred = transpose(temporary(res), [1, 0, 2])
518        vmaskred = reform(binary(vmaskred), 8*ny, nx, nz, /over)
519        vmaskred = transpose(temporary(vmaskred), [1, 0, 2])
520        vmaskred = reform(vmaskred[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *])
521     ENDIF ELSE BEGIN
522@read_ncdf_varget
523        vmaskred = reform(byte(res), /over)
524     ENDELSE
525  ENDIF ELSE vmaskred = bytarr(jpi, jpk)
526; boundary conditions used to compute fmask (2).
527  IF ncdf_varid(cdfid, 'fmask') NE -1 THEN BEGIN
528     varinq = ncdf_varinq(cdfid, 'fmask')
529     name = varinq.name
530     IF micromask NE -1 THEN BEGIN
531@read_ncdf_varget
532        IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over)
533        fmaskredx = transpose(temporary(res), [1, 0, 2])
534        fmaskredx = reform(binary(fmaskredx), 8*ny, nx, nz, /over)
535        fmaskredx = transpose(temporary(fmaskredx), [1, 0, 2])
536        fmaskredx = reform(fmaskredx[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *])
537;
538        iyminmesh = iyminmeshtrue
539        key_stride = key_stridetrue
540     ENDIF ELSE BEGIN
541@read_ncdf_varget
542        fmaskredx = reform(byte(res), /over)
543        fmaskredx = fmaskredx MOD 2
544     ENDELSE
545  ENDIF ELSE fmaskredx = bytarr(jpi, jpk)
546;-------------------------------------------------------
547; 1d arrays
548;-------------------------------------------------------
549  IF (where(allvarname EQ 'e3t_0'))[0] NE -1 THEN fnamevar = ['e3t_0', 'e3w_0', 'gdept_0', 'gdepw_0'] $
550  ELSE                                            fnamevar = ['e3t', 'e3w', 'gdept', 'gdepw']
551  for i = 0, n_elements(fnamevar)-1 do begin
552    varinq = ncdf_varinq(cdfid, fnamevar[i])
553    CASE n_elements(varinq.dim) OF
554      4:ncdf_varget,cdfid,fnamevar[i],tmp,offset = [0,0,izminmesh,0], count = [1,1,jpk,1], stride=[1,1,key_stride[2],1]
555      2:ncdf_varget,cdfid,fnamevar[i],tmp,offset = [izminmesh,0], count = [jpk,1], stride=[key_stride[2], 1]
556      1:ncdf_varget,cdfid,fnamevar[i],tmp,offset = [izminmesh], count = [jpk], stride=key_stride[2]
557    ENDCASE
558    if size(tmp, /n_dimension) gt 0 then tmp = reform(tmp, /over)
559    CASE fnamevar[i] OF
560      'gdept':gdept = float(tmp)
561      'gdept_0':gdept = float(tmp)
562      'gdepw':gdepw = float(tmp)
563      'gdepw_0':gdepw = float(tmp)
564      'e3t':e3t = tmp
565      'e3t_0':e3t = tmp
566      'e3w':e3w = tmp
567      'e3w_0':e3w = tmp
568    ENDCASE
569  ENDFOR
570;-------------------------------------------------------
571  ncdf_close,  cdfid
572;-------------------------------------------------------
573; Apply Glamboundary
574;-------------------------------------------------------
575  if keyword_set(glamboundary) AND key_onearth then BEGIN
576    if glamboundary[0] NE glamboundary[1] then BEGIN
577      glamt = temporary(glamt) MOD 360
578      smaller = where(glamt LT glamboundary[0])
579      if smaller[0] NE -1 then glamt[smaller] = glamt[smaller]+360
580      bigger = where(glamt GE glamboundary[1])
581      if bigger[0] NE -1 then glamt[bigger] = glamt[bigger]-360
582      glamu = temporary(glamu) MOD 360
583      smaller = where(glamu LT glamboundary[0])
584      if smaller[0] NE -1 then glamu[smaller] = glamu[smaller]+360
585      bigger = where(glamu GE glamboundary[1])
586      if bigger[0] NE -1 then glamu[bigger] = glamu[bigger]-360
587      glamv = temporary(glamv) MOD 360
588      smaller = where(glamv LT glamboundary[0])
589      if smaller[0] NE -1 then glamv[smaller] = glamv[smaller]+360
590      bigger = where(glamv GE glamboundary[1])
591      if bigger[0] NE -1 then glamv[bigger] = glamv[bigger]-360
592      glamf = temporary(glamf) MOD 360
593      smaller = where(glamf LT glamboundary[0])
594      if smaller[0] NE -1 then glamf[smaller] = glamf[smaller]+360
595      bigger = where(glamf GE glamboundary[1])
596      if bigger[0] NE -1 then glamf[bigger] = glamf[bigger]-360
597      toosmall = where(glamu EQ glamboundary[0])
598      IF toosmall[0] NE -1 THEN glamu[toosmall] = glamu[toosmall] + 360
599      toosmall = where(glamf EQ glamboundary[0])
600      IF toosmall[0] NE -1 THEN glamf[toosmall] = glamf[toosmall] + 360
601    endif
602  endif
603;-------------------------------------------------------
604; make sure we do have 2d arrays when jpj eq 1
605;-------------------------------------------------------
606  IF jpj EQ 1 THEN BEGIN
607    glamt = reform(glamt, jpi, jpj, /over)
608    gphit = reform(gphit, jpi, jpj, /over)
609    e1t = reform(e1t, jpi, jpj, /over)
610    e2t = reform(e2t, jpi, jpj, /over)
611    glamu = reform(glamu, jpi, jpj, /over)
612    gphiu = reform(gphiu, jpi, jpj, /over)
613    e1u = reform(e1u, jpi, jpj, /over)
614    e2u = reform(e2u, jpi, jpj, /over)
615    glamv = reform(glamv, jpi, jpj, /over)
616    gphiv = reform(gphiv, jpi, jpj, /over)
617    e1v = reform(e1v, jpi, jpj, /over)
618    e2v = reform(e2v, jpi, jpj, /over)
619    glamf = reform(glamf, jpi, jpj, /over)
620    gphif = reform(gphif, jpi, jpj, /over)
621    e1f = reform(e1f, jpi, jpj, /over)
622    e2f = reform(e2f, jpi, jpj, /over)
623    IF keyword_set(key_partialstep) THEN BEGIN
624      hdept = reform(hdept, jpi, jpj, /over)
625      hdepw = reform(hdepw, jpi, jpj, /over)
626      e3t_ps = reform(e3t_ps, jpi, jpj, /over)
627      e3w_ps = reform(e3w_ps, jpi, jpj, /over)
628    ENDIF
629  ENDIF
630;-------------------------------------------------------
631  ixmindta = ixmindtasauve
632  iymindta = iymindtasauve
633  izmindta = izmindtasauve
634;-------------------------------------------------------
635  IF NOT keyword_set(key_batch) then widget_control, noticebase, bad_id = nothing, /destroy
636;
637;====================================================
638; grid parameters used by xxx
639;====================================================
640;
641  IF NOT keyword_set(strcalling) THEN BEGIN
642    IF n_elements(ccmeshparameters) EQ 0 THEN strcalling = 'ncdf_meshread' $
643    ELSE strcalling = ccmeshparameters.filename
644  ENDIF
645  IF n_elements(glamt) GE 2 THEN BEGIN
646    glaminfo = moment(glamt)
647    IF finite(glaminfo[2]) EQ 0 THEN glaminfo = glaminfo[0:1]
648    gphiinfo = moment(gphit)
649    IF finite(gphiinfo[2]) EQ 0 THEN gphiinfo = gphiinfo[0:1]
650  ENDIF ELSE BEGIN
651    glaminfo = glamt
652    gphiinfo = gphit
653  ENDELSE
654  romszinfos = {h:-1, zeta:-1, theta_s:-1, theta_b:-1, hc:-1}
655  ccmeshparameters = {filename:strcalling  $
656          , glaminfo:float(string(glaminfo, format = '(E11.4)')) $
657          , gphiinfo:float(string(gphiinfo, format = '(E11.4)')) $
658          , jpiglo:jpiglo, jpjglo:jpjglo, jpkglo:jpkglo $
659          , jpi:jpi, jpj:jpj, jpk:jpk $
660          , ixminmesh:ixminmesh, ixmaxmesh:ixmaxmesh $
661          , iyminmesh:iyminmesh, iymaxmesh:iymaxmesh $
662          , izminmesh:izminmesh, izmaxmesh:izmaxmesh $
663          , key_shift:key_shift, key_periodic:key_periodic $
664          , key_stride:key_stride, key_gridtype:key_gridtype $
665          , key_yreverse:key_yreverse, key_zreverse:key_zreverse $
666          , key_partialstep:key_partialstep, key_onearth:key_onearth}
667;
668  if keyword_set(key_performance) THEN $
669    print, 'time ncdf_meshread', systime(1)-tempsun
670
671;-------------------------------------------------------
672   @updateold
673;-------------------------------------------------------
674   return
675 end
Note: See TracBrowser for help on using the repository browser.