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

Last change on this file since 236 was 236, checked in by pinsard, 17 years ago

replace some print by some report in some .pro #2

  • Property svn:keywords set to Id
File size: 4.2 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
84; $Id$
85;
86;-
87;
88FUNCTION fromreg, method, datain, lonin, latin, lonout, latout $
89                  , WEIG = weig, ADDR = addr $
90                  , NONORTHERNLINE = nonorthernline $
91                  , NOSOUTHERNLINE = nosouthernline
92;
93  compile_opt idl2, strictarrsubs
94;
95;---------------
96; atmospheric grid parameters
97;---------------
98    alon = lonin
99    alat = latin
100    get_gridparams, alon, alat, jpia, jpja, 1, /double
101;---------------
102; Oceanic grid parameters
103;---------------
104    olon = lonout
105    olat = latout
106    get_gridparams, olon, olat, jpio, jpjo, 2, /double
107;---------------
108; Compute weight and address
109;---------------
110  IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN
111    CASE method OF
112      'bilinear':compute_fromreg_bilinear_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline
113      'imoms3':  compute_fromreg_imoms3_weigaddr,   alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline
114      ELSE:BEGIN
115        ras = report(' unknown interpolation method... we stop')
116        stop
117      ENDELSE
118    ENDCASE
119  ENDIF
120;
121  dataout = total(weig*datain[addr], 1)
122  dataout = reform(dataout, jpio, jpjo, /over)
123;
124  RETURN, dataout
125END
Note: See TracBrowser for help on using the repository browser.