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

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

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

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