source: trunk/SRC/Interpolation/fromirr.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: 3.9 KB
Line 
1;+
2;
3; @file_comments
4; interpolate data from an irregular 2D grid to any 2D grid.
5;   Only 1 method available = bilinear
6;
7; @categories
8; Interpolation
9;
10; @param method {in}{required}{type=string}
11; a string defining the interpolation method. must be 'bilinear'
12;
13; @param datain {in}{required}{type=2d array}
14; a 2D array the input data to interpolate
15;
16; @param lonin {in}{required}{type=2d array}
17; a 2D array defining the longitude of the input data
18;
19; @param latin {in}{required}{type=2d array}
20; a 2D array defining the latitude of the input data.
21;
22; @param mskin {in}{required}{type=2d array or -1}
23; a 2D array, the land-sea mask of the input data (1 on ocean, 0 on land)
24; put -1 if input data are not masked
25;
26; @param lonout {in}{required}{type=1d or 2d array}
27; 1D or 2D array defining the longitude of the output data.
28;
29; @param latout {in}{required}{type=1d or 2d array}
30; 1D or 2D array defining the latitude of the output data.
31;
32; @param mskout {in}{required}{type=2d array or -1}
33; a 2D array, the land-sea mask of the output data (1 on ocean, 0 on land)
34; put -1 if output data are not masked
35;
36; @keyword WEIG {type=2d array}
37; (see ADDR)
38;
39; @keyword ADDR {type=2d array}
40; 1) at the first call of fromirr:
41; This keyword can be set to a named variable (undefined or equal to 0) into which the
42; addresses used to perform the interpolation will be copied when the current routine exits.
43; 2) Next, once this keyword is set to a defined 2d array, it is used to bypass the computation
44; of the weights and addresses used to perform the interpolation. In this case, fromirr simply
45; compute the interpolated field as:
46;          dataout = total(weig*datain[addr], 1)
47;          dataout = reform(dataout, jpio, jpjo, /over)
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
50;
51; @returns
52; 2D array the interpolated data
53;
54; @restrictions
55; We supposed the data are located on a sphere, with a periodicity along
56; the longitude.
57; Note that the input data can contain the same cells several times
58; (like ORCA grid near the north pole boundary)
59;
60; @examples
61;
62;  To interpolate 1 field:
63;
64; IDL> tncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout)
65;
66;  or if you have several fields to interpolate from the same source and target grids
67;
68; 1) get back the weights and addresses in variables a and b
69;   (that must be undefined or equal to 0 before calling fromirr)
70;
71; IDL> t1ncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout $
72;                            , 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> t2ncep = fromirr('bilinear', topa, WEIG = a, ADDR = b)
79;
80; @history
81;  June 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
82;
83; @version
84; $Id$
85;
86;-
87;
88FUNCTION fromirr, method, datain, lonin, latin, mskin, lonout, latout, mskout $
89                  , WEIG = weig, ADDR = addr
90;
91  compile_opt strictarr, strictarrsubs
92;
93;---------------
94; atmospheric grid parameters
95;---------------
96    alon = lonin
97    alat = latin
98    get_gridparams, alon, alat, jpia, jpja, 2, /double
99;---------------
100; Oceanic grid parameters
101;---------------
102    olon = lonout
103    olat = latout
104    get_gridparams, olon, olat, jpio, jpjo, 2, /double
105;---------------
106; Compute weight and address
107;---------------
108  IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN
109    CASE method OF
110      'bilinear':compute_fromirr_bilinear_weigaddr, alon, alat, mskin, olon, olat, mskout, weig, addr
111      ELSE:BEGIN
112        ras = report(' unknown interpolation method... we stop')
113        stop
114      ENDELSE
115    ENDCASE
116  ENDIF
117;---------------
118; to the interpolation
119;---------------
120  dataout = total(weig*datain[addr], 1)
121  dataout = reform(dataout, jpio, jpjo, /over)
122;
123  RETURN, dataout
124END
Note: See TracBrowser for help on using the repository browser.