source: trunk/SRC/ToBeReviewed/INIT/initncdf.pro @ 508

Last change on this file since 508 was 508, checked in by smasson, 7 years ago

minor improvments

  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1;+
2;
3; @file_comments
4; Initfile for netCDF file. define all the grid parameters through
5; an appropriate call to <pro>computegrid</pro>
6;
7; @categories
8; Grid
9;
10; @param ncfilein {in}{required}{type=scalar string}
11; A string giving the name of the netCDF file
12;
13; @keyword START1 {default=0}{type=scalar: 0 or 1}
14; Index the axis from 1 instead of 0 when using
15; /xyindex and/or /zindex
16;
17; @keyword ZAXISNAME {default='z', 'level', 'lev', 'depth...'}{type=scalar string}
18; A string giving the name of the variable in the file
19; that contains the [xyz]axis.
20;
21; @keyword XYINDEX {default=0}{type=scalar: 0 or 1}
22; To define the x/y axis with index instead of using
23; the values contained in X/YAXISNAME.
24; x/yaxis = keyword_set(start1) + findgen(jpi/jpj)
25; this forces key_onearth = 0
26;
27; @keyword XMINMESH {default=0L}{type=scalar}
28; Define common (cm_4mesh) variables ixminmesh used to define the localization
29; of the first point of the grid along the x direction in a zoom of the original grid
30;
31; @keyword YMINMESH {default=0L}{type=scalar}
32; Define common (cm_4mesh) variables iyminmesh used to define the localization
33; of the first point of the grid along the y direction in a zoom of the original grid
34;
35; @keyword XMAXMESH {default=jpiglo-1}{type=scalar}
36; Define common (cm_4mesh) variables ixmaxmesh used to define the localization
37; of the last point of the grid along the x direction in a zoom of the original grid
38; Note that if XMAXMESH < 0 then ixmaxmesh is defined as ixmaxmesh = jpiglo -1 + xmaxmesh
39;
40; @keyword YMAXMESH {default=jpjglo-1}{type=scalar}
41; Define common (cm_4mesh) variables iymaxmesh used to define the localization
42; of the last point of the grid along the y direction in a zoom of the original grid
43; Note that if YMAXMESH < 0 then iymaxmesh is defined as iymaxmesh = jpjglo -1 + ymaxmesh
44;
45; @keyword ZINDEX {default=0}{type=scalar: 0 or 1}
46; To define the z axis with index instead of using
47; the values contained in ZAXISNAME.
48; zaxis = keyword_set(start1) + findgen(jpk)
49;
50; @keyword _EXTRA
51; Used to pass keywords to <pro>computegrid</pro>,
52; <pro>ncdf_getaxis</pro>, <pro>ncdf_getmask</pro> and <pro>isafile</pro>
53;
54; @uses
55; <pro>common</pro>
56;
57; @restrictions
58; Change the grid parameters (see <pro>computegrid</pro>)
59;
60; the file must contain an x and an y axis. (1 ou 2 dimensional array)
61;
62; @examples
63;
64;   IDL> initncdf,'toto.nc',glam=[-180,180]
65;
66; @history
67; Sebastien Masson (smasson\@lodyc.jussieu.fr)
68;                      8 May 2002
69;
70; @version
71; $Id$
72;
73;-
74PRO initncdf, ncfilein $
75              , ZAXISNAME=zaxisname, START1=start1 $
76              , XYINDEX=xyindex, ZINDEX=zindex, ABSZ = absz $
77              , _EXTRA=ex
78;
79  compile_opt idl2, strictarrsubs
80;
81@common
82;----------------------------------------------------------
83; check the name of the file
84  ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex)
85  if size(ncfile, /type) NE 7 then BEGIN
86    ras = report( 'initncdf cancelled')
87    return
88  endif
89; if the file is stored on tape
90  if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null'
91;----------------------------------------------------------
92; open the file
93  cdfid = ncdf_open(ncfile)
94; what is inside the file
95  inside = ncdf_inquire(cdfid)
96;----------------------------------------------------------
97; name of the variables
98  namevar = strarr(inside.nvars)
99  for varid = 0, inside.nvars-1 do begin
100    invar = ncdf_varinq(cdfid, varid)
101    namevar[varid] = strlowcase(invar.name)
102  ENDFOR
103;----------------------------------------------------------
104; find the x/yaxis
105 ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $
106               , START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex
107;----------------------------------------------------------
108; find the zaxis
109  IF keyword_set(romsgrid) THEN BEGIN
110    FOR i = 0, inside.ndims-1 DO BEGIN
111      ncdf_diminq, cdfid, i, name, size
112      CASE strlowcase(name) OF
113        's_rho':zaxis = reverse(indgen(size))
114        's_u':zaxis = reverse(indgen(size))
115        's_v':zaxis = reverse(indgen(size))
116        's_psi':zaxis = reverse(indgen(size))
117        's_w':zaxis = reverse(indgen(size-1))
118        ELSE:
119      ENDCASE
120    ENDFOR
121    IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN
122      ncdf_varget, cdfid, 'h', romsh
123    ENDIF ELSE romsh = -1
124  ENDIF ELSE BEGIN
125    if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z'
126    zvarid = (where(namevar EQ 'nav_lev' or namevar EQ zaxisname OR namevar EQ 'level' OR namevar EQ 'lev' OR strmid(namevar, 0, 5) EQ 'depth'))[0]
127    if zvarid EQ -1 AND inside.ndims GT 3 then begin
128      ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...')
129;     stop
130    endif
131; read the zaxis
132    if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis
133  ENDELSE
134  IF keyword_set(zindex) AND keyword_set(zaxis) THEN $
135     zaxis = keyword_set(start1) + findgen(n_elements(zaxis))
136  IF keyword_set(absz) AND n_elements(zaxis) NE 0 THEN zaxis = abs(zaxis)
137;----------------------------------------------------------
138; mask
139  tmask = ncdf_getmask(cdfid, _extra = ex)
140;----------------------------------------------------------
141;
142  ncdf_close, cdfid
143;----------------------------------------------------------
144  IF keyword_set(romsgrid) THEN BEGIN ; remove last column/row
145    sz = size(tmask)
146    nx = sz[1] & ny = sz[2]
147    xaxis = xaxis[0:nx-2, 0:ny-2]
148    yaxis = yaxis[0:nx-2, 0:ny-2]
149    romsh = romsh[0:nx-2, 0:ny-2]
150    CASE sz[0] OF
151      2:tmask = tmask[0:nx-2, 0:ny-2]
152      3:tmask = tmask[0:nx-2, 0:ny-2, *]
153    ENDCASE
154  ENDIF
155;----------------------------------------------------------
156; call compute the grid
157  if NOT keyword_set(zaxis) then BEGIN
158    computegrid, xaxis = xaxis, yaxis = yaxis $
159                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
160  ENDIF ELSE BEGIN
161    computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $
162                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
163  ENDELSE
164  IF n_elements(time) EQ 0 THEN time = 0
165  jpt = n_elements(time)
166;----------------------------------------------------------
167
168  return
169end
Note: See TracBrowser for help on using the repository browser.