[283] | 1 | ;+ |
---|
| 2 | ; |
---|
| 3 | ; @hidden |
---|
| 4 | ; |
---|
| 5 | ;- |
---|
[327] | 6 | FUNCTION call_interp2d, data, inlon, inlat, inmask, outlon, outlat $ |
---|
| 7 | , INIRR=inirr, METHOD=method, SMOOTH=smooth $ |
---|
[362] | 8 | , WEIG=weig, ADDR=addr, MISSING_VALUE=missing_value, _EXTRA=ex |
---|
[283] | 9 | ; |
---|
| 10 | compile_opt idl2, strictarrsubs |
---|
| 11 | ; |
---|
[292] | 12 | ; for byte, short and long, convert to double before extrapolation and interpolation |
---|
[283] | 13 | intype = size(data, /type) |
---|
| 14 | if intype LE 3 THEN data = double(temporary(data)) |
---|
| 15 | ; |
---|
| 16 | ; take care of NaN values |
---|
[362] | 17 | nanmsk = finite(data) |
---|
| 18 | IF total(nanmsk) NE n_elements(nanmsk) THEN BEGIN |
---|
| 19 | data[where(nanmsk EQ 0b)] = 1.e20 ; put large value to be sure they are removed during the interpolation |
---|
| 20 | mask = inmask * temporary(nanmsk) |
---|
| 21 | ENDIF ELSE mask = inmask |
---|
[283] | 22 | ; |
---|
[362] | 23 | tpmiss = size(missing_value, /type) |
---|
| 24 | IF tpmiss NE 0 AND tpmiss NE 7 THEN BEGIN |
---|
[283] | 25 | CASE 1 OF |
---|
[362] | 26 | missing_value GT 1.e6:mask = temporary(mask) * (data LT (missing_value-10.)) |
---|
| 27 | missing_value LT -1.e6:mask = temporary(mask) * (data GT (missing_value+10.)) |
---|
| 28 | abs(missing_value) LT 1.e-6:mask = temporary(mask) * (abs(data) GT 1.e-6) |
---|
| 29 | ELSE:mask = temporary(mask) * (data NE missing_value) |
---|
[283] | 30 | ENDCASE |
---|
| 31 | ENDIF |
---|
| 32 | ; extrapolation |
---|
| 33 | IF keyword_set(smooth) THEN data = extrapsmooth(temporary(data), mask, /x_periodic, _extra = ex) $ |
---|
| 34 | ELSE data = extrapolate(temporary(data), mask, /x_periodic, _extra = ex) |
---|
| 35 | ; interpolation |
---|
| 36 | IF NOT keyword_set(inirr) THEN BEGIN |
---|
| 37 | data = fromreg(method, temporary(data), inlon, inlat, outlon, outlat, WEIG = weig, ADDR = addr, _extra = ex) |
---|
| 38 | ENDIF ELSE BEGIN |
---|
| 39 | data = fromirr(method, temporary(data), inlon, inlat, -1, outlon, outlat, -1, WEIG = weig, ADDR = addr) |
---|
[292] | 40 | ENDELSE |
---|
| 41 | |
---|
[283] | 42 | if intype LE 3 THEN data = round(temporary(data)) |
---|
| 43 | |
---|
| 44 | RETURN, data |
---|
| 45 | END |
---|
| 46 | ;+ |
---|
| 47 | ; |
---|
| 48 | ; @file_comments |
---|
| 49 | ; interpolate a NetCDF file from a grid to another (both regular or not) |
---|
| 50 | ; |
---|
| 51 | ; @categories |
---|
[292] | 52 | ; Interpolation, NetCDF |
---|
[283] | 53 | ; |
---|
| 54 | ; @param filein {in}{type=scalar string} |
---|
| 55 | ; input file name (must exist) |
---|
| 56 | ; |
---|
| 57 | ; @param fileout {in}{type=scalar string} |
---|
| 58 | ; output file name (will be overwritten if already exist) |
---|
| 59 | ; |
---|
| 60 | ; @param gridout {in}{type=scalar string} |
---|
| 61 | ; output grid file name (must exist and must contain the |
---|
| 62 | ; longitude and latitude axis as 1D or 2D arrays) |
---|
| 63 | ; |
---|
| 64 | ; @keyword GRIDIN {type=scalar string}{default=set to filein} |
---|
[292] | 65 | ; define the input grid file name. It must exist and must contain the |
---|
[283] | 66 | ; longitude and latitude axis as 1D or 2D arrays. Useful if |
---|
| 67 | ; filein file doesn't contain longitude and latitude axis |
---|
| 68 | ; |
---|
| 69 | ; @keyword MASKIN {type=scalar string}{default=set to gridin} |
---|
| 70 | ; define the input mask file name. It must exist. The mask will be |
---|
[292] | 71 | ; determined through <pro>ncdf_getmask</pro> according to the keywords |
---|
[283] | 72 | ; inmaskname, ininvmask, inuseasmask, inmissing_value, inaddscl_before |
---|
[292] | 73 | ; (see below) |
---|
[283] | 74 | ; |
---|
| 75 | ; @keyword MASKOUT {type=scalar string}{default=set to gridout} |
---|
| 76 | ; define the output mask file name. It must exist. The mask will be |
---|
[292] | 77 | ; determined through <pro>ncdf_getmask</pro> according to the keywords |
---|
[283] | 78 | ; outmaskname, outinvmask, outuseasmask, outmissing_value, |
---|
[358] | 79 | ; outaddscl_before (see below). |
---|
[283] | 80 | ; |
---|
| 81 | ; @keyword KEEP {type=string array}{default=all variables} |
---|
| 82 | ; array defining the name of the variables that must be kept in the |
---|
| 83 | ; output file |
---|
| 84 | ; |
---|
| 85 | ; @keyword REMOVE {type=string array}{default=empty} |
---|
| 86 | ; array defining the name of the variables that will be removed in the |
---|
| 87 | ; output file |
---|
| 88 | ; |
---|
| 89 | ; @keyword METHOD {type=scalar string}{default='bilinear'} |
---|
[292] | 90 | ; interpolation method: can be only 'bilinear' (or 'imoms3' if the input grid |
---|
[283] | 91 | ; is a "regular" grid). A "regular/rectangular grid" is defined as a |
---|
[292] | 92 | ; grid for which each longitude lines have the same latitude and each |
---|
[283] | 93 | ; latitude columns have the same longitude. |
---|
| 94 | ; |
---|
| 95 | ; @keyword SMOOTH {type=scalar 0 or 1}{default=0} |
---|
| 96 | ; activate to use <pro>extrapsmooth</pro> instead of |
---|
| 97 | ; <pro>extrapolate</pro> when extrapolating input data over masked |
---|
| 98 | ; points. |
---|
[292] | 99 | ; |
---|
[283] | 100 | ; @keyword SET_XDIMNAME {type=scalar string}{default=not used} |
---|
| 101 | ; used to defined the name of x dimension in filein input file when |
---|
| 102 | ; gridin keyword is used and when the x dimension name is not the same |
---|
| 103 | ; in filein and gridin files. By default, we assume both file have the |
---|
| 104 | ; same x dimension name. |
---|
| 105 | ; |
---|
| 106 | ; @keyword SET_YDIMNAME {type=scalar string}{default=not used} |
---|
| 107 | ; same as set_xdimname but for y dimension |
---|
| 108 | ; |
---|
| 109 | ; @keyword SET_XAXISNAME {type=scalar string}{default=not used} |
---|
| 110 | ; used to defined the name of the variable containing the x axis in |
---|
| 111 | ; filein input file when gridin keyword is used and when its variable |
---|
| 112 | ; containing the x axis name is not the same. By default, we assume |
---|
| 113 | ; both file have the same x axis name. Not that if filein includes x |
---|
[292] | 114 | ; axis there is no point to use gridin |
---|
[283] | 115 | ; |
---|
| 116 | ; @keyword SET_YAXISNAME {type=scalar string}{default=not used} |
---|
| 117 | ; same as set_xaxisname but for y dimension |
---|
| 118 | ; |
---|
| 119 | ; @keyword INMASKNAME {type=scalar string}{default=not used} |
---|
| 120 | ; A string giving the name of the variable in the file maskin that |
---|
[292] | 121 | ; contains the land/sea mask |
---|
[283] | 122 | ; |
---|
| 123 | ; @keyword OUTMASKNAME {type=scalar string}{default=not used} |
---|
| 124 | ; same as inmaskname but for output mask file maskout |
---|
| 125 | ; |
---|
| 126 | ; @keyword ININVMASK {default=0}{type=scalar: 0 or 1} |
---|
| 127 | ; Inverse the land/sea mask of the input mask file maskin (that should |
---|
[292] | 128 | ; have 0/1 values for land/sea) |
---|
[283] | 129 | ; |
---|
| 130 | ; @keyword OUTINVMASK {default=0}{type=scalar: 0 or 1} |
---|
| 131 | ; same as ininvmask but for output mask file maskout |
---|
| 132 | ; |
---|
| 133 | ; @keyword INUSEASMASK {type=scalar string} |
---|
[343] | 134 | ; A string giving the name of the variable in the input mask file |
---|
| 135 | ; that will be used to build the input land/sea mask. In this case the |
---|
[283] | 136 | ; mask is based on the first record (if record dimension |
---|
[343] | 137 | ; exists). The input mask is build according to operator defined by INTESTOP |
---|
| 138 | ; keyword (default NE) and the testing values defined as |
---|
| 139 | ; 1) the second word of TESTOP if existing |
---|
| 140 | ; 2) MISSING_VALUE keyword |
---|
| 141 | ; 3) attribute missing_value or _fillvalue of the variable USEASMASK |
---|
| 142 | ; 4) !Values.f_nan (can be used only with NE and EQ operators) |
---|
[283] | 143 | ; |
---|
| 144 | ; @keyword OUTUSEASMASK {type=scalar string} |
---|
| 145 | ; same as inuseasmask but for output mask file maskout |
---|
| 146 | ; |
---|
| 147 | ; @keyword INMISSING_VALUE {type=scalar} |
---|
| 148 | ; To define (or redefine if the attribute is already existing) the |
---|
[362] | 149 | ; missing values used with INUSEASMASK keyword to build the input mask. |
---|
| 150 | ; Note that this value is not used if INTESTOP keyword is given and |
---|
| 151 | ; contains 2 words. |
---|
| 152 | ; Note: do not mismatch with MISSING_VALUE used to detect missing |
---|
| 153 | ; values at reach record. |
---|
[283] | 154 | ; |
---|
| 155 | ; @keyword OUTMISSING_VALUE {type=scalar} |
---|
| 156 | ; same as inmissing_value but for output mask file maskout |
---|
| 157 | ; |
---|
[343] | 158 | ; @keyword INTESTOP {default='NE'} {type=scalar string, for example 'GT 0.5'} |
---|
| 159 | ; a string describing the type of test that will be done to define the |
---|
| 160 | ; input mask. The test is performed on the variable specified by INUSEASMASK |
---|
| 161 | ; keyword. |
---|
| 162 | ; INTESTOP can contain 1 or 2 words. The first word is the operator |
---|
| 163 | ; definition: "EQ" "NE" "GE" "GT" "LE" "LT" (default is NE). The |
---|
[362] | 164 | ; second word define the testing value. If INTESTOP contains only 1 |
---|
[343] | 165 | ; word, then the test value is denifed by |
---|
[362] | 166 | ; 1) INMISSING_VALUE keyword |
---|
| 167 | ; 2) attribute missing_value or _fillvalue of the variable INUSEASMASK |
---|
[343] | 168 | ; 3) !Values.f_nan (can be used only with NE and EQ operators) |
---|
| 169 | ; |
---|
| 170 | ; @keyword OUTTESTOP {default='NE'} {type=scalar string, for example 'GT 0.5'} |
---|
| 171 | ; same as INTESTOP but for output mask file maskout |
---|
| 172 | ; |
---|
[283] | 173 | ; @keyword INADDSCL_BEFORE {default=0}{type=scalar: 0 or 1} |
---|
[292] | 174 | ; put 1 to apply add_offset and scale factor on data before looking for |
---|
[283] | 175 | ; missing values when using INUSEASMASK keyword |
---|
| 176 | ; |
---|
| 177 | ; @keyword OUTADDSCL_BEFORE {default=0}{type=scalar: 0 or 1} |
---|
| 178 | ; same as inaddscl_before but for output mask file maskout |
---|
| 179 | ; |
---|
[362] | 180 | ; @keyword MISSING_VALUE {type=scalar}{default=defined by attribute missing_value or _fillvalue} |
---|
| 181 | ; (Re)define the missing value in input data (missing values are treated |
---|
[283] | 182 | ; like masked values and will be filled with extrapolation before |
---|
[362] | 183 | ; interpolation). |
---|
| 184 | ; Note: do not mismatch with (IN/OUT)MISSING_VALUE which are missing value |
---|
| 185 | ; used (in association with (IN/OUT)USEASMASK) to built the mask (that |
---|
| 186 | ; does not change from one record to another). |
---|
| 187 | ; Note: this value will be apply to all interpolated variables |
---|
[283] | 188 | ; |
---|
| 189 | ; @keyword ADDR {type=2d array or variable name} |
---|
[292] | 190 | ; 1) at the first call of file_interp: |
---|
[283] | 191 | ; This keyword can be set to a named variable (undefined or equal to |
---|
| 192 | ; 0) into which the addresses used to perform the interpolation will |
---|
| 193 | ; be copied when the current routine exits. |
---|
| 194 | ; 2) Next, once this keyword is set to a defined 2d array, it is used |
---|
| 195 | ; to bypass the computation of the weights and addresses used to |
---|
| 196 | ; perform the interpolation. In this case, interpolation is much |
---|
[292] | 197 | ; faster |
---|
[283] | 198 | ; |
---|
| 199 | ; @keyword WEIG {type=2d array or variable name} |
---|
| 200 | ; (see ADDR) |
---|
[292] | 201 | ; |
---|
[283] | 202 | ; @keyword INXAXISNAME {default='x', 'longitude', 'nav_lon', 'lon', 'lon_rho' or 'NbLongitudes'}{type=scalar string} |
---|
[292] | 203 | ; A string giving the name of the variable containing the x axis in |
---|
[283] | 204 | ; the input grid file gridin |
---|
| 205 | ; |
---|
| 206 | ; @keyword INYAXISNAME {default='y', 'latitude', 'nav_lat','lat', 'lat_rho' or 'NbLatitudes'}{type=scalar string} |
---|
| 207 | ; same as inxaxisname but for the y axis in the input grid file gridin |
---|
| 208 | ; |
---|
| 209 | ; @keyword OUTXAXISNAME {default='x', 'longitude', 'nav_lon', 'lon', 'lon_rho' or 'NbLongitudes'}{type=scalar string} |
---|
| 210 | ; same as inxaxisname but for output grid file gridout |
---|
| 211 | ; |
---|
| 212 | ; @keyword OUTYAXISNAME {default='y', 'latitude', 'nav_lat','lat', 'lat_rho' or 'NbLatitudes'}{type=scalar string} |
---|
| 213 | ; same as inyaxisname but for output grid file gridout |
---|
| 214 | ; |
---|
| 215 | ; @keyword _EXTRA |
---|
| 216 | ; to use <pro>extrapolate</pro>, <pro>extrapsmooth</pro> and <pro>fromreg</pro> keywords |
---|
| 217 | ; |
---|
| 218 | ; @uses |
---|
| 219 | ; <pro>extrapsmooth</pro>, <pro>extrapolate</pro>, <pro>fromreg</pro> and <pro>fromirr</pro> |
---|
| 220 | ; |
---|
| 221 | ; @restrictions |
---|
| 222 | ; |
---|
| 223 | ; - perform only horizontal interpolations on scalar fields |
---|
[343] | 224 | ; - all masked and missing values are filled before interpolation |
---|
| 225 | ; -> output data are not masked and have values everywhere. |
---|
[283] | 226 | ; - attributes (like valid_min...) are not updated |
---|
| 227 | ; - see restrictions of <pro>fromreg</pro> and <pro>fromirr</pro> |
---|
[343] | 228 | ; - output mask is not used but, if the input file contains the mask |
---|
| 229 | ; in a variable (defined by inmaskname), this variable will contain |
---|
| 230 | ; the output mask in the ouput file |
---|
[283] | 231 | ; |
---|
| 232 | ; @examples |
---|
| 233 | ; |
---|
[371] | 234 | ; IDL> file_interp, filein, fileout, gridout, inxaxisname = 'lo', inyaxisname = 'la', keep = ['lo', 'la', 'cond_sed'] |
---|
| 235 | ; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, missing_value = -1000.00 |
---|
[283] | 236 | ; |
---|
| 237 | ; @history |
---|
| 238 | ; September 2007: Sebastien Masson (smasson\@locean-ipsl.upmc.fr) |
---|
| 239 | ; |
---|
| 240 | ; @version |
---|
| 241 | ; $Id$ |
---|
| 242 | ; |
---|
| 243 | ;- |
---|
[327] | 244 | PRO file_interp, filein, fileout, gridout, GRIDIN=gridin, MASKIN=maskin, MASKOUT=maskout $ |
---|
| 245 | , KEEP=keep, REMOVE=remove, METHOD=method, SMOOTH=smooth $ |
---|
| 246 | , SET_XDIMNAME=set_xdimname, SET_YDIMNAME=set_ydimname $ |
---|
| 247 | , SET_XAXISNAME=set_xaxisname, SET_YAXISNAME=set_yaxisname $ |
---|
| 248 | , INMASKNAME=inmaskname, ININVMASK=ininvmask $ |
---|
[343] | 249 | , INUSEASMASK=inuseasmask, INMISSING_VALUE=inmissing_value $ |
---|
| 250 | , INADDSCL_BEFORE=inaddscl_before, INTESTOP = intestop $ |
---|
[327] | 251 | , OUTMASKNAME=outmaskname, OUTINVMASK=outinvmask $ |
---|
[343] | 252 | , OUTUSEASMASK=outuseasmask, OUTMISSING_VALUE=outmissing_value $ |
---|
| 253 | , OUTADDSCL_BEFORE=outaddscl_before, OUTTESTOP = outtestop $ |
---|
[362] | 254 | , MISSING_VALUE=MISSING_VALUE, WEIG=weig, ADDR=addr $ |
---|
[327] | 255 | , INXAXISNAME=inxaxisname, INYAXISNAME=inyaxisname $ |
---|
| 256 | , OUTXAXISNAME=outxaxisname, OUTYAXISNAME=outyaxisname $ |
---|
| 257 | , _EXTRA=ex |
---|
[283] | 258 | ; |
---|
| 259 | compile_opt idl2, strictarrsubs |
---|
| 260 | revision = '$Id$' |
---|
| 261 | ; |
---|
| 262 | IF NOT keyword_set(method) THEN method = 'bilinear' |
---|
| 263 | ; |
---|
| 264 | ; input filenames checks... |
---|
| 265 | ; |
---|
| 266 | inid = ncdf_open(filein) |
---|
| 267 | ininq = ncdf_inquire(inid) |
---|
| 268 | |
---|
| 269 | outid = ncdf_create(fileout, /clobber) |
---|
| 270 | ncdf_control, outid, /nofill |
---|
| 271 | |
---|
| 272 | IF NOT keyword_set(gridin) THEN gridin = filein |
---|
| 273 | |
---|
| 274 | IF NOT keyword_set(maskin) THEN maskin = gridin |
---|
| 275 | IF NOT keyword_set(maskout) THEN maskout = gridout |
---|
| 276 | ; |
---|
| 277 | ; Copy global attributes |
---|
| 278 | ; |
---|
| 279 | FOR i = 0, ininq.ngatts-1 DO BEGIN |
---|
| 280 | name = ncdf_attname(inid, i, /global) |
---|
| 281 | dummy = ncdf_attcopy(inid, name, outid, /in_global, /out_global) |
---|
| 282 | ENDFOR |
---|
| 283 | ncdf_attput, outid, 'Created_by', revision, /GLOBAL |
---|
| 284 | ; |
---|
| 285 | ; x/y dim and x/yaxis informations |
---|
| 286 | ; |
---|
| 287 | ncdf_getaxis, gridin, indimidx, indimidy, inlon, inlat, xdimname = inxdimname, ydimname = inydimname $ |
---|
| 288 | , xaxisname = inxaxisname, yaxisname = inyaxisname |
---|
| 289 | get_gridparams, inlon, inlat, jpiin, jpjin, 2 |
---|
| 290 | IF keyword_set(set_xdimname) THEN inxdimname = set_xdimname |
---|
| 291 | IF keyword_set(set_ydimname) THEN inydimname = set_ydimname |
---|
| 292 | IF keyword_set(set_xaxisname) THEN inxaxisname = set_xaxisname |
---|
| 293 | IF keyword_set(set_yaxisname) THEN inyaxisname = set_yaxisname |
---|
| 294 | ; |
---|
| 295 | ncdf_getaxis, gridout, outdimidx, outdimidy, outlon, outlat, xaxisname = outxaxisname, yaxisname = outyaxisname |
---|
| 296 | get_gridparams, outlon, outlat, jpiout, jpjout, 2 |
---|
| 297 | ; |
---|
| 298 | ; masks |
---|
| 299 | ; |
---|
| 300 | inmask = ncdf_getmask(maskin, MASKNAME = inmaskname, INVMASK = ininvmask, USEASMASK = inuseasmask $ |
---|
[343] | 301 | , MISSING_VALUE = inmissing_value, ADDSCL_BEFORE = inaddscl_before, TESTOP = intestop) |
---|
[283] | 302 | inmasksz = size(inmask, /dimensions) |
---|
| 303 | IF size(inmask, /n_dimensions) EQ 2 THEN inmasksz = [inmasksz, 0] |
---|
| 304 | IF n_elements(inmaskname) EQ 0 THEN inmaskname = 'not defined' ; default definition |
---|
| 305 | outmask = ncdf_getmask(maskout, MASKNAME = outmaskname, INVMASK = outinvmask, USEASMASK = outuseasmask $ |
---|
[343] | 306 | , MISSING_VALUE = outmissing_value, ADDSCL_BEFORE = outaddscl_before, TESTOP = outtestop) |
---|
[283] | 307 | ; |
---|
| 308 | ; irregular grids? |
---|
| 309 | ; |
---|
| 310 | CASE 0 OF |
---|
| 311 | array_equal(inlon[*, 0], inlon[*, jpjin-1]):inirr = 1b |
---|
| 312 | array_equal(inlat[0, *], inlat[jpiin-1, *]):inirr = 1b |
---|
| 313 | array_equal(inlon, inlon[*, 0]#replicate(1, jpjin)):inirr = 1b |
---|
| 314 | array_equal(inlat, replicate(1, jpiin)#(inlat[0, *])[*]):inirr = 1b |
---|
| 315 | ELSE:inirr = 0b |
---|
| 316 | ENDCASE |
---|
| 317 | CASE 0 OF |
---|
| 318 | array_equal(outlon[*, 0], outlon[*, jpjout-1]):outirr = 1b |
---|
| 319 | array_equal(outlat[0, *], outlat[jpiout-1, *]):outirr = 1b |
---|
| 320 | array_equal(outlon, outlon[*, 0]#replicate(1, jpjout)):outirr = 1b |
---|
| 321 | array_equal(outlat, replicate(1, jpiout)#(outlat[0, *])[*]):outirr = 1b |
---|
| 322 | ELSE:outirr = 0b |
---|
| 323 | ENDCASE |
---|
| 324 | |
---|
| 325 | IF inirr AND method NE 'bilinear' THEN stop |
---|
| 326 | ; |
---|
| 327 | ; Dimensions |
---|
| 328 | ; |
---|
| 329 | indimsz = lonarr(ininq.ndims) |
---|
| 330 | outdimsz = lonarr(ininq.ndims) |
---|
| 331 | outdimid = lonarr(ininq.ndims) |
---|
| 332 | FOR i = 0, ininq.ndims-1 DO BEGIN |
---|
| 333 | ncdf_diminq, inid, i, name, size |
---|
| 334 | indimsz[i] = size |
---|
| 335 | outdimsz[i] = size |
---|
| 336 | CASE 1 OF |
---|
| 337 | strlowcase(name) EQ strlowcase(inxdimname): BEGIN |
---|
| 338 | outdimid[i] = ncdf_dimdef(outid, name, jpiout) |
---|
| 339 | outdimsz[i] = jpiout |
---|
| 340 | indimx = i |
---|
| 341 | outdimx = outdimid[i] |
---|
[292] | 342 | END |
---|
| 343 | strlowcase(name) EQ strlowcase(inydimname): BEGIN |
---|
[283] | 344 | outdimid[i] = ncdf_dimdef(outid, name, jpjout) |
---|
| 345 | outdimsz[i] = jpjout |
---|
| 346 | indimy = i |
---|
| 347 | outdimy = outdimid[i] |
---|
[292] | 348 | END |
---|
| 349 | i EQ ininq.recdim: outdimid[i] = ncdf_dimdef(outid, name, /UNLIMITED) |
---|
[283] | 350 | ELSE: outdimid[i] = ncdf_dimdef(outid, name, size) |
---|
| 351 | ENDCASE |
---|
| 352 | ENDFOR |
---|
| 353 | ; |
---|
| 354 | ; Variables |
---|
[292] | 355 | ; |
---|
[283] | 356 | outvarid = lonarr(ininq.nvars) |
---|
| 357 | FOR i = 0, ininq.nvars-1 DO BEGIN |
---|
| 358 | varinq = ncdf_varinq(inid, i) |
---|
| 359 | okvar = 1 |
---|
| 360 | IF keyword_set(keep) THEN okvar = total(strlowcase(keep) EQ strlowcase(varinq.name)) EQ 1 |
---|
| 361 | IF keyword_set(remove) THEN okvar = total(strlowcase(remove) EQ strlowcase(varinq.name)) EQ 0 |
---|
| 362 | IF okvar THEN BEGIN |
---|
| 363 | IF varinq.ndims EQ 0 THEN BEGIN ; scalar variable |
---|
| 364 | outvarid[i] = ncdf_vardef(outid, varinq.name $ |
---|
| 365 | , BYTE = varinq.datatype EQ 'BYTE', CHAR = varinq.datatype EQ 'CHAR' $ |
---|
[330] | 366 | , SHORT = varinq.datatype EQ 'INT' OR varinq.datatype EQ 'SHORT' $ |
---|
| 367 | , LONG = varinq.datatype EQ 'LONG' $ |
---|
[283] | 368 | , FLOAT = varinq.datatype EQ 'FLOAT', DOUBLE = varinq.datatype EQ 'DOUBLE') |
---|
| 369 | ENDIF ELSE BEGIN ; array |
---|
| 370 | CASE 1 OF |
---|
| 371 | strlowcase(varinq.name) EQ strlowcase(inxaxisname):BEGIN ; xaxis |
---|
| 372 | IF outirr THEN dimvar = [outdimx, outdimy] ELSE dimvar = [outdimx] |
---|
[292] | 373 | END |
---|
[283] | 374 | strlowcase(varinq.name) EQ strlowcase(inyaxisname):BEGIN ; yaxis |
---|
| 375 | IF outirr THEN dimvar = [outdimx, outdimy] ELSE dimvar = [outdimy] |
---|
| 376 | END |
---|
| 377 | strlowcase(varinq.name) EQ strlowcase(inmaskname):BEGIN ; mask |
---|
| 378 | IF outmask[0] NE -1 THEN dimvar = outdimid[varinq.dim] ELSE dimvar = -1 |
---|
| 379 | END |
---|
| 380 | (total(varinq.dim EQ indimx) + total(varinq.dim EQ indimx)) EQ 1: dimvar = -1 ; strange variable... |
---|
| 381 | ELSE: dimvar = outdimid[varinq.dim] |
---|
| 382 | ENDCASE |
---|
| 383 | IF dimvar[0] NE -1 THEN BEGIN |
---|
| 384 | outvarid[i] = ncdf_vardef(outid, varinq.name, dimvar $ |
---|
| 385 | , BYTE = varinq.datatype EQ 'BYTE', CHAR = varinq.datatype EQ 'CHAR' $ |
---|
[330] | 386 | , SHORT = varinq.datatype EQ 'INT' OR varinq.datatype EQ 'SHORT' $ |
---|
| 387 | , LONG = varinq.datatype EQ 'LONG' $ |
---|
[283] | 388 | , FLOAT = varinq.datatype EQ 'FLOAT', DOUBLE = varinq.datatype EQ 'DOUBLE') |
---|
| 389 | ENDIF ELSE outvarid[i] = - 1 |
---|
[292] | 390 | ENDELSE |
---|
[283] | 391 | ; Variables attributes |
---|
[292] | 392 | IF outvarid[i] NE - 1 THEN BEGIN |
---|
[283] | 393 | FOR j = 0, varinq.natts-1 DO BEGIN |
---|
| 394 | name = ncdf_attname(inid, i, j) |
---|
| 395 | dummy = ncdf_attcopy(inid, i, name, outid, outvarid[i]) |
---|
| 396 | ENDFOR |
---|
| 397 | ENDIF |
---|
| 398 | ENDIF ELSE outvarid[i] = -1 |
---|
| 399 | ENDFOR |
---|
| 400 | ; |
---|
| 401 | ncdf_control, outid, /endef |
---|
| 402 | ; |
---|
| 403 | FOR i = 0, ininq.nvars-1 DO BEGIN |
---|
| 404 | IF outvarid[i] NE -1 THEN BEGIN |
---|
| 405 | varinq = ncdf_varinq(inid, i) |
---|
| 406 | IF varinq.ndims GE 2 THEN BEGIN |
---|
| 407 | interp = varinq.dim[0] EQ indimx AND varinq.dim[1] EQ indimy |
---|
| 408 | ENDIF ELSE interp = 0b |
---|
| 409 | CASE 1 OF |
---|
| 410 | strlowcase(varinq.name) EQ strlowcase(inxaxisname):BEGIN ; x axis |
---|
| 411 | IF outirr THEN ncdf_varput, outid, outvarid[i], outlon $ |
---|
| 412 | ELSE ncdf_varput, outid, outvarid[i], outlon[*, 0] |
---|
[292] | 413 | END |
---|
[283] | 414 | strlowcase(varinq.name) EQ strlowcase(inyaxisname):BEGIN ; y axis |
---|
| 415 | IF outirr THEN ncdf_varput, outid, outvarid[i], outlat $ |
---|
| 416 | ELSE ncdf_varput, outid, outvarid[i], reform(outlat[0, *]) |
---|
| 417 | END |
---|
| 418 | strlowcase(varinq.name) EQ strlowcase(inmaskname):BEGIN ; mask |
---|
| 419 | ncdf_varput, outid, outvarid[i], outmask |
---|
| 420 | END |
---|
| 421 | ELSE:BEGIN |
---|
[362] | 422 | IF n_elements(missing_value) NE 0 THEN var_missing_value = MISSING_VALUE $ |
---|
| 423 | ELSE ncdf_getatt, inid, i, MISSING_VALUE = var_missing_value |
---|
[283] | 424 | CASE varinq.ndims OF |
---|
| 425 | 0:BEGIN ; salar |
---|
| 426 | ncdf_varget, inid, i, data |
---|
| 427 | ncdf_varput, outid, outvarid[i], temporary(data) |
---|
[292] | 428 | END |
---|
[283] | 429 | 1:BEGIN ; 1D |
---|
| 430 | ncdf_varget, inid, i, data |
---|
| 431 | ncdf_varput, outid, outvarid[i], temporary(data) |
---|
[292] | 432 | END |
---|
[283] | 433 | 2:BEGIN ; 2D |
---|
| 434 | ncdf_varget, inid, i, data |
---|
| 435 | IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, inmask[*, *, 0], outlon, outlat $ |
---|
| 436 | , INIRR = inirr, METHOD = method, SMOOTH = smooth $ |
---|
[362] | 437 | , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) |
---|
[283] | 438 | ncdf_varput, outid, outvarid[i], temporary(data) |
---|
[292] | 439 | END |
---|
[283] | 440 | 3:BEGIN ; 3D |
---|
| 441 | FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN |
---|
| 442 | incnt = [indimsz[varinq.dim[0: 1]], 1] |
---|
| 443 | outcnt = [outdimsz[varinq.dim[0: 1]], 1] |
---|
| 444 | off = [0, 0, k] |
---|
| 445 | ncdf_varget, inid, i, data, offset = off, count = incnt |
---|
[303] | 446 | IF n_elements(inmasksz) GE 3 THEN BEGIN |
---|
| 447 | IF inmasksz[2] EQ indimsz[varinq.dim[2]] AND varinq.dim[2] NE ininq.recdim THEN tmpmsk = inmask[*, *, k] $ |
---|
| 448 | ELSE tmpmsk = inmask[*, *, 0] |
---|
| 449 | ENDIF ELSE tmpmsk = inmask[*, *, 0] |
---|
[283] | 450 | IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $ |
---|
| 451 | , INIRR = inirr, METHOD = method, SMOOTH = smooth $ |
---|
[362] | 452 | , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) |
---|
[283] | 453 | ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt |
---|
| 454 | ENDFOR |
---|
[292] | 455 | END |
---|
[283] | 456 | 4:BEGIN ; 4D |
---|
| 457 | FOR t = 0, indimsz[varinq.dim[3]]-1 DO BEGIN |
---|
| 458 | FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN |
---|
| 459 | incnt = [indimsz[varinq.dim[0: 1]], 1, 1] |
---|
[303] | 460 | outcnt = [outdimsz[varinq.dim[0: 1]], 1, 1] |
---|
[283] | 461 | off = [0, 0, k, t] |
---|
| 462 | ncdf_varget, inid, i, data, offset = off, count = incnt |
---|
[303] | 463 | IF n_elements(inmasksz) GE 3 THEN BEGIN |
---|
| 464 | IF inmasksz[2] EQ indimsz[varinq.dim[2]] THEN tmpmsk = inmask[*, *, k] ELSE tmpmsk = inmask |
---|
| 465 | ENDIF ELSE tmpmsk = inmask[*, *, 0] |
---|
[283] | 466 | IF interp THEN data = call_interp2d(temporary(data), inlon, inlat, temporary(tmpmsk), outlon, outlat $ |
---|
| 467 | , INIRR = inirr, METHOD = method, SMOOTH = smooth $ |
---|
[362] | 468 | , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value, _extra = ex) |
---|
[283] | 469 | ncdf_varput, outid, outvarid[i], temporary(data), offset = off, count = outcnt |
---|
| 470 | ENDFOR |
---|
| 471 | ENDFOR |
---|
[292] | 472 | END |
---|
[283] | 473 | ENDCASE |
---|
| 474 | END |
---|
| 475 | ENDCASE |
---|
[292] | 476 | ENDIF |
---|
[283] | 477 | ENDFOR |
---|
[292] | 478 | |
---|
[283] | 479 | ncdf_close, inid |
---|
| 480 | ncdf_close, outid |
---|
| 481 | |
---|
| 482 | return |
---|
[292] | 483 | END |
---|