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} |
---|
32 | ; (see ADDR) |
---|
33 | ; |
---|
34 | ; @keyword ADDR {type=2d array} |
---|
35 | ; 2D arrays, weig and addr are the weight and addresses used to |
---|
36 | ; perform the interpolation: |
---|
37 | ; dataout = total(weig*datain[addr], 1) |
---|
38 | ; dataout = reform(dataout, jpio, jpjo, /over) |
---|
39 | ; Those keywords can be set to named variables (that are undefined or equal to 0) into which the |
---|
40 | ; values will be copied when the current routine exits. Next, they can be used to perform |
---|
41 | ; the interpolation without computing again those 2 parameters. In that |
---|
42 | ; case, lonin, latin, lonout and latout are not necessary. |
---|
43 | ; |
---|
44 | ; @keyword NONORTHERNLINE |
---|
45 | ; activate if you don't want to take into account the northern line |
---|
46 | ; of the input data when performing the interpolation. |
---|
47 | ; |
---|
48 | ; @keyword NOSOUTHERNLINE |
---|
49 | ; activate if you don't want to take into account the southern line |
---|
50 | ; of the input data when performing the interpolation. |
---|
51 | ; |
---|
52 | ; @returns |
---|
53 | ; 2D array the interpolated data |
---|
54 | ; |
---|
55 | ; @restrictions |
---|
56 | ; We supposed the data are located on a sphere, with a periodicity along the |
---|
57 | ; longitude. |
---|
58 | ; |
---|
59 | ; @examples |
---|
60 | ; |
---|
61 | ; IDL> topa = fromreg('bilinear', tncep, xncep, yncep, glamt, gphit) |
---|
62 | ; |
---|
63 | ; or |
---|
64 | ; |
---|
65 | ; IDL> t1opa = fromreg('bilinear', t1ncep, xncep, yncep, glamt, gphit, WEIG = a, ADDR = b) |
---|
66 | ; IDL> help, a, b |
---|
67 | ; IDL> t2opa = fromreg('bilinear', t2ncep, xncep, WEIG = a, ADDR = b) |
---|
68 | ; |
---|
69 | ; @history |
---|
70 | ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
71 | ; |
---|
72 | ; @version $Id$ |
---|
73 | ; |
---|
74 | ;- |
---|
75 | ;---------------------------------------------------------- |
---|
76 | ;---------------------------------------------------------- |
---|
77 | ; |
---|
78 | FUNCTION fromreg, method, datain, lonin, latin, lonout, latout $ |
---|
79 | , WEIG = weig, ADDR = addr $ |
---|
80 | , NONORTHERNLINE = nonorthernline $ |
---|
81 | , NOSOUTHERNLINE = nosouthernline |
---|
82 | ; |
---|
83 | compile_opt idl2, strictarrsubs |
---|
84 | ; |
---|
85 | ;--------------- |
---|
86 | ; atmospheric grid parameters |
---|
87 | ;--------------- |
---|
88 | alon = lonin |
---|
89 | alat = latin |
---|
90 | get_gridparams, alon, alat, jpia, jpja, 1, /double |
---|
91 | ;--------------- |
---|
92 | ; Oceanic grid parameters |
---|
93 | ;--------------- |
---|
94 | olon = lonout |
---|
95 | olat = latout |
---|
96 | get_gridparams, olon, olat, jpio, jpjo, 2, /double |
---|
97 | ;--------------- |
---|
98 | ; Compute weight and address |
---|
99 | ;--------------- |
---|
100 | IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN |
---|
101 | CASE method OF |
---|
102 | 'bilinear':compute_fromreg_bilinear_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline |
---|
103 | 'imoms3': compute_fromreg_imoms3_weigaddr, alon, alat, olon, olat, weig, addr, NONORTHERNLINE = nonorthernline, NOSOUTHERNLINE = nosouthernline |
---|
104 | ELSE:BEGIN |
---|
105 | print, ' unknown interpolation method... we stop' |
---|
106 | stop |
---|
107 | ENDELSE |
---|
108 | ENDCASE |
---|
109 | ENDIF |
---|
110 | ; |
---|
111 | dataout = total(weig*datain[addr], 1) |
---|
112 | dataout = reform(dataout, jpio, jpjo, /over) |
---|
113 | ; |
---|
114 | RETURN, dataout |
---|
115 | END |
---|