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

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

some light header cleaning...

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