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