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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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