source: trunk/SRC/Grid/smallmeshmask.pro @ 302

Last change on this file since 302 was 302, checked in by smasson, 17 years ago

compatibility with new meshmask using gdept_O, ...

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