source: trunk/SRC/Interpolation/fromreg.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 4.4 KB
RevLine 
[59]1;+
2;
[136]3; @file_comments
[125]4; interpolate data from a "regular/rectangular grid" to any grid.
[372]5;
6; 2 methods available: bilinear and imoms3
7;
[495]8; A "regular/rectangular grid" is defined as a grid for which
[372]9;
[495]10; Each longitude lines have the same latitude and each latitude columns
[238]11; have the same longitude.
[125]12;
[495]13; @categories
[157]14; Interpolation
[59]15;
[163]16; @param method {in}{required}{type=string}
[238]17; the interpolation method.
[136]18; must be 'bilinear' or 'imoms3'
[59]19;
[163]20; @param datain {in}{required}{type=2d array}
[238]21; the input data to interpolate
[136]22;
[205]23; @param lonin {in}{required}{type=1d or 2d array}
[238]24; the longitude of the input data
[136]25;
[205]26; @param latin {in}{required}{type=1d or 2d array}
[238]27; the latitude of the input data
[136]28;
[205]29; @param lonout {in}{required}{type=1d or 2d array}
[238]30; the longitude of the output data
[136]31;
[163]32; @param latout {in}{required}{type=1d or 2d array}
[238]33; the latitude of the output data
[136]34;
[228]35; @keyword WEIG {type=2d array or variable name}
[163]36; (see ADDR)
37;
[228]38; @keyword ADDR {type=2d array or variable name}
[495]39; 1) at the first call of fromreg:
[228]40; This keyword can be set to a named variable (undefined or equal to 0) into which the
41; addresses used to perform the interpolation will be copied when the current routine exits.
42; 2) Next, once this keyword is set to a defined 2d array, it is used to bypass the computation
43; of the weights and addresses used to perform the interpolation. In this case, fromreg simply
44; compute the interpolated field as:
[59]45;          dataout = total(weig*datain[addr], 1)
46;          dataout = reform(dataout, jpio, jpjo, /over)
[372]47;
[228]48; In that case, method, lonin, latin, are not used (but are necessary).
49; lonout, latout are used only to know the output domain size
[59]50;
[125]51; @keyword NONORTHERNLINE
[163]52; activate if you don't want to take into account the northern line
53; of the input data when performing the interpolation.
54;
[125]55; @keyword NOSOUTHERNLINE
[163]56; activate if you don't want to take into account the southern line
57; of the input data when performing the interpolation.
[59]58;
[495]59; @keyword
[271]60; _EXTRA to be able to call fromreg with _extra keyword
61;
[136]62; @returns
63; 2D array the interpolated data
[59]64;
[125]65; @restrictions
66; We supposed the data are located on a sphere, with a periodicity along the
67; longitude.
[59]68;
[125]69; @examples
[59]70;
[228]71;  To interpolate 1 field:
72;
[371]73;   IDL> topa = fromreg('bilinear', tncep, xncep, yncep, glamt, gphit)
[59]74;
[228]75;  or if you have several fields to interpolate from the same source and target grids
[495]76;
[228]77; 1) get back the weights and addresses in variables a and b
[238]78;   (that must be undefined or equal to 0 before calling fromreg
[59]79;
[371]80;   IDL> t1opa = fromreg('bilinear', t1ncep, xncep, yncep, glamt, gphit, WEIG = a, ADDR = b)
81;   IDL> help, a, b
[125]82;
[495]83; 2) use a and b that are now defined to bypass the computation of the weights and addresses
[228]84; and speed-up the computation!
85;
[371]86;   IDL> t2opa = fromreg('bilinear', t2ncep, xncep, yncep, glamt, gphit, WEIG = a, ADDR = b)
[228]87;
[101]88; @history
[125]89;  November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr)
[118]90;
[231]91; @version
92; $Id$
[118]93;
[59]94;-
95FUNCTION fromreg, method, datain, lonin, latin, lonout, latout $
[327]96                  , WEIG=weig, ADDR=addr $
97                  , NONORTHERNLINE=nonorthernline $
98                  , NOSOUTHERNLINE=nosouthernline, _EXTRA=ex
[59]99;
[125]100  compile_opt idl2, strictarrsubs
[59]101;
102;---------------
103; atmospheric grid parameters
104;---------------
105    alon = lonin
106    alat = latin
107    get_gridparams, alon, alat, jpia, jpja, 1, /double
108;---------------
109; Oceanic grid parameters
110;---------------
111    olon = lonout
112    olat = latout
113    get_gridparams, olon, olat, jpio, jpjo, 2, /double
114;---------------
115; Compute weight and address
116;---------------
[113]117  IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN
[59]118    CASE method OF
119      'bilinear':compute_fromreg_bilinear_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline
120      'imoms3':  compute_fromreg_imoms3_weigaddr,   alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline
[125]121      ELSE:BEGIN
[236]122        ras = report(' unknown interpolation method... we stop')
[59]123        stop
124      ENDELSE
125    ENDCASE
126  ENDIF
127;
[433]128;---------------
129; do the interpolation
130;---------------
131  intype = size(datain, /type)
132  if intype LE 3 THEN dataout = total(weig*float(datain[addr]), 1) $
133  ELSE                dataout = total(weig*      datain[addr] , 1)
[59]134  dataout = reform(dataout, jpio, jpjo, /over)
[433]135  IF intype LE 3 THEN dataout = round(temporary(dataout))
[59]136;
137  RETURN, dataout
138END
Note: See TracBrowser for help on using the repository browser.