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 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 | ; <pro>common</pro> |
---|
38 | ; |
---|
39 | ; @restrictions |
---|
40 | ; Change the grid parameters (see <pro>computegrid</pro>) |
---|
41 | ; |
---|
42 | ; the file must contain an x and an y axis. (1 ou 2 dimensional array) |
---|
43 | ; |
---|
44 | ; @examples |
---|
45 | ; |
---|
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 | PRO initncdf, ncfilein $ |
---|
57 | , ZAXISNAME=zaxisname, START1=start1 $ |
---|
58 | , XYINDEX=xyindex, ZINDEX=zindex $ |
---|
59 | , _EXTRA=ex |
---|
60 | ; |
---|
61 | compile_opt idl2, strictarrsubs |
---|
62 | ; |
---|
63 | @common |
---|
64 | ;---------------------------------------------------------- |
---|
65 | ; check the name of the file |
---|
66 | ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex) |
---|
67 | if size(ncfile, /type) NE 7 then BEGIN |
---|
68 | ras = report( 'initncdf cancelled') |
---|
69 | return |
---|
70 | endif |
---|
71 | ; if the file is stored on tape |
---|
72 | if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null' |
---|
73 | ;---------------------------------------------------------- |
---|
74 | ; open the file |
---|
75 | cdfid = ncdf_open(ncfile) |
---|
76 | ; what is inside the file |
---|
77 | inside = ncdf_inquire(cdfid) |
---|
78 | ;---------------------------------------------------------- |
---|
79 | ; name of the variables |
---|
80 | namevar = strarr(inside.nvars) |
---|
81 | for varid = 0, inside.nvars-1 do begin |
---|
82 | invar = ncdf_varinq(cdfid, varid) |
---|
83 | namevar[varid] = strlowcase(invar.name) |
---|
84 | ENDFOR |
---|
85 | ;---------------------------------------------------------- |
---|
86 | ; find the x/yaxis |
---|
87 | ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $ |
---|
88 | , START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex |
---|
89 | ;---------------------------------------------------------- |
---|
90 | ; find the zaxis |
---|
91 | IF keyword_set(romsgrid) THEN BEGIN |
---|
92 | FOR i = 0, inside.ndims-1 DO BEGIN |
---|
93 | ncdf_diminq, cdfid, i, name, size |
---|
94 | CASE strlowcase(name) OF |
---|
95 | 's_rho':zaxis = reverse(indgen(size)) |
---|
96 | 's_u':zaxis = reverse(indgen(size)) |
---|
97 | 's_v':zaxis = reverse(indgen(size)) |
---|
98 | 's_psi':zaxis = reverse(indgen(size)) |
---|
99 | 's_w':zaxis = reverse(indgen(size-1)) |
---|
100 | ELSE: |
---|
101 | ENDCASE |
---|
102 | ENDFOR |
---|
103 | IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN |
---|
104 | ncdf_varget, cdfid, 'h', romsh |
---|
105 | ENDIF ELSE romsh = -1 |
---|
106 | ENDIF ELSE BEGIN |
---|
107 | if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z' |
---|
108 | 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] |
---|
109 | if zvarid EQ -1 AND inside.ndims GT 3 then begin |
---|
110 | ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...') |
---|
111 | ; stop |
---|
112 | endif |
---|
113 | ; read the zaxis |
---|
114 | if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis |
---|
115 | ENDELSE |
---|
116 | IF keyword_set(zindex) AND keyword_set(zaxis) THEN $ |
---|
117 | zaxis = keyword_set(start1) + findgen(n_elements(zaxis)) |
---|
118 | ;---------------------------------------------------------- |
---|
119 | ; mask |
---|
120 | tmask = ncdf_getmask(cdfid, _extra = ex) |
---|
121 | ;---------------------------------------------------------- |
---|
122 | ; |
---|
123 | ncdf_close, cdfid |
---|
124 | ; |
---|
125 | ;---------------------------------------------------------- |
---|
126 | ; call compute the grid |
---|
127 | if NOT keyword_set(zaxis) then BEGIN |
---|
128 | computegrid, xaxis = xaxis, yaxis = yaxis $ |
---|
129 | , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex |
---|
130 | ENDIF ELSE BEGIN |
---|
131 | computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $ |
---|
132 | , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex |
---|
133 | ENDELSE |
---|
134 | IF n_elements(time) EQ 0 THEN time = 0 |
---|
135 | jpt = n_elements(time) |
---|
136 | ;---------------------------------------------------------- |
---|
137 | |
---|
138 | return |
---|
139 | end |
---|