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

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

bugfix for roms

  • Property svn:keywords set to Id
File size: 6.2 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              , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $
76              , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $
77              , ZAXISNAME=zaxisname, START1=start1 $
78              , XYINDEX=xyindex, ZINDEX=zindex $
79              , _EXTRA=ex
80;
81  compile_opt idl2, strictarrsubs
82;
83@common
84;----------------------------------------------------------
85; check the name of the file
86  ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex)
87  if size(ncfile, /type) NE 7 then BEGIN
88    ras = report( 'initncdf cancelled')
89    return
90  endif
91; if the file is stored on tape
92  if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null'
93;----------------------------------------------------------
94; open the file
95  cdfid = ncdf_open(ncfile)
96; what is inside the file
97  inside = ncdf_inquire(cdfid)
98;----------------------------------------------------------
99; name of the variables
100  namevar = strarr(inside.nvars)
101  for varid = 0, inside.nvars-1 do begin
102    invar = ncdf_varinq(cdfid, varid)
103    namevar[varid] = strlowcase(invar.name)
104  ENDFOR
105;----------------------------------------------------------
106; find the x/yaxis
107 ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $
108               , XMINMESH = xminmesh, XMAXMESH = xmaxmesh $
109               , YMINMESH = yminmesh, YMAXMESH = ymaxmesh $
110               , START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex
111;----------------------------------------------------------
112; find the zaxis
113  IF keyword_set(romsgrid) THEN BEGIN
114    FOR i = 0, inside.ndims-1 DO BEGIN
115      ncdf_diminq, cdfid, i, name, size
116      CASE strlowcase(name) OF
117        's_rho':zaxis = reverse(indgen(size))
118        's_u':zaxis = reverse(indgen(size))
119        's_v':zaxis = reverse(indgen(size))
120        's_psi':zaxis = reverse(indgen(size))
121        's_w':zaxis = reverse(indgen(size-1))
122        ELSE:
123      ENDCASE
124    ENDFOR
125    IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN
126      ncdf_varget, cdfid, 'h', romsh
127    ENDIF ELSE romsh = -1
128  ENDIF ELSE BEGIN
129    if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z'
130    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]
131    if zvarid EQ -1 AND inside.ndims GT 3 then begin
132      ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...')
133;     stop
134    endif
135; read the zaxis
136    if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis
137  ENDELSE
138  IF keyword_set(zindex) AND keyword_set(zaxis) THEN $
139     zaxis = keyword_set(start1) + findgen(n_elements(zaxis))
140;----------------------------------------------------------
141; mask
142  tmask = ncdf_getmask(cdfid, _extra = ex)
143;----------------------------------------------------------
144;
145  ncdf_close, cdfid
146;----------------------------------------------------------
147  IF keyword_set(romsgrid) THEN BEGIN ; remove last column/row
148    sz = size(tmask)
149    nx = sz[1] & ny = sz[2]
150    xaxis = xaxis[0:nx-2, 0:ny-2]
151    yaxis = yaxis[0:nx-2, 0:ny-2]
152    romsh = romsh[0:nx-2, 0:ny-2]
153    CASE sz[0] OF
154      2:tmask = tmask[0:nx-2, 0:ny-2]
155      3:tmask = tmask[0:nx-2, 0:ny-2, *]
156    ENDCASE
157  ENDIF
158;----------------------------------------------------------
159; call compute the grid
160  if NOT keyword_set(zaxis) then BEGIN
161    computegrid, xaxis = xaxis, yaxis = yaxis $
162                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
163  ENDIF ELSE BEGIN
164    computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $
165                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
166  ENDELSE
167  IF n_elements(time) EQ 0 THEN time = 0
168  jpt = n_elements(time)
169;----------------------------------------------------------
170
171  return
172end
Note: See TracBrowser for help on using the repository browser.