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