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