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

Last change on this file since 451 was 451, checked in by smasson, 13 years ago

update meshmask related file for full compatibility with partial steps

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