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

Last change on this file since 271 was 271, checked in by smasson, 17 years ago

bugfix for interpolation from ORCA2 without mask

  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1;+
2;
3; @file_comments
4; Initfile for Netcdf file. define all the grid parameters through
5; an appropriate call to computegid
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 ZINDEX {default=0}{type=scalar: 0 or 1}
28; To define the z axis with index instead of using
29; the values contained in ZAXISNAME.
30; zaxis = keyword_set(start1) + findgen(jpk)
31;
32; @keyword _EXTRA
33; Used to pass keywords to <pro>computegrid</pro>,
34; <pro>ncdf_getaxis</pro>, <pro>ncdf_getmask</pro> and <pro>isafile</pro>
35;
36; @uses
37; common.pro
38;
39; @restrictions
40; Change the grid parameters (see <pro>computegrid</pro>)
41;
42; @restrictions
43; the file must contain an x and an y axis. (1 ou 2 dimensional array)
44;
45; @examples
46; IDL> initncdf,'toto.nc',glam=[-180,180]
47;
48; @history
49; Sebastien Masson (smasson\@lodyc.jussieu.fr)
50;                      8 May 2002
51;
52; @version
53; $Id$
54;
55;-
56;
57PRO initncdf, ncfilein $
58              , ZAXISNAME = zaxisname, START1 = start1 $
59              , XYINDEX = xyindex, ZINDEX = zindex $
60              , _EXTRA = ex
61;
62  compile_opt idl2, strictarrsubs
63;
64@common
65;----------------------------------------------------------
66; check the name of the file
67  ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex)
68  if size(ncfile, /type) NE 7 then BEGIN
69    ras = report( 'initncdf cancelled')
70    return
71  endif
72; if the file is stored on tape
73  if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null'
74;----------------------------------------------------------
75; open the file
76  cdfid = ncdf_open(ncfile)
77; what is inside the file
78  inside = ncdf_inquire(cdfid)
79;----------------------------------------------------------
80; name of the variables
81  namevar = strarr(inside.nvars)
82  for varid = 0, inside.nvars-1 do begin
83    invar = ncdf_varinq(cdfid, varid)
84    namevar[varid] = strlowcase(invar.name)
85  ENDFOR
86;----------------------------------------------------------
87; find the x/yaxis
88 ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $
89               , START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex
90;----------------------------------------------------------
91; find the zaxis
92  IF keyword_set(romsgrid) THEN BEGIN
93    FOR i = 0, inside.ndims-1 DO BEGIN
94      ncdf_diminq, cdfid, i, name, size
95      CASE strlowcase(name) OF
96        's_rho':zaxis = reverse(indgen(size))
97        's_u':zaxis = reverse(indgen(size))
98        's_v':zaxis = reverse(indgen(size))
99        's_psi':zaxis = reverse(indgen(size))
100        's_w':zaxis = reverse(indgen(size-1))
101        ELSE:
102      ENDCASE
103    ENDFOR
104    IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN
105      ncdf_varget, cdfid, 'h', romsh
106    ENDIF ELSE romsh = -1
107  ENDIF ELSE BEGIN
108    if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z'
109    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]
110    if zvarid EQ -1 AND inside.ndims GT 3 then begin
111      ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you whant to find one...')
112;     stop
113    endif
114; read the zaxis
115    if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis
116  ENDELSE
117  IF keyword_set(zindex) AND keyword_set(zaxis) THEN $
118     zaxis = keyword_set(start1) + findgen(n_elements(zaxis))
119;----------------------------------------------------------
120; mask
121  tmask = ncdf_getmask(cdfid, _extra = ex)
122;----------------------------------------------------------
123;
124  ncdf_close, cdfid
125;
126;----------------------------------------------------------
127; call compute the grid
128  if NOT keyword_set(zaxis) then BEGIN
129    computegrid, xaxis = xaxis, yaxis = yaxis $
130                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
131  ENDIF ELSE BEGIN
132    computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $
133                 , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
134  ENDELSE
135  IF n_elements(time) EQ 0 THEN time = 0
136  jpt = n_elements(time)
137;----------------------------------------------------------
138
139  return
140end
Note: See TracBrowser for help on using the repository browser.