source: trunk/SRC/Grid/micromeshmask.pro @ 103

Last change on this file since 103 was 103, checked in by pinsard, 18 years ago

start to modify headers of Grid .pro files for better idldoc output

  • Property svn:executable set to *
File size: 8.8 KB
Line 
1;+
2;
3; @file_comments reduce the size of the NetCDF meshmask created by OPA by
4; using bit (and not byte) format for the masks and the foat format
5; for the other fields.
6;
7; @categories for OPA meshmask files
8;
9; @examples
10; IDL> reducencmeshmask, ncfilein[, ncfileout]
11;
12; @examples
13;    IDL> meshdir='/d1fes2-raid2/smasson/DATA/ORCA05/'
14;    IDL> micromeshmask, 'meshmask_ORCA_R05.nc',iodir=meshdir
15;
16; @history
17;      July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr)
18;-
19;------------------------------------------------------
20;------------------------------------------------------
21PRO ncdf_transfer, inid, outid, inname, outname
22  IF n_elements(outname) EQ 0 THEN outname = inname
23  ncdf_varget, inid, inname, zzz
24  ncdf_varput, outid, outname, float(reform(zzz, /over))
25  RETURN
26END
27;
28;+
29;    @keyword IODIR to define the files path.
30;      @param ncfilein {in}{required}
31;      1) the name of the meshmask file to be reduced. In that case,
32;      there is only one meshmask file
33;
34;      OR
35;
36;      2) the xxx part in the names: xxx.mesh_hgr.nc xxx.mesh_zgr.nc
37;      xxx.mask.nc. In that case, the meshmask is split into 3 files.
38;
39;      @param ncfileout {in}{required} the name of the uniq reduced meshmask file. default
40;      definition is micromeshmask.nc
41;
42;-
43PRO micromeshmask, ncfilein, ncfileout, IODIR = iodir
44;
45  filein = isafile(FILE = ncfilein, IODIR = iodir, /NEW)
46  test = (findfile(filein))[0]
47  IF test EQ '' THEN BEGIN
48    filein_hgr = (findfile(filein+'.mesh_hgr.nc'))[0]
49    filein_zgr = (findfile(filein+'.mesh_zgr.nc'))[0]
50    filein_msk = (findfile(filein+'.mask.nc'))[0]
51    IF filein_hgr EQ '' OR filein_zgr EQ '' OR filein_msk EQ ''  THEN BEGIN
52      print, 'meshmask file(s) not found...'
53      print, filein+' does not exist'
54      print, filein+'.mesh_hgr.nc does not exist'
55      print, filein+'.mesh_zgr.nc does not exist'
56      print, filein+'.mask.nc does not exist'
57      return
58    ENDIF
59  ENDIF ELSE filein = test
60;------------------------------------------------------
61;------------------------------------------------------
62; get the horizontal dimensions
63  IF n_elements(filein_hgr) NE 0  THEN cdfid = ncdf_open(filein_hgr) $
64  ELSE cdfid = ncdf_open(filein)
65  ncdf_diminq, cdfid, 'x', name, jpi
66  ncdf_diminq, cdfid, 'y', name, jpj
67; for the mask, we use "its byte" representation -> its y dimension
68; will be extended to be a multiple of 8, then it will be divided by
69; 8. -> if (jpj mod 8) eq 0 the jpj_m=jpi/8 else jpj_m=jpi/8 + 1
70  jpj_m = (jpj+7)/8
71; get the vertical dimensions
72  IF n_elements(filein_zgr) NE 0  THEN BEGIN
73    ncdf_close, cdfid
74    cdfid = ncdf_open(filein_zgr)
75  ENDIF
76  listdims = strlowcase(ncdf_listdims(cdfid))
77  IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpk ELSE BEGIN
78    dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0]
79    IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpk ELSE BEGIN
80      report, 'We could not find the vertical dimension..., its name must be z or start with depth'
81      return
82    ENDELSE
83  ENDELSE
84;; get the variables list related to the partial steps
85  varlist_ps = ncdf_listvars(cdfid)
86  varlist_ps = strtrim(strlowcase(varlist_ps), 2)
87;------------------------------------------------------
88;------------------------------------------------------
89;
90;------------------------------------------------------
91; define the output file
92;------------------------------------------------------
93  IF n_elements(ncfileout) EQ 0  THEN ncfileout = 'micromeshmask.nc'
94  cdfidout = ncdf_create(isafile(FILE = ncfileout, IODIR = iodir, /NEW), /clobber)
95  ncdf_control, cdfidout, /nofill
96; dimension
97  dimidx = ncdf_dimdef(cdfidout, 'x', jpi)
98  dimidy = ncdf_dimdef(cdfidout, 'y', jpj)
99  dimidy_m = ncdf_dimdef(cdfidout, 'y_m', jpj_m)
100  dimidz = ncdf_dimdef(cdfidout, 'z', jpk)
101; global attributs
102  ncdf_attput, cdfidout, 'IDL_Program_Name', 'micromeshmask.pro', /GLOBAL
103  ncdf_attput, cdfidout, 'Creation_Date', systime(), /GLOBAL
104; declaration des variables
105  varid = lonarr(20)
106; horizontal variables
107  hgrlist = ['glamt', 'glamu', 'glamv', 'glamf' $
108             , 'gphit', 'gphiu', 'gphiv', 'gphif' $
109             , 'e1t', 'e1u', 'e1v', 'e1f' $
110             , 'e2t', 'e2u', 'e2v', 'e2f']
111  FOR h = 0, n_elements(hgrlist)-1 DO $
112    varid[h] = ncdf_vardef(cdfidout, hgrlist[h], [dimidx, dimidy], /float)
113; vertical variables
114  zgrlist = ['e3t', 'e3w', 'gdept', 'gdepw']
115  FOR z = 0, n_elements(zgrlist)-1 DO $
116    varid[16+z] = ncdf_vardef(cdfidout, zgrlist[z], [dimidz], /float)
117; variables related to the partial steps
118  IF (where(varlist_ps EQ 'hdept'))[0] NE -1 THEN $
119    varid = [varid, ncdf_vardef(cdfidout, 'hdept', [dimidx, dimidy], /float)]
120  IF (where(varlist_ps EQ 'hdepw'))[0] NE -1 THEN $
121    varid = [varid, ncdf_vardef(cdfidout, 'hdepw', [dimidx, dimidy], /float)]
122; old variable name. keep for compatibility with old run. Change e3tp to e3t_ps
123  IF (where(varlist_ps EQ 'e3tp'))[0] NE -1 THEN $
124    varid = [varid, ncdf_vardef(cdfidout, 'e3t_ps', [dimidx, dimidy], /float)]
125; old variable name. keep for compatibility with old run. Change e3wp to e3w_ps
126  IF (where(varlist_ps EQ 'e3wp'))[0] NE -1 THEN $
127    varid = [varid, ncdf_vardef(cdfidout, 'e3w_ps', [dimidx, dimidy], /float)]
128;
129  IF (where(varlist_ps EQ 'e3t_ps'))[0] NE -1 THEN $
130    varid = [varid, ncdf_vardef(cdfidout, 'e3t_ps', [dimidx, dimidy], /float)]
131  IF (where(varlist_ps EQ 'e3w_ps'))[0] NE -1 THEN $
132    varid = [varid, ncdf_vardef(cdfidout, 'e3w_ps', [dimidx, dimidy], /float)]
133;   IF (where(varlist_ps EQ 'e3u_ps'))[0] NE -1 THEN $
134;     varid = [varid, ncdf_vardef(cdfidout, 'e3u_ps', [dimidx, dimidy], /float)]
135;   IF (where(varlist_ps EQ 'e3v_ps'))[0] NE -1 THEN $
136;     varid = [varid, ncdf_vardef(cdfidout, 'e3v_ps', [dimidx, dimidy], /float)]
137; mask variable
138  msklist = ['tmask', 'umask', 'vmask', 'fmask']
139  FOR m = 0, n_elements(msklist)-1 DO BEGIN
140    varid = [varid, ncdf_vardef(cdfidout, msklist[m] $
141                                , [dimidx, dimidy_m, dimidz], /byte)]
142;     ncdf_attput, cdfidout, varid[n_elements(varid)-1] $
143;       , 'Comment', 'the mask is stored as bit. You must use ' $
144;       +'the binary representation of the byte to get back the data.'
145  ENDFOR
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      zzz = byte(temporary(zzz))
204; zzz must contain only 0 or 1
205      zzz = temporary(zzz) MOD 2
206; we transpose zzz because we need to work with the y dimension as the
207; first dimension
208      zzz = transpose(temporary(zzz))
209; extend jpj to be a multiple of 8
210      jpjadd = jpj_m*8-jpj
211      IF jpjadd NE 0 THEN zzz = [temporary(zzz), bytarr(jpjadd, jpi)]
212; reform zzz, to look like output of binary.pro
213      zzz = reform(zzz, 8, 1, jpj_m, jpi, /over)
214; convert into "its byte form"
215      zzz = inverse_binary(temporary(zzz))
216      ncdf_varput, cdfidout, msklist[m], transpose(temporary(zzz)) $
217        , offset = [0, 0, k], count = [jpi, jpj_m, 1]
218    ENDFOR
219  ENDFOR
220;------------------------------------------------------
221;------------------------------------------------------
222  ncdf_close, cdfid
223  ncdf_close, cdfidout
224
225  RETURN
226END
Note: See TracBrowser for help on using the repository browser.