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 | ; 2D arrays, weig and addr are the weight and addresses used to |
---|
41 | ; perform the interpolation: |
---|
42 | ; dataout = total(weig*datain[addr], 1) |
---|
43 | ; dataout = reform(dataout, jpio, jpjo, /over) |
---|
44 | ; Those keywords can be set to named variables (that are undefined or equal to 0) into which the |
---|
45 | ; values will be copied when the current routine exits. Next, they can be used to perform |
---|
46 | ; the interpolation without computing again those 2 parameters. This greatly |
---|
47 | ; speed-up the interpolation! In that case, lonin, latin, lonout and latout are not necessary. |
---|
48 | ; |
---|
49 | ; @returns |
---|
50 | ; 2D array the interpolated data |
---|
51 | ; |
---|
52 | ; @restrictions |
---|
53 | ; We supposed the data are located on a sphere, with a periodicity along |
---|
54 | ; the longitude. |
---|
55 | ; Note that the input data can contain the same cells several times |
---|
56 | ; (like ORCA grid near the north pole boundary) |
---|
57 | ; |
---|
58 | ; @examples |
---|
59 | ; |
---|
60 | ; IDL> tncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout) |
---|
61 | ; |
---|
62 | ; or |
---|
63 | ; |
---|
64 | ; IDL> t1ncep = fromirr('bilinear', topa, glamt, gphit, tmask[*,*,0], lonout, latout, mskout $ |
---|
65 | ; , WEIG = a, ADDR = b) |
---|
66 | ; IDL> help, a, b |
---|
67 | ; IDL> t2ncep = fromirr('bilinear', topa, WEIG = a, ADDR = b) |
---|
68 | ; |
---|
69 | ; @history |
---|
70 | ; June 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
71 | ; |
---|
72 | ; @version $Id$ |
---|
73 | ; |
---|
74 | ;- |
---|
75 | ;---------------------------------------------------------- |
---|
76 | ;---------------------------------------------------------- |
---|
77 | ; |
---|
78 | FUNCTION fromirr, method, datain, lonin, latin, mskin, lonout, latout, mskout $ |
---|
79 | , WEIG = weig, ADDR = addr |
---|
80 | ; |
---|
81 | compile_opt strictarr, strictarrsubs |
---|
82 | ; |
---|
83 | ;--------------- |
---|
84 | ; atmospheric grid parameters |
---|
85 | ;--------------- |
---|
86 | alon = lonin |
---|
87 | alat = latin |
---|
88 | get_gridparams, alon, alat, jpia, jpja, 2, /double |
---|
89 | ;--------------- |
---|
90 | ; Oceanic grid parameters |
---|
91 | ;--------------- |
---|
92 | olon = lonout |
---|
93 | olat = latout |
---|
94 | get_gridparams, olon, olat, jpio, jpjo, 2, /double |
---|
95 | ;--------------- |
---|
96 | ; Compute weight and address |
---|
97 | ;--------------- |
---|
98 | IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN |
---|
99 | CASE method OF |
---|
100 | 'bilinear':compute_fromirr_bilinear_weigaddr, alon, alat, mskin, olon, olat, mskout, weig, addr |
---|
101 | ELSE:BEGIN |
---|
102 | print, ' unknown interpolation method... we stop' |
---|
103 | stop |
---|
104 | ENDELSE |
---|
105 | ENDCASE |
---|
106 | ENDIF |
---|
107 | ;--------------- |
---|
108 | ; to the interpolation |
---|
109 | ;--------------- |
---|
110 | dataout = total(weig*datain[addr], 1) |
---|
111 | dataout = reform(dataout, jpio, jpjo, /over) |
---|
112 | ; |
---|
113 | RETURN, dataout |
---|
114 | END |
---|