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

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

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