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