Changeset 433 for trunk/SRC/Interpolation/file_interp.pro
- Timestamp:
- 06/14/10 12:31:14 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Interpolation/file_interp.pro
r417 r433 1 ;+ 2 ; 3 ; @hidden 4 ; 5 ;- 6 FUNCTION boxmean_interp, data, divx, divy 7 ; 8 compile_opt idl2, strictarrsubs 9 ; 10 sz = size(data, /dimensions ) 11 jpiout = sz[0] / divx 12 jpjout = sz[1] / divy 13 ; 14 data = reform(data, divx, jpiout, divy, jpjout, /overwrite) 15 data = total(temporary(data), 1) ; ave along divx 16 data = total(temporary(data), 2) ; ave along divy 17 data = temporary(data) / float(divx*divy) 18 19 RETURN, data 20 END 1 21 ;+ 2 22 ; … … 7 27 , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 8 28 , WEIG = weig, ADDR = addr, MISSING_VALUE = missing_value $ 29 , DIVX = divx, DIVY = divy $ 9 30 , GETHAN = gethan, LETHAN = lethan, _EXTRA = ex 10 31 ; … … 35 56 IF mask[0] NE -1 THEN mask = temporary(missmask) * mask ELSE mask = temporary(missmask) 36 57 ENDIF 58 37 59 ; extrapolation 38 60 IF keyword_set(smooth) THEN data = extrapsmooth(temporary(data), mask, /x_periodic, _extra = ex) $ 39 61 ELSE data = extrapolate(temporary(data), mask, /x_periodic, _extra = ex) 40 62 ; interpolation 41 IF NOT keyword_set(inirr) THEN BEGIN 42 data = fromreg(method, temporary(data), inlon, inlat, outlon, outlat, WEIG = weig, ADDR = addr, _extra = ex) 43 ENDIF ELSE BEGIN 44 data = fromirr(method, temporary(data), inlon, inlat, -1, outlon, outlat, -1, WEIG = weig, ADDR = addr) 45 ENDELSE 63 IF method EQ 'boxmean' THEN BEGIN 64 data = boxmean_interp(temporary(data), divx, divy) 65 ENDIF ELSE BEGIN 66 IF NOT keyword_set(inirr) THEN BEGIN 67 data = fromreg(method, temporary(data), inlon, inlat, outlon, outlat, WEIG = weig, ADDR = addr, _extra = ex) 68 ENDIF ELSE BEGIN 69 data = fromirr(method, temporary(data), inlon, inlat, -1, outlon, outlat, -1, WEIG = weig, ADDR = addr) 70 ENDELSE 71 ENDELSE 46 72 47 73 IF n_elements(gethan) EQ 1 THEN data = gethan > temporary(data) … … 66 92 ; output file name (will be overwritten if already exist) 67 93 ; 68 ; @param gridout {in}{type=scalar string} 69 ; output grid file name (must exist and must contain the 70 ; longitude and latitude axis as 1D or 2D arrays) 94 ; @param gridout {in}{type=scalar string or 2 element vector if boxmean method} 95 ; if boxmean method: 96 ; 2 elements vector defining the size of the box used to compute the 97 ; mean value. It must divide the original grid size. 98 ; else: 99 ; output grid file name (must exist and must contain the 100 ; longitude and latitude axis as 1D or 2D arrays) 71 101 ; 72 102 ; @keyword GRIDIN {type=scalar string}{default=set to filein} … … 96 126 ; 97 127 ; @keyword METHOD {type=scalar string}{default='bilinear'} 98 ; interpolation method: can be only 'bilinear' (or 'imoms3' if the input grid128 ; interpolation method: can be only 'bilinear', 'boxmean' (or 'imoms3' if the input grid 99 129 ; is a "regular" grid). A "regular/rectangular grid" is defined as a 100 130 ; grid for which each longitude lines have the same latitude and each 101 131 ; latitude columns have the same longitude. 132 ; boxmean interpolation is simply the mean value over a box of nx by ny 133 ; points (see gridout definition). 102 134 ; 103 135 ; @keyword SMOOTH {type=scalar 0 or 1}{default=0} … … 248 280 ; IDL> file_interp, filein, fileout, gridout, inxaxisname = 'lo', inyaxisname = 'la', keep = ['lo', 'la', 'cond_sed'] 249 281 ; IDL> file_interp, in, out, gdout, inuseasmask = 'sst', inmissing_value = -1.00000e+30, missing_value = -1000.00 282 ; IDL> file_interp,'sst_reg025.nc', 'sst_reg1.nc',[4,4], method = 'boxmean' 250 283 ; 251 284 ; @history … … 308 341 IF keyword_set(set_yaxisname) THEN inyaxisname = set_yaxisname 309 342 ; 310 ncdf_getaxis, gridout, outdimidx, outdimidy, outlon, outlat, xaxisname = outxaxisname, yaxisname = outyaxisname 311 get_gridparams, outlon, outlat, jpiout, jpjout, 2 343 IF method EQ 'boxmean' THEN BEGIN 344 IF n_elements(gridout) NE 2 THEN stop 345 divx = round(gridout[0]) 346 divy = round(gridout[1]) 347 IF jpiin MOD divx NE 0 THEN BEGIN 348 print, 'in boxmean method, the x size ('+strtrim(divx, 1)+') of the box used to average the data must devide the size of the x dimension ('+strtrim(jpiin, 1)+')' 349 return 350 ENDIF 351 IF jpjin MOD divy NE 0 THEN BEGIN 352 print, 'in boxmean method, the y size ('+strtrim(divy, 1)+') of the box used to average the data must devide the size of the y dimension ('+strtrim(jpjin, 1)+')' 353 return 354 ENDIF 355 jpiout = jpiin / divx 356 jpjout = jpjin / divy 357 outlon = inlon & outlon = boxmean_interp(outlon, divx, divy) 358 outlat = inlat & outlat = boxmean_interp(outlat, divx, divy) 359 IF jpiout EQ 1 OR jpjout EQ 1 THEN BEGIN 360 outlon = reform(outlon, jpiout, jpjout, /overwrite) 361 outlat = reform(outlat, jpiout, jpjout, /overwrite) 362 ENDIF 363 ENDIF ELSE BEGIN 364 ncdf_getaxis, gridout, outdimidx, outdimidy, outlon, outlat, xaxisname = outxaxisname, yaxisname = outyaxisname 365 get_gridparams, outlon, outlat, jpiout, jpjout, 2 366 ENDELSE 312 367 ; 313 368 ; masks … … 318 373 IF size(inmask, /n_dimensions) EQ 2 THEN inmasksz = [inmasksz, 0] 319 374 IF n_elements(inmaskname) EQ 0 THEN inmaskname = 'not defined' ; default definition 320 outmask = ncdf_getmask(maskout, MASKNAME = outmaskname, INVMASK = outinvmask, USEASMASK = outuseasmask $ 321 , MISSING_VALUE = outmissing_value, ADDSCL_BEFORE = outaddscl_before, TESTOP = outtestop) 375 IF method EQ 'boxmean' THEN BEGIN 376 outmask = inmask 377 IF inmask[0] NE -1 THEN outmask = boxmean_interp(outmask, divx, divy) 378 ENDIF ELSE BEGIN 379 outmask = ncdf_getmask(maskout, MASKNAME = outmaskname, INVMASK = outinvmask, USEASMASK = outuseasmask $ 380 , MISSING_VALUE = outmissing_value, ADDSCL_BEFORE = outaddscl_before, TESTOP = outtestop) 381 ENDELSE 322 382 ; 323 383 ; irregular grids? … … 338 398 ENDCASE 339 399 340 IF inirr AND method NE 'bilinear' THEN stop400 IF inirr AND method EQ 'imoms3' THEN stop 341 401 ; 342 402 ; Dimensions … … 451 511 , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 452 512 , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 513 , DIVX = divx, DIVY = divy $ 453 514 , GETHAN = gethan, LETHAN = lethan, _extra = ex) 454 515 IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout) … … 457 518 3:BEGIN ; 3D 458 519 FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN 520 IF k MOD 100 EQ 0 THEN print, k 459 521 incnt = [indimsz[varinq.dim[0: 1]], 1] 460 522 outcnt = [outdimsz[varinq.dim[0: 1]], 1] … … 468 530 , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 469 531 , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 532 , DIVX = divx, DIVY = divy $ 470 533 , GETHAN = gethan, LETHAN = lethan, _extra = ex) 471 534 IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout) … … 475 538 4:BEGIN ; 4D 476 539 FOR t = 0, indimsz[varinq.dim[3]]-1 DO BEGIN 540 IF t MOD 100 EQ 0 THEN print, t 477 541 FOR k = 0, indimsz[varinq.dim[2]]-1 DO BEGIN 478 542 incnt = [indimsz[varinq.dim[0: 1]], 1, 1] … … 486 550 , INIRR = inirr, METHOD = method, SMOOTH = smooth $ 487 551 , WEIG = weig, ADDR = addr, MISSING_VALUE = var_missing_value $ 552 , DIVX = divx, DIVY = divy $ 488 553 , GETHAN = gethan, LETHAN = lethan, _extra = ex) 489 554 IF interp AND n_elements(data) EQ 1 THEN data = replicate(data, jpiout, jpjout)
Note: See TracChangeset
for help on using the changeset viewer.