[59] | 1 | ;+ |
---|
| 2 | ; |
---|
[136] | 3 | ; @file_comments |
---|
[125] | 4 | ; interpolate data from a "regular/rectangular grid" to any grid. |
---|
[163] | 5 | ; 2 methods available: bilinear and imoms3 |
---|
| 6 | ; A "regular/rectangular grid" is defined as a grid for which each longitudes lines have |
---|
[59] | 7 | ; the same latitude and each latitudes columns have the same longitude. |
---|
[125] | 8 | ; |
---|
[157] | 9 | ; @categories |
---|
| 10 | ; Interpolation |
---|
[59] | 11 | ; |
---|
[163] | 12 | ; @param method {in}{required}{type=string} |
---|
[136] | 13 | ; a string defining the interpolation method. |
---|
| 14 | ; must be 'bilinear' or 'imoms3' |
---|
[59] | 15 | ; |
---|
[163] | 16 | ; @param datain {in}{required}{type=2d array} |
---|
[136] | 17 | ; a 2D array the input data to interpolate |
---|
| 18 | ; |
---|
[205] | 19 | ; @param lonin {in}{required}{type=1d or 2d array} |
---|
[136] | 20 | ; 1D or 2D array defining the longitude of the input data |
---|
| 21 | ; |
---|
[205] | 22 | ; @param latin {in}{required}{type=1d or 2d array} |
---|
[136] | 23 | ; 1D or 2D array defining the latitude of the input data |
---|
| 24 | ; |
---|
[205] | 25 | ; @param lonout {in}{required}{type=1d or 2d array} |
---|
[136] | 26 | ; 1D or 2D array defining the longitude of the output data |
---|
| 27 | ; |
---|
[163] | 28 | ; @param latout {in}{required}{type=1d or 2d array} |
---|
[136] | 29 | ; 1D or 2D array defining the latitude of the output data |
---|
| 30 | ; |
---|
[228] | 31 | ; @keyword WEIG {type=2d array or variable name} |
---|
[163] | 32 | ; (see ADDR) |
---|
| 33 | ; |
---|
[228] | 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: |
---|
[59] | 41 | ; dataout = total(weig*datain[addr], 1) |
---|
| 42 | ; dataout = reform(dataout, jpio, jpjo, /over) |
---|
[228] | 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 |
---|
[59] | 45 | ; |
---|
[125] | 46 | ; @keyword NONORTHERNLINE |
---|
[163] | 47 | ; activate if you don't want to take into account the northern line |
---|
| 48 | ; of the input data when performing the interpolation. |
---|
| 49 | ; |
---|
[125] | 50 | ; @keyword NOSOUTHERNLINE |
---|
[163] | 51 | ; activate if you don't want to take into account the southern line |
---|
| 52 | ; of the input data when performing the interpolation. |
---|
[59] | 53 | ; |
---|
[136] | 54 | ; @returns |
---|
| 55 | ; 2D array the interpolated data |
---|
[59] | 56 | ; |
---|
[125] | 57 | ; @restrictions |
---|
| 58 | ; We supposed the data are located on a sphere, with a periodicity along the |
---|
| 59 | ; longitude. |
---|
[59] | 60 | ; |
---|
[125] | 61 | ; @examples |
---|
[59] | 62 | ; |
---|
[228] | 63 | ; To interpolate 1 field: |
---|
| 64 | ; |
---|
[125] | 65 | ; IDL> topa = fromreg('bilinear', tncep, xncep, yncep, glamt, gphit) |
---|
[59] | 66 | ; |
---|
[228] | 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) |
---|
[59] | 71 | ; |
---|
[125] | 72 | ; IDL> t1opa = fromreg('bilinear', t1ncep, xncep, yncep, glamt, gphit, WEIG = a, ADDR = b) |
---|
| 73 | ; IDL> help, a, b |
---|
| 74 | ; |
---|
[228] | 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 | ; |
---|
[101] | 80 | ; @history |
---|
[125] | 81 | ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[118] | 82 | ; |
---|
[231] | 83 | ; @version |
---|
| 84 | ; $Id$ |
---|
[118] | 85 | ; |
---|
[59] | 86 | ;- |
---|
| 87 | ; |
---|
| 88 | FUNCTION fromreg, method, datain, lonin, latin, lonout, latout $ |
---|
| 89 | , WEIG = weig, ADDR = addr $ |
---|
| 90 | , NONORTHERNLINE = nonorthernline $ |
---|
| 91 | , NOSOUTHERNLINE = nosouthernline |
---|
| 92 | ; |
---|
[125] | 93 | compile_opt idl2, strictarrsubs |
---|
[59] | 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 | ;--------------- |
---|
[113] | 110 | IF NOT (keyword_set(weig) AND keyword_set(addr)) THEN BEGIN |
---|
[59] | 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 |
---|
[125] | 114 | ELSE:BEGIN |
---|
[59] | 115 | print, ' 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 |
---|
| 125 | END |
---|