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