;+ ; ; @file_comments ; interpolate data from a "regular/rectangular grid" to any grid. ; 2 methods availables: bilinear and imoms3 ; A "regular/rectangular grid" is defined as a grid for which each lontitudes lines have ; the same latitude and each latitudes columns have the same longitude. ; ; @categories interpolation ; ; @param method {in}{required} a string defining the interpolation method. ; must be 'bilinear' or 'imoms3' ; @param datain {in}{required} a 2D array the input data to interpolate ; @param lonin {in}{optional} 1D or 2D array defining the longitude of the input data ; @param latin {in}{optional} 1D or 2D array defining the latitude of the input data ; @param lonout {in}{optional} 1D or 2D array defining the longitude of the output data ; @param latout {in}{required} 1D or 2D array defining the latitude of the output data ; ; @keyword WEIG (see ADDR) ; @keyword ADDR 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 whithout computing again those 2 parameters. In that ; case, lonin, latin, lonout and latout are not necessary. ; ; @keyword NONORTHERNLINE ; @keyword NOSOUTHERNLINE ; activate if you don't want to take into account the northen/southern line ; of the input data when perfoming the interpolation. ; ; @returns 2D array the interpolated data ; ; @restrictions ; We supposed the data are located on a sphere, with a periodicity along the ; longitude. ; ; @examples ; ; IDL> topa = fromreg('bilinear', tncep, xncep, yncep, glamt, gphit) ; ; or ; ; IDL> t1opa = fromreg('bilinear', t1ncep, xncep, yncep, glamt, gphit, WEIG = a, ADDR = b) ; IDL> help, a, b ; IDL> t2opa = fromreg('bilinear', t2ncep, xncep, WEIG = a, ADDR = b) ; ; @history ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) ; ; @version $Id$ ; ;- ;---------------------------------------------------------- ;---------------------------------------------------------- ; FUNCTION fromreg, method, datain, lonin, latin, lonout, latout $ , WEIG = weig, ADDR = addr $ , NONORTHERNLINE = nonorthernline $ , NOSOUTHERNLINE = nosouthernline ; compile_opt idl2, strictarrsubs ; ;--------------- ; atmospheric grid parameters ;--------------- alon = lonin alat = latin get_gridparams, alon, alat, jpia, jpja, 1, /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_fromreg_bilinear_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline 'imoms3': compute_fromreg_imoms3_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline ELSE:BEGIN print, ' unknown interpolation method... we stop' stop ENDELSE ENDCASE ENDIF ; dataout = total(weig*datain[addr], 1) dataout = reform(dataout, jpio, jpjo, /over) ; RETURN, dataout END