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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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