1 | ;+ |
---|
2 | ; |
---|
3 | ; |
---|
4 | ; @categories for OPA meshmask files |
---|
5 | ; |
---|
6 | ; @param inid {in}{required} |
---|
7 | ; @param outid {in}{required} |
---|
8 | ; @param inname {in}{required} |
---|
9 | ; @param outname {in}{optional} |
---|
10 | ; |
---|
11 | ; @history |
---|
12 | ; July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
13 | ; |
---|
14 | ; @version $Id$ |
---|
15 | ; |
---|
16 | ;- |
---|
17 | ;------------------------------------------------------ |
---|
18 | ;------------------------------------------------------ |
---|
19 | PRO ncdf_transfer, inid, outid, inname, outname |
---|
20 | ; |
---|
21 | compile_opt idl2, strictarrsubs |
---|
22 | ; |
---|
23 | IF n_elements(outname) EQ 0 THEN outname = inname |
---|
24 | ncdf_varget, inid, inname, zzz |
---|
25 | ncdf_varput, outid, outname, float(reform(zzz, /over)) |
---|
26 | RETURN |
---|
27 | END |
---|
28 | ; |
---|
29 | ;+ |
---|
30 | ; @file_comments reduce the size of the NetCDF meshmask created by OPA by |
---|
31 | ; using byte format for the masks and the float format for the other |
---|
32 | ; fields. |
---|
33 | ; |
---|
34 | ; @keyword IODIR to define the files path. |
---|
35 | ; @param ncfilein {in}{required} |
---|
36 | ; 1) the name of the meshmask file to be reduced. In that case, |
---|
37 | ; there is only one meshmask file |
---|
38 | ; |
---|
39 | ; OR |
---|
40 | ; |
---|
41 | ; 2) the xxx part in the names: xxx.mesh_hgr.nc xxx.mesh_zgr.nc |
---|
42 | ; xxx.mask.nc. In that case, the meshmask is split into 3 files. |
---|
43 | ; |
---|
44 | ; @param ncfileout {in}{optional}{default=smallmeshmask.nc} |
---|
45 | ; the name of the reduced meshmask file. |
---|
46 | ; |
---|
47 | ; @examples |
---|
48 | ; IDL> meshdir='/d1fes2-raid2/smasson/DATA/ORCA05/' |
---|
49 | ; IDL> smallmeshmask, 'meshmask_ORCA_R05.nc',iodir=meshdir |
---|
50 | ; |
---|
51 | ; @categories for OPA meshmask files |
---|
52 | ; |
---|
53 | ; @history |
---|
54 | ; July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
55 | ; |
---|
56 | ; @version $Id$ |
---|
57 | ; |
---|
58 | ;- |
---|
59 | PRO smallmeshmask, ncfilein, ncfileout, IODIR = iodir |
---|
60 | ; |
---|
61 | ; |
---|
62 | compile_opt idl2, strictarrsubs |
---|
63 | ; |
---|
64 | filein = isafile(FILE = ncfilein, IODIR = iodir, /NEW) |
---|
65 | test = (findfile(filein))[0] |
---|
66 | IF test EQ '' THEN BEGIN |
---|
67 | filein_hgr = (findfile(filein+'.mesh_hgr.nc'))[0] |
---|
68 | filein_zgr = (findfile(filein+'.mesh_zgr.nc'))[0] |
---|
69 | filein_msk = (findfile(filein+'.mask.nc'))[0] |
---|
70 | IF filein_hgr EQ '' OR filein_zgr EQ '' OR filein_msk EQ '' THEN BEGIN |
---|
71 | print, 'meshmask file(s) not found...' |
---|
72 | print, filein+' does not exist' |
---|
73 | print, filein+'.mesh_hgr.nc does not exist' |
---|
74 | print, filein+'.mesh_zgr.nc does not exist' |
---|
75 | print, filein+'.mask.nc does not exist' |
---|
76 | return |
---|
77 | ENDIF |
---|
78 | ENDIF ELSE filein = test |
---|
79 | ;------------------------------------------------------ |
---|
80 | ;------------------------------------------------------ |
---|
81 | ; get the horizontal dimensions |
---|
82 | IF n_elements(filein_hgr) NE 0 THEN cdfid = ncdf_open(filein_hgr) $ |
---|
83 | ELSE cdfid = ncdf_open(filein) |
---|
84 | ncdf_diminq, cdfid, 'x', name, jpi |
---|
85 | ncdf_diminq, cdfid, 'y', name, jpj |
---|
86 | ; get the vertical dimensions |
---|
87 | IF n_elements(filein_zgr) NE 0 THEN BEGIN |
---|
88 | ncdf_close, cdfid |
---|
89 | cdfid = ncdf_open(filein_zgr) |
---|
90 | ENDIF |
---|
91 | listdims = strlowcase(ncdf_listdims(cdfid)) |
---|
92 | IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpk ELSE BEGIN |
---|
93 | dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0] |
---|
94 | IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpk ELSE BEGIN |
---|
95 | dummy = report('We could not find the vertical dimension..., its name must be z or start with depth') |
---|
96 | return |
---|
97 | ENDELSE |
---|
98 | ENDELSE |
---|
99 | ; get the variables list related to the partial steps |
---|
100 | varlist_ps = ncdf_listvars(cdfid) |
---|
101 | varlist_ps = strtrim(strlowcase(varlist_ps), 2) |
---|
102 | ;------------------------------------------------------ |
---|
103 | ;------------------------------------------------------ |
---|
104 | ; |
---|
105 | ;------------------------------------------------------ |
---|
106 | ; define the output file |
---|
107 | ;------------------------------------------------------ |
---|
108 | IF n_elements(ncfileout) EQ 0 THEN ncfileout = 'smallmeshmask.nc' |
---|
109 | |
---|
110 | cdfidout = ncdf_create(isafile(FILE = ncfileout, IODIR = iodir, /NEW), /clobber) |
---|
111 | ncdf_control, cdfidout, /nofill |
---|
112 | ; dimension |
---|
113 | dimidx = ncdf_dimdef(cdfidout, 'x', jpi) |
---|
114 | dimidy = ncdf_dimdef(cdfidout, 'y', jpj) |
---|
115 | dimidz = ncdf_dimdef(cdfidout, 'z', jpk) |
---|
116 | ; global attributs |
---|
117 | ncdf_attput, cdfidout, 'IDL_Program_Name', 'smallmeshmask.pro', /GLOBAL |
---|
118 | ncdf_attput, cdfidout, 'Creation_Date', systime(), /GLOBAL |
---|
119 | ; declaration des variables |
---|
120 | varid = lonarr(20) |
---|
121 | ; horizontal variables |
---|
122 | hgrlist = ['glamt', 'glamu', 'glamv', 'glamf' $ |
---|
123 | , 'gphit', 'gphiu', 'gphiv', 'gphif' $ |
---|
124 | , 'e1t', 'e1u', 'e1v', 'e1f' $ |
---|
125 | , 'e2t', 'e2u', 'e2v', 'e2f'] |
---|
126 | FOR h = 0, n_elements(hgrlist)-1 DO $ |
---|
127 | varid[h] = ncdf_vardef(cdfidout, hgrlist[h], [dimidx, dimidy], /float) |
---|
128 | ; vertical variables |
---|
129 | zgrlist = ['e3t', 'e3w', 'gdept', 'gdepw'] |
---|
130 | FOR z = 0, n_elements(zgrlist)-1 DO $ |
---|
131 | varid[16+z] = ncdf_vardef(cdfidout, zgrlist[z], [dimidz], /float) |
---|
132 | ; variables related to the partial steps |
---|
133 | IF (where(varlist_ps EQ 'hdept'))[0] NE -1 THEN $ |
---|
134 | varid = [varid, ncdf_vardef(cdfidout, 'hdept', [dimidx, dimidy], /float)] |
---|
135 | IF (where(varlist_ps EQ 'hdepw'))[0] NE -1 THEN $ |
---|
136 | varid = [varid, ncdf_vardef(cdfidout, 'hdepw', [dimidx, dimidy], /float)] |
---|
137 | ; old variable name. keep for compatibility with old run. Change e3tp to e3t_ps |
---|
138 | IF (where(varlist_ps EQ 'e3tp'))[0] NE -1 THEN $ |
---|
139 | varid = [varid, ncdf_vardef(cdfidout, 'e3t_ps', [dimidx, dimidy], /float)] |
---|
140 | ; old variable name. keep for compatibility with old run. Change e3wp to e3w_ps |
---|
141 | IF (where(varlist_ps EQ 'e3wp'))[0] NE -1 THEN $ |
---|
142 | varid = [varid, ncdf_vardef(cdfidout, 'e3w_ps', [dimidx, dimidy], /float)] |
---|
143 | ; |
---|
144 | IF (where(varlist_ps EQ 'e3t_ps'))[0] NE -1 THEN $ |
---|
145 | varid = [varid, ncdf_vardef(cdfidout, 'e3t_ps', [dimidx, dimidy], /float)] |
---|
146 | IF (where(varlist_ps EQ 'e3w_ps'))[0] NE -1 THEN $ |
---|
147 | varid = [varid, ncdf_vardef(cdfidout, 'e3w_ps', [dimidx, dimidy], /float)] |
---|
148 | ; IF (where(varlist_ps EQ 'e3u_ps'))[0] NE -1 THEN $ |
---|
149 | ; varid = [varid, ncdf_vardef(cdfidout, 'e3u_ps', [dimidx, dimidy], /float)] |
---|
150 | ; IF (where(varlist_ps EQ 'e3v_ps'))[0] NE -1 THEN $ |
---|
151 | ; varid = [varid, ncdf_vardef(cdfidout, 'e3v_ps', [dimidx, dimidy], /float)] |
---|
152 | ; mask variable |
---|
153 | msklist = ['tmask', 'umask', 'vmask', 'fmask'] |
---|
154 | FOR m = 0, n_elements(msklist)-1 DO $ |
---|
155 | varid = [varid, ncdf_vardef(cdfidout, msklist[m] $ |
---|
156 | , [dimidx, dimidy, dimidz], /byte)] |
---|
157 | ;------------------------------------------------------ |
---|
158 | ;------------------------------------------------------ |
---|
159 | ncdf_control, cdfidout, /endef |
---|
160 | ;------------------------------------------------------ |
---|
161 | ; |
---|
162 | ; get the horizontal variables |
---|
163 | ; |
---|
164 | IF n_elements(filein_hgr) NE 0 THEN BEGIN |
---|
165 | ncdf_close, cdfid |
---|
166 | cdfid = ncdf_open(filein_hgr) |
---|
167 | ENDIF |
---|
168 | ; |
---|
169 | FOR h = 0, n_elements(hgrlist)-1 DO $ |
---|
170 | ncdf_transfer, cdfid, cdfidout, hgrlist[h] |
---|
171 | ; |
---|
172 | ; get the vertical variables |
---|
173 | ; |
---|
174 | IF n_elements(filein_zgr) NE 0 THEN BEGIN |
---|
175 | ncdf_close, cdfid |
---|
176 | cdfid = ncdf_open(filein_zgr) |
---|
177 | ENDIF |
---|
178 | ; |
---|
179 | FOR z = 0, n_elements(zgrlist)-1 DO $ |
---|
180 | ncdf_transfer, cdfid, cdfidout, zgrlist[z] |
---|
181 | ; partial step variables |
---|
182 | IF (where(varlist_ps EQ 'hdept'))[0] NE -1 THEN $ |
---|
183 | ncdf_transfer, cdfid, cdfidout, 'hdept' |
---|
184 | IF (where(varlist_ps EQ 'hdepw'))[0] NE -1 THEN $ |
---|
185 | ncdf_transfer, cdfid, cdfidout, 'hdepw' |
---|
186 | IF (where(varlist_ps EQ 'e3tp'))[0] NE -1 THEN $ |
---|
187 | ncdf_transfer, cdfid, cdfidout, 'e3tp', 'e3t_ps' |
---|
188 | IF (where(varlist_ps EQ 'e3wp'))[0] NE -1 THEN $ |
---|
189 | ncdf_transfer, cdfid, cdfidout, 'e3wp', 'e3w_ps' |
---|
190 | IF (where(varlist_ps EQ 'e3t_ps'))[0] NE -1 THEN $ |
---|
191 | ncdf_transfer, cdfid, cdfidout, 'e3t_ps' |
---|
192 | IF (where(varlist_ps EQ 'e3w_ps'))[0] NE -1 THEN $ |
---|
193 | ncdf_transfer, cdfid, cdfidout, 'e3w_ps' |
---|
194 | ; IF (where(varlist_ps EQ 'e3u_ps'))[0] NE -1 THEN $ |
---|
195 | ; ncdf_transfer, cdfid, cdfidout, 'e3u_ps' |
---|
196 | ; IF (where(varlist_ps EQ 'e3v_ps'))[0] NE -1 THEN $ |
---|
197 | ; ncdf_transfer, cdfid, cdfidout, 'e3v_ps' |
---|
198 | ; |
---|
199 | ; mask |
---|
200 | ; |
---|
201 | IF n_elements(filein_msk) NE 0 THEN BEGIN |
---|
202 | ncdf_close, cdfid |
---|
203 | cdfid = ncdf_open(filein_msk) |
---|
204 | ENDIF |
---|
205 | ; loop on the vertical levels to limit the memory use |
---|
206 | FOR k = 0, jpk-1 DO BEGIN |
---|
207 | FOR m = 0, 3 DO BEGIN |
---|
208 | CASE (ncdf_varinq(cdfid, msklist[m])).ndims OF |
---|
209 | 3:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k] $ |
---|
210 | , count = [jpi, jpj, 1] |
---|
211 | 4:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k, 0] $ |
---|
212 | , count = [jpi, jpj, 1, 1] |
---|
213 | ENDCASE |
---|
214 | ncdf_varput, cdfidout, msklist[m], byte(temporary(zzz)) $ |
---|
215 | , offset = [0, 0, k], count = [jpi, jpj, 1] |
---|
216 | ENDFOR |
---|
217 | ENDFOR |
---|
218 | ;------------------------------------------------------ |
---|
219 | ;------------------------------------------------------ |
---|
220 | ncdf_close, cdfid |
---|
221 | ncdf_close, cdfidout |
---|
222 | |
---|
223 | RETURN |
---|
224 | END |
---|