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

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

add $ in Calendar, Grid, Interpolation, Obsolete and Postscript *.pro files, add svn:keywords Id to all these files, some improvements in header

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.0 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 float format
5; for the other fields.
6;
7; @categories for OPA meshmask files
8;
9; @param inid {in}{required}
10; @param outid {in}{required}
11; @param inname {in}{required}
12; @param outname {in}{optional}
13;
14; @history
15;      July 2004 Sebastien Masson (smasson\@lodyc.jussieu.fr)
16;
17; @version $Id$
18;
19;-
20;------------------------------------------------------
21;------------------------------------------------------
22PRO ncdf_transfer, inid, outid, inname, outname
23;
24  compile_opt idl2, strictarrsubs
25;
26  IF n_elements(outname) EQ 0 THEN outname = inname
27  ncdf_varget, inid, inname, zzz
28  ncdf_varput, outid, outname, float(reform(zzz, /over))
29  RETURN
30END
31;
32;+
33;
34;      @param ncfilein {in}{required}
35;      1) the name of the meshmask file to be reduced. In that case,
36;      there is only one meshmask file
37;
38;      OR
39;
40;      2) the xxx part in the names: xxx.mesh_hgr.nc xxx.mesh_zgr.nc
41;      xxx.mask.nc. In that case, the meshmask is split into 3 files.
42;
43; @param ncfileout {in}{optional} the name of the uniq reduced meshmask file.
44; default definition is micromeshmask.nc
45;
46; @keyword IODIR to define the files path.
47;
48; @examples
49; IDL> meshdir='/d1fes2-raid2/smasson/DATA/ORCA05/'
50; IDL> micromeshmask, 'meshmask_ORCA_R05.nc',iodir=meshdir
51;
52;-
53PRO micromeshmask, ncfilein, ncfileout, IODIR = iodir
54;
55  compile_opt idl2, strictarrsubs
56;
57  filein = isafile(FILE = ncfilein, IODIR = iodir, /NEW)
58  test = (findfile(filein))[0]
59  IF test EQ '' THEN BEGIN
60    filein_hgr = (findfile(filein+'.mesh_hgr.nc'))[0]
61    filein_zgr = (findfile(filein+'.mesh_zgr.nc'))[0]
62    filein_msk = (findfile(filein+'.mask.nc'))[0]
63    IF filein_hgr EQ '' OR filein_zgr EQ '' OR filein_msk EQ ''  THEN BEGIN
64      print, 'meshmask file(s) not found...'
65      print, filein+' does not exist'
66      print, filein+'.mesh_hgr.nc does not exist'
67      print, filein+'.mesh_zgr.nc does not exist'
68      print, filein+'.mask.nc does not exist'
69      return
70    ENDIF
71  ENDIF ELSE filein = test
72;------------------------------------------------------
73;------------------------------------------------------
74; get the horizontal dimensions
75  IF n_elements(filein_hgr) NE 0  THEN cdfid = ncdf_open(filein_hgr) $
76  ELSE cdfid = ncdf_open(filein)
77  ncdf_diminq, cdfid, 'x', name, jpi
78  ncdf_diminq, cdfid, 'y', name, jpj
79; for the mask, we use "its byte" representation -> its y dimension
80; will be extended to be a multiple of 8, then it will be divided by
81; 8. -> if (jpj mod 8) eq 0 the jpj_m=jpi/8 else jpj_m=jpi/8 + 1
82  jpj_m = (jpj+7)/8
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 = 'micromeshmask.nc'
106  cdfidout = ncdf_create(isafile(FILE = ncfileout, IODIR = iodir, /NEW), /clobber)
107  ncdf_control, cdfidout, /nofill
108; dimension
109  dimidx = ncdf_dimdef(cdfidout, 'x', jpi)
110  dimidy = ncdf_dimdef(cdfidout, 'y', jpj)
111  dimidy_m = ncdf_dimdef(cdfidout, 'y_m', jpj_m)
112  dimidz = ncdf_dimdef(cdfidout, 'z', jpk)
113; global attributs
114  ncdf_attput, cdfidout, 'IDL_Program_Name', 'micromeshmask.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 BEGIN
152    varid = [varid, ncdf_vardef(cdfidout, msklist[m] $
153                                , [dimidx, dimidy_m, dimidz], /byte)]
154;     ncdf_attput, cdfidout, varid[n_elements(varid)-1] $
155;       , 'Comment', 'the mask is stored as bit. You must use ' $
156;       +'the binary representation of the byte to get back the data.'
157  ENDFOR
158;------------------------------------------------------
159;------------------------------------------------------
160  ncdf_control, cdfidout, /endef
161;------------------------------------------------------
162;
163; get the horizontal variables
164;
165  IF n_elements(filein_hgr) NE 0  THEN BEGIN
166    ncdf_close, cdfid
167    cdfid = ncdf_open(filein_hgr)
168  ENDIF
169;
170  FOR h = 0, n_elements(hgrlist)-1 DO $
171    ncdf_transfer, cdfid, cdfidout, hgrlist[h]
172;
173; get the vertical variables
174;
175  IF n_elements(filein_zgr) NE 0  THEN BEGIN
176    ncdf_close, cdfid
177    cdfid = ncdf_open(filein_zgr)
178  ENDIF
179;
180  FOR z = 0, n_elements(zgrlist)-1 DO $
181    ncdf_transfer, cdfid, cdfidout, zgrlist[z]
182; partial step variables
183  IF (where(varlist_ps EQ 'hdept'))[0] NE -1 THEN $
184    ncdf_transfer, cdfid, cdfidout, 'hdept'
185  IF (where(varlist_ps EQ 'hdepw'))[0] NE -1 THEN $
186    ncdf_transfer, cdfid, cdfidout, 'hdepw'
187  IF (where(varlist_ps EQ 'e3tp'))[0] NE -1 THEN $
188    ncdf_transfer, cdfid, cdfidout, 'e3tp', 'e3t_ps'
189  IF (where(varlist_ps EQ 'e3wp'))[0] NE -1 THEN $
190    ncdf_transfer, cdfid, cdfidout, 'e3wp', 'e3w_ps'
191  IF (where(varlist_ps EQ 'e3t_ps'))[0] NE -1 THEN $
192    ncdf_transfer, cdfid, cdfidout, 'e3t_ps'
193  IF (where(varlist_ps EQ 'e3w_ps'))[0] NE -1 THEN $
194    ncdf_transfer, cdfid, cdfidout, 'e3w_ps'
195;   IF (where(varlist_ps EQ 'e3u_ps'))[0] NE -1 THEN $
196;     ncdf_transfer, cdfid, cdfidout, 'e3u_ps'
197;   IF (where(varlist_ps EQ 'e3v_ps'))[0] NE -1 THEN $
198;     ncdf_transfer, cdfid, cdfidout, 'e3v_ps'
199;
200; mask
201;
202  IF n_elements(filein_msk) NE 0  THEN BEGIN
203    ncdf_close, cdfid
204    cdfid = ncdf_open(filein_msk)
205  ENDIF
206; loop on the vertical levels to limit the memory use
207  FOR k = 0, jpk-1 DO BEGIN
208    FOR m = 0, 3 DO BEGIN
209      CASE (ncdf_varinq(cdfid, msklist[m])).ndims OF
210        3:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k] $
211        , count = [jpi, jpj, 1]
212        4:ncdf_varget, cdfid, msklist[m], zzz, offset = [0, 0, k, 0] $
213        , count = [jpi, jpj, 1, 1]
214      ENDCASE
215      zzz = byte(temporary(zzz))
216; zzz must contain only 0 or 1
217      zzz = temporary(zzz) MOD 2
218; we transpose zzz because we need to work with the y dimension as the
219; first dimension
220      zzz = transpose(temporary(zzz))
221; extend jpj to be a multiple of 8
222      jpjadd = jpj_m*8-jpj
223      IF jpjadd NE 0 THEN zzz = [temporary(zzz), bytarr(jpjadd, jpi)]
224; reform zzz, to look like output of binary.pro
225      zzz = reform(zzz, 8, 1, jpj_m, jpi, /over)
226; convert into "its byte form"
227      zzz = inverse_binary(temporary(zzz))
228      ncdf_varput, cdfidout, msklist[m], transpose(temporary(zzz)) $
229        , offset = [0, 0, k], count = [jpi, jpj_m, 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.