1 | ;+ |
---|
2 | ; |
---|
3 | ; @categories |
---|
4 | ; For OPA |
---|
5 | ; |
---|
6 | ; @param inid {in}{required} |
---|
7 | ; |
---|
8 | ; @param outid {in}{required} |
---|
9 | ; |
---|
10 | ; @param inname {in}{required} |
---|
11 | ; |
---|
12 | ; @param outname {in}{optional} |
---|
13 | ; |
---|
14 | ; @history |
---|
15 | ; July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
16 | ; |
---|
17 | ; @version |
---|
18 | ; $Id$ |
---|
19 | ; |
---|
20 | ;- |
---|
21 | PRO ncdf_transfer, inid, outid, inname, outname |
---|
22 | ; |
---|
23 | compile_opt idl2, strictarrsubs |
---|
24 | ; |
---|
25 | IF n_elements(outname) EQ 0 THEN outname = inname |
---|
26 | ncdf_varget, inid, inname, zzz |
---|
27 | ncdf_varput, outid, outname, float(reform(zzz, /over)) |
---|
28 | RETURN |
---|
29 | END |
---|
30 | ; |
---|
31 | ;+ |
---|
32 | ; |
---|
33 | ; @file_comments |
---|
34 | ; Reduce the size of the NetCDF meshmask created by OPA by |
---|
35 | ; using byte format for the masks and the float format for the other |
---|
36 | ; fields. |
---|
37 | ; |
---|
38 | ; @keyword IODIR |
---|
39 | ; to define the files path. |
---|
40 | ; |
---|
41 | ; @param ncfilein {in}{required} |
---|
42 | ; 1) the name of the meshmask file to be reduced. In that case, |
---|
43 | ; there is only one meshmask file |
---|
44 | ; |
---|
45 | ; OR |
---|
46 | ; |
---|
47 | ; 2) the xxx part in the names: xxx.mesh_hgr.nc xxx.mesh_zgr.nc |
---|
48 | ; xxx.mask.nc. In that case, the meshmask is split into 3 files. |
---|
49 | ; |
---|
50 | ; @param ncfileout {in}{optional}{default=smallmeshmask.nc} |
---|
51 | ; the name of the reduced meshmask file. |
---|
52 | ; |
---|
53 | ; @examples |
---|
54 | ; |
---|
55 | ; IDL> meshdir='/d1fes2-raid2/smasson/DATA/ORCA05/' |
---|
56 | ; IDL> smallmeshmask, 'meshmask_ORCA_R05.nc',iodir=meshdir |
---|
57 | ; |
---|
58 | ; @categories |
---|
59 | ; For OPA |
---|
60 | ; |
---|
61 | ; @history |
---|
62 | ; July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
63 | ; |
---|
64 | ; @version |
---|
65 | ; $Id$ |
---|
66 | ; |
---|
67 | ;- |
---|
68 | PRO smallmeshmask, ncfilein, ncfileout, IODIR = iodir, HGRFILE = hgrfile, ZGRFILE = zgrfile, MSKFILE = mskfile, USEBATHY = usebathy |
---|
69 | ; |
---|
70 | compile_opt idl2, strictarrsubs |
---|
71 | ; |
---|
72 | filein = isafile(FILE = ncfilein, IODIR = iodir, /NEW) |
---|
73 | test = (file_search(filein))[0] |
---|
74 | IF test EQ '' THEN BEGIN |
---|
75 | IF keyword_set(hgrfile) THEN filein_hgr = isafile(FILE = hgrfile, IODIR = iodir) ELSE filein_hgr = (file_search(filein+'[._]mesh_hgr.nc'))[0] |
---|
76 | IF keyword_set(zgrfile) THEN filein_zgr = isafile(FILE = zgrfile, IODIR = iodir) ELSE filein_zgr = (file_search(filein+'[._]mesh_zgr.nc'))[0] |
---|
77 | IF keyword_set(usebathy) THEN filein_msk = 'not used' ELSE BEGIN |
---|
78 | IF keyword_set(mskfile) THEN filein_msk = isafile(FILE = mskfile, IODIR = iodir) ELSE filein_msk = (file_search(filein+'[._]mask.nc'))[0] |
---|
79 | ENDELSE |
---|
80 | IF filein_hgr EQ '' OR filein_zgr EQ '' OR filein_msk EQ '' THEN BEGIN |
---|
81 | ras = report(['meshmask file(s) not found...', $ |
---|
82 | filein+' does not exist', $ |
---|
83 | filein+'.mesh_hgr.nc does not exist', $ |
---|
84 | filein+'.mesh_zgr.nc does not exist', $ |
---|
85 | filein+'.mask.nc does not exist']) |
---|
86 | return |
---|
87 | ENDIF |
---|
88 | ENDIF ELSE filein = test |
---|
89 | ;------------------------------------------------------ |
---|
90 | ;------------------------------------------------------ |
---|
91 | ; get the horizontal dimensions |
---|
92 | IF n_elements(filein_hgr) NE 0 THEN cdfid = ncdf_open(filein_hgr) $ |
---|
93 | ELSE cdfid = ncdf_open(filein) |
---|
94 | ncdf_diminq, cdfid, 'x', name, jpi |
---|
95 | ncdf_diminq, cdfid, 'y', name, jpj |
---|
96 | ; get the vertical dimensions |
---|
97 | IF n_elements(filein_zgr) NE 0 THEN BEGIN |
---|
98 | ncdf_close, cdfid |
---|
99 | cdfid = ncdf_open(filein_zgr) |
---|
100 | ENDIF |
---|
101 | listdims = strlowcase(ncdf_listdims(cdfid)) |
---|
102 | IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpk ELSE BEGIN |
---|
103 | dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0] |
---|
104 | IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpk ELSE BEGIN |
---|
105 | dummy = report('We could not find the vertical dimension..., its name must be z or start with depth') |
---|
106 | return |
---|
107 | ENDELSE |
---|
108 | ENDELSE |
---|
109 | ; get the variables list related to the partial steps |
---|
110 | zgr_varlist = ncdf_listvars(cdfid) |
---|
111 | zgr_varlist = strtrim(strlowcase(zgr_varlist), 2) |
---|
112 | ; is e3t a real 3D array? |
---|
113 | IF (where(zgr_varlist EQ 'e3t'))[0] NE -1 THEN BEGIN |
---|
114 | varinq = ncdf_varinq(cdfid, 'e3t') |
---|
115 | if varinq.ndims GE 3 THEN BEGIN |
---|
116 | ncdf_diminq, cdfid, varinq.dim[0], name, iii |
---|
117 | ncdf_diminq, cdfid, varinq.dim[1], name, jjj |
---|
118 | ncdf_diminq, cdfid, varinq.dim[2], name, kkk |
---|
119 | IF iii EQ jpi AND jjj EQ jpj AND kkk EQ jpk THEN key_e3_3d = 1 |
---|
120 | ENDIF |
---|
121 | ENDIF |
---|
122 | ; is gdept a real 3D array? |
---|
123 | IF (where(zgr_varlist EQ 'gdept'))[0] NE -1 THEN BEGIN |
---|
124 | varinq = ncdf_varinq(cdfid, 'gdept') |
---|
125 | if varinq.ndims GE 3 THEN BEGIN |
---|
126 | ncdf_diminq, cdfid, varinq.dim[0], name, iii |
---|
127 | ncdf_diminq, cdfid, varinq.dim[1], name, jjj |
---|
128 | ncdf_diminq, cdfid, varinq.dim[2], name, kkk |
---|
129 | IF iii EQ jpi AND jjj EQ jpj AND kkk EQ jpk THEN key_gdep_3d = 1 |
---|
130 | ENDIF |
---|
131 | ENDIF |
---|
132 | ;------------------------------------------------------ |
---|
133 | ; |
---|
134 | ;------------------------------------------------------ |
---|
135 | ; define the output file |
---|
136 | ;------------------------------------------------------ |
---|
137 | IF n_elements(ncfileout) EQ 0 THEN ncfileout = 'smallmeshmask.nc' |
---|
138 | |
---|
139 | cdfidout = ncdf_create(isafile(FILE = ncfileout, IODIR = iodir, /NEW), /clobber) |
---|
140 | ncdf_control, cdfidout, /nofill |
---|
141 | ; dimension |
---|
142 | dimidx = ncdf_dimdef(cdfidout, 'x', jpi) |
---|
143 | dimidy = ncdf_dimdef(cdfidout, 'y', jpj) |
---|
144 | dimidz = ncdf_dimdef(cdfidout, 'z', jpk) |
---|
145 | ; global attributes |
---|
146 | ncdf_attput, cdfidout, 'IDL_Program_Name', 'smallmeshmask.pro', /GLOBAL |
---|
147 | ncdf_attput, cdfidout, 'Creation_Date', systime(), /GLOBAL |
---|
148 | ; declaration des variables |
---|
149 | varid = lonarr(20) |
---|
150 | ; horizontal variables |
---|
151 | hgrlist = ['glamt', 'glamu', 'glamv', 'glamf' $ |
---|
152 | , 'gphit', 'gphiu', 'gphiv', 'gphif' $ |
---|
153 | , 'e1t', 'e1u', 'e1v', 'e1f' $ |
---|
154 | , 'e2t', 'e2u', 'e2v', 'e2f'] |
---|
155 | FOR h = 0, n_elements(hgrlist)-1 DO $ |
---|
156 | varid[h] = ncdf_vardef(cdfidout, hgrlist[h], [dimidx, dimidy], /float) |
---|
157 | ; vertical variables |
---|
158 | zgrlist = ['e3t', 'e3w', 'gdept', 'gdepw'] |
---|
159 | FOR z = 0, n_elements(zgrlist)-1 DO $ |
---|
160 | varid[16+z] = ncdf_vardef(cdfidout, zgrlist[z], [dimidz], /float) |
---|
161 | ; variables related to the partial steps |
---|
162 | with_partial = keyword_set(key_e3_3d) OR (where(zgr_varlist EQ 'hdept'))[0] NE -1 $ |
---|
163 | OR (where(zgr_varlist EQ 'e3tp'))[0] NE -1 $ |
---|
164 | OR (where(zgr_varlist EQ 'e3t_ps'))[0] NE -1 |
---|
165 | IF with_partial THEN BEGIN |
---|
166 | varid = [varid, ncdf_vardef(cdfidout, 'hdept', [dimidx, dimidy], /float)] |
---|
167 | varid = [varid, ncdf_vardef(cdfidout, 'hdepw', [dimidx, dimidy], /float)] |
---|
168 | varid = [varid, ncdf_vardef(cdfidout, 'e3t_ps', [dimidx, dimidy], /float)] |
---|
169 | varid = [varid, ncdf_vardef(cdfidout, 'e3w_ps', [dimidx, dimidy], /float)] |
---|
170 | ENDIF |
---|
171 | ; |
---|
172 | IF (where(zgr_varlist EQ 'mbathy'))[0] NE -1 THEN $ |
---|
173 | varid = [varid, ncdf_vardef(cdfidout, 'mbathy', [dimidx, dimidy], /short)] |
---|
174 | ; mask variable |
---|
175 | IF keyword_set(usebathy) THEN msklist = ['tmask'] ELSE msklist = ['tmask', 'umask', 'vmask', 'fmask'] |
---|
176 | FOR m = 0, n_elements(msklist)-1 DO $ |
---|
177 | varid = [varid, ncdf_vardef(cdfidout, msklist[m], [dimidx, dimidy, dimidz], /byte)] |
---|
178 | ;------------------------------------------------------ |
---|
179 | ;------------------------------------------------------ |
---|
180 | ncdf_control, cdfidout, /endef |
---|
181 | ;------------------------------------------------------ |
---|
182 | ; |
---|
183 | ; get the horizontal variables |
---|
184 | ; |
---|
185 | IF n_elements(filein_hgr) NE 0 THEN BEGIN |
---|
186 | ncdf_close, cdfid |
---|
187 | cdfid = ncdf_open(filein_hgr) |
---|
188 | ENDIF |
---|
189 | ; |
---|
190 | FOR h = 0, n_elements(hgrlist)-1 DO $ |
---|
191 | ncdf_transfer, cdfid, cdfidout, hgrlist[h] |
---|
192 | ; |
---|
193 | ; get the vertical variables |
---|
194 | ; |
---|
195 | IF n_elements(filein_zgr) NE 0 THEN BEGIN |
---|
196 | ncdf_close, cdfid |
---|
197 | cdfid = ncdf_open(filein_zgr) |
---|
198 | ENDIF |
---|
199 | ; |
---|
200 | inzgrlist = zgrlist |
---|
201 | IF (where(zgr_varlist EQ 'gdept_0'))[0] NE -1 THEN inzgrlist = inzgrlist+'_0' |
---|
202 | FOR z = 0, n_elements(zgrlist)-1 DO ncdf_transfer, cdfid, cdfidout, inzgrlist[z], zgrlist[z] |
---|
203 | ; partial step variables |
---|
204 | IF (where(zgr_varlist EQ 'hdept' ))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'hdept' |
---|
205 | IF (where(zgr_varlist EQ 'hdepw' ))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'hdepw' |
---|
206 | IF (where(zgr_varlist EQ 'e3tp' ))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'e3tp', 'e3t_ps' |
---|
207 | IF (where(zgr_varlist EQ 'e3wp' ))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'e3wp', 'e3w_ps' |
---|
208 | IF (where(zgr_varlist EQ 'e3t_ps'))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'e3t_ps' |
---|
209 | IF (where(zgr_varlist EQ 'e3w_ps'))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'e3w_ps' |
---|
210 | IF (where(zgr_varlist EQ 'mbathy'))[0] NE -1 THEN ncdf_transfer, cdfid, cdfidout, 'mbathy' |
---|
211 | ; |
---|
212 | bat = -1 |
---|
213 | IF keyword_set(key_e3_3d) THEN BEGIN |
---|
214 | ; get the bottom |
---|
215 | CASE (ncdf_varinq(cdfid, 'mbathy')).ndims OF |
---|
216 | 2:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj] |
---|
217 | 3:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1] |
---|
218 | 4:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1, 1] |
---|
219 | ENDCASE |
---|
220 | bottom = 0L > ( long(bat) - 1L ) |
---|
221 | bottom = lindgen(jpi, jpj) + jpi*jpj*temporary(bottom) |
---|
222 | ; |
---|
223 | CASE (ncdf_varinq(cdfid, 'e3t')).ndims OF |
---|
224 | 3:ncdf_varget, cdfid, 'e3t', res, count = [jpi, jpj, jpk] |
---|
225 | 4:ncdf_varget, cdfid, 'e3t', res, count = [jpi, jpj, jpk, 1] |
---|
226 | ENDCASE |
---|
227 | ncdf_varput, cdfidout, 'e3t_ps', (temporary(res))[bottom] * (bat NE 0L) |
---|
228 | ; |
---|
229 | CASE (ncdf_varinq(cdfid, 'e3w')).ndims OF |
---|
230 | 3:ncdf_varget, cdfid, 'e3w', res, count = [jpi, jpj, jpk] |
---|
231 | 4:ncdf_varget, cdfid, 'e3w', res, count = [jpi, jpj, jpk, 1] |
---|
232 | ENDCASE |
---|
233 | ncdf_varput, cdfidout, 'e3w_ps', (temporary(res))[bottom] * (bat NE 0L) |
---|
234 | ENDIF |
---|
235 | ; |
---|
236 | IF keyword_set(key_gdep_3d) THEN BEGIN |
---|
237 | ; get the bottom |
---|
238 | IF bat[0] EQ -1 THEN BEGIN |
---|
239 | CASE (ncdf_varinq(cdfid, 'mbathy')).ndims OF |
---|
240 | 2:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj] |
---|
241 | 3:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1] |
---|
242 | 4:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1, 1] |
---|
243 | ENDCASE |
---|
244 | ENDIF |
---|
245 | bottom = 0L > ( long(bat) - 1L ) |
---|
246 | bottom = lindgen(jpi, jpj) + jpi*jpj*temporary(bottom) |
---|
247 | ; |
---|
248 | CASE (ncdf_varinq(cdfid, 'gdept')).ndims OF |
---|
249 | 3:ncdf_varget, cdfid, 'gdept', res, count = [jpi, jpj, jpk] |
---|
250 | 4:ncdf_varget, cdfid, 'gdept', res, count = [jpi, jpj, jpk, 1] |
---|
251 | ENDCASE |
---|
252 | ncdf_varput, cdfidout, 'hdept', (temporary(res))[bottom] * (bat NE 0L) |
---|
253 | ; |
---|
254 | bottom = jpi*jpj + temporary(bottom) |
---|
255 | CASE (ncdf_varinq(cdfid, 'gdepw')).ndims OF |
---|
256 | 3:ncdf_varget, cdfid, 'gdepw', res, count = [jpi, jpj, jpk] |
---|
257 | 4:ncdf_varget, cdfid, 'gdepw', res, count = [jpi, jpj, jpk, 1] |
---|
258 | ENDCASE |
---|
259 | ncdf_varput, cdfidout, 'hdepw', (temporary(res))[bottom] * (bat NE 0L) |
---|
260 | ENDIF |
---|
261 | ; |
---|
262 | ; mask |
---|
263 | ; |
---|
264 | IF keyword_set(usebathy) THEN BEGIN |
---|
265 | IF bat[0] EQ -1 THEN BEGIN |
---|
266 | CASE (ncdf_varinq(cdfid, 'mbathy')).ndims OF |
---|
267 | 2:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj] |
---|
268 | 3:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1] |
---|
269 | 4:ncdf_varget, cdfid, 'mbathy', bat, count = [jpi, jpj, 1, 1] |
---|
270 | ENDCASE |
---|
271 | ENDIF |
---|
272 | FOR k = 0, jpk-1 DO BEGIN |
---|
273 | zz = bat GT k |
---|
274 | ncdf_varput, cdfidout, 'tmask', temporary(zz), offset = [0, 0, k], count = [jpi, jpj, 1] |
---|
275 | ENDFOR |
---|
276 | ENDIF ELSE BEGIN |
---|
277 | IF n_elements(filein_msk) NE 0 THEN BEGIN |
---|
278 | ncdf_close, cdfid |
---|
279 | cdfid = ncdf_open(filein_msk) |
---|
280 | ENDIF |
---|
281 | ; loop on the vertical levels to limit the memory use |
---|
282 | FOR k = 0, jpk-1 DO BEGIN |
---|
283 | FOR m = 0, n_elements(msklist)-1 DO BEGIN |
---|
284 | CASE (ncdf_varinq(cdfid, msklist[m])).ndims OF |
---|
285 | 3:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k ], count = [jpi, jpj, 1] |
---|
286 | 4:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k, 0], count = [jpi, jpj, 1, 1] |
---|
287 | ENDCASE |
---|
288 | ncdf_varput, cdfidout, msklist[m], byte(temporary(zzz)), offset = [0, 0, k], count = [jpi, jpj, 1] |
---|
289 | ENDFOR |
---|
290 | ENDFOR |
---|
291 | ENDELSE |
---|
292 | ;------------------------------------------------------ |
---|
293 | ;------------------------------------------------------ |
---|
294 | ncdf_close, cdfid |
---|
295 | ncdf_close, cdfidout |
---|
296 | |
---|
297 | RETURN |
---|
298 | END |
---|