source: trunk/SRC/Interpolation/fromreg.pro @ 228

Last change on this file since 228 was 228, checked in by smasson, 17 years ago

more explicit header

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