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