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