source: trunk/SRC/Interpolation/fromirr.pro @ 371

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

  • 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; the interpolation method. must be 'bilinear'
12;
13; @param datain {in}{required}{type=2d array}
14; the input data to interpolate
15;
16; @param lonin {in}{required}{type=2d array}
17; the longitude of the input data
18;
19; @param latin {in}{required}{type=2d array}
20; 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; the longitude of the output data.
28;
29; @param latout {in}{required}{type=1d or 2d array}
30; 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; @keyword
52; _EXTRA to be able to call fromirr with _extra keyword
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
59; the longitude.
60; Note that the input data can contain the same cells several times
61; (like ORCA grid near the north pole boundary)
62;
63; @examples
64;
65;  To interpolate 1 field:
66;
67;   IDL> tncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout)
68;
69;  or if you have several fields to interpolate from the same source and target grids
70;
71; 1) get back the weights and addresses in variables a and b
72;   (that must be undefined or equal to 0 before calling fromirr)
73;
74;   IDL> t1ncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout $
75;                            , WEIG = a, ADDR = b)
76;   IDL> help, a, b
77;
78; 2) use a and b that are now defined to bypass the computation of the weights
79; and addresses and speed-up the computation!
80;
81;   IDL> t2ncep = fromirr('bilinear', topa, WEIG = a, ADDR = b)
82;
83; @history
84;  June 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
85;
86; @version
87; $Id$
88;
89;-
90FUNCTION fromirr, method, datain, lonin, latin, mskin, lonout, latout $
91                , mskout $
92                , WEIG=weig, ADDR=addr, _EXTRA=ex
93;
94  compile_opt strictarr, strictarrsubs
95;
96;---------------
97; atmospheric grid parameters
98;---------------
99    alon = lonin
100    alat = latin
101    get_gridparams, alon, alat, jpia, jpja, 2, /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_fromirr_bilinear_weigaddr, alon, alat, mskin, olon, olat, mskout, weig, addr
114      ELSE:BEGIN
115        ras = report(' unknown interpolation method... we stop')
116        stop
117      ENDELSE
118    ENDCASE
119  ENDIF
120;---------------
121; to the interpolation
122;---------------
123  dataout = total(weig*datain[addr], 1)
124  dataout = reform(dataout, jpio, jpjo, /over)
125;
126  RETURN, dataout
127END
Note: See TracBrowser for help on using the repository browser.