;+ ; ; @file_comments ; interpolate data from an irregular 2D grid to any 2D grid. ; Only 1 method available = bilinear ; ; @categories ; Interpolation ; ; @param method {in}{required}{type=string} ; a string defining the interpolation method. must be 'bilinear' ; ; @param datain {in}{required}{type=2d array} ; a 2D array the input data to interpolate ; ; @param lonin {in}{optional}{type=2d array} ; a 2D array defining the longitude of the input data ; ; @param latin {in}{optional}{type=2d array} ; a 2D array defining the latitude of the input data. ; ; @param mskin {in}{optional}{type=2d array} ; a 2D array, the land-sea mask of the input data (1 on ocean, 0 on land) ; ; @param lonout {in}{optional}{type=1d or 2d array} ; 1D or 2D array defining the longitude of the output data. ; ; @param latout {in}{optional}{type=1d or 2d array} ; 1D or 2D array defining the latitude of the output data. ; ; @param mskout {in}{required}{type=2d array} ; a 2D array, the land-sea mask of the output data (1 on ocean, 0 on land) ; ; @keyword WEIG {type=2d array} ; (see ADDR) ; ; @keyword ADDR {type=2d array} ; 2D arrays, weig and addr are the weight and addresses used to ; perform the interpolation: ; dataout = total(weig*datain[addr], 1) ; dataout = reform(dataout, jpio, jpjo, /over) ; Those keywords can be set to named variables (that are undefined or equal to 0) into which the ; values will be copied when the current routine exits. Next, they can be used to perform ; the interpolation without computing again those 2 parameters. This greatly ; speed-up the interpolation! In that case, lonin, latin, lonout and latout are not necessary. ; ; @returns ; 2D array the interpolated data ; ; @restrictions ; We supposed the data are located on a sphere, with a periodicity along ; the longitude. ; Note that the input data can contain the same cells several times ; (like ORCA grid near the north pole boundary) ; ; @examples ; ; IDL> tncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout) ; ; or ; ; IDL> t1ncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout $ ; , WEIG = a, ADDR = b) ; IDL> help, a, b ; IDL> t2ncep = fromirr('bilinear', topa, WEIG = a, ADDR = b) ; ; @history ; June 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr) ; ; @version $Id$ ; ;- ;---------------------------------------------------------- ;---------------------------------------------------------- ; FUNCTION fromirr, method, datain, lonin, latin, mskin, lonout, latout, mskout $ , WEIG = weig, ADDR = addr ; compile_opt strictarr, strictarrsubs ; ;--------------- ; atmospheric grid parameters ;--------------- alon = lonin alat = latin get_gridparams, alon, alat, jpia, jpja, 2, /double ;--------------- ; Oceanic grid parameters ;--------------- olon = lonout olat = latout get_gridparams, olon, olat, jpio, jpjo, 2, /double ;--------------- ; Compute weight and address ;--------------- IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN CASE method OF 'bilinear':compute_fromirr_bilinear_weigaddr, alon, alat, mskin, olon, olat, mskout, weig, addr ELSE:BEGIN print, ' unknown interpolation method... we stop' stop ENDELSE ENDCASE ENDIF ;--------------- ; to the interpolation ;--------------- dataout = total(weig*datain[addr], 1) dataout = reform(dataout, jpio, jpjo, /over) ; RETURN, dataout END