[59] | 1 | ;+ |
---|
| 2 | ; |
---|
[118] | 3 | ; @file_comments |
---|
[271] | 4 | ; Case 1: extract from a NetCDF file longitude and latitude arrays, their dimensions |
---|
[136] | 5 | ; and make sure it is 1D or 2D arrays |
---|
[59] | 6 | ; |
---|
[271] | 7 | ; Case 2: given longitude and latitude arrays, get their dimensions and make |
---|
[136] | 8 | ; sure they are 1D or 2D arrays |
---|
[118] | 9 | ; |
---|
[157] | 10 | ; @categories |
---|
| 11 | ; Interpolation |
---|
[59] | 12 | ; |
---|
[118] | 13 | ; @examples |
---|
| 14 | ; |
---|
[271] | 15 | ; Case 1: |
---|
[371] | 16 | ; IDL> get_gridparams, file name/id, lonname, latname, lon, lat, jpi, jpj, n_dimensions |
---|
[59] | 17 | ; |
---|
[271] | 18 | ; Case 2: |
---|
[371] | 19 | ; IDL> get_gridparams, lon, lat, jpi, jpj, n_dimensions |
---|
[59] | 20 | ; |
---|
[136] | 21 | ; @param in1 {in}{required} |
---|
[271] | 22 | ; Case 1: name or the id (returned by ncdf_open) of the netcdf file |
---|
| 23 | ; Case 2: 1D or 2D arrays defining longitudes, will be forced to have |
---|
| 24 | ; n_dimensions dimensions when returned |
---|
[59] | 25 | ; |
---|
[136] | 26 | ; @param in2 {in}{required} |
---|
[271] | 27 | ; Case 1: name of the variable containing the longitude in the NetCDF file |
---|
| 28 | ; Case 2: 1D or 2D arrays defining latitudes, will be forced to have |
---|
| 29 | ; n_dimensions dimensions when returned |
---|
[136] | 30 | ; |
---|
[271] | 31 | ; @param in3 |
---|
| 32 | ; Case 1: name of the variable containing the latitude in the NetCDF file |
---|
| 33 | ; Case 2: returned number of points in longitudinal direction. |
---|
[136] | 34 | ; |
---|
| 35 | ; @param in4 {out} |
---|
[271] | 36 | ; Case 1: returned longitudes array, with n_dimensions dimensions |
---|
| 37 | ; Case 2: returned number of points in latitudinal direction |
---|
[136] | 38 | ; |
---|
[271] | 39 | ; @param in5 |
---|
| 40 | ; Case 1: returned latitudes array, with n_dimensions dimensions |
---|
| 41 | ; Case 2: input scalar (1 or 2) to specify if lon and lat should be returned |
---|
| 42 | ; as 1D or 2D arrays. Note that if n_dimensions = 1, the grid must be |
---|
| 43 | ; regular (longitude and latitudes can be described as 1D arrays). |
---|
[136] | 44 | ; |
---|
| 45 | ; @param in6 {out} |
---|
[271] | 46 | ; Case 1: returned number of points in longitudinal direction. |
---|
[136] | 47 | ; |
---|
| 48 | ; @param in7 {out} |
---|
[271] | 49 | ; Case 1: returned number of points in latitudinal direction |
---|
[136] | 50 | ; |
---|
[271] | 51 | ; @param in8 {in} |
---|
| 52 | ; Case 1: input scalar (1 or 2) to specify if lon and lat should be returned |
---|
| 53 | ; as 1D or 2D arrays. Note that if n_dimensions = 1, the grid must be |
---|
| 54 | ; regular (longitude and latitudes can be described as 1D arrays). |
---|
[136] | 55 | ; |
---|
[271] | 56 | ; @keyword DOUBLE {default=0}{type=scalar: 0 or 1} |
---|
| 57 | ; activate to force double precision for lon/lat arrays |
---|
[136] | 58 | ; |
---|
[118] | 59 | ; @examples |
---|
| 60 | ; |
---|
[372] | 61 | ; 1) |
---|
| 62 | ; |
---|
| 63 | ; IDL> ncdf_get_gridparams, 'coordinates_ORCA_R05.nc', 'glamt', 'gphit' $ |
---|
[59] | 64 | ; , olon, olat, jpio, jpjo, 2 |
---|
| 65 | ; |
---|
[372] | 66 | ; 2) |
---|
[59] | 67 | ; |
---|
[379] | 68 | ; IDL> ncdf_get_gridparams, olon, olat, jpio, jpjo, 2 |
---|
[372] | 69 | ; |
---|
[101] | 70 | ; @history |
---|
[372] | 71 | ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[118] | 72 | ; |
---|
[231] | 73 | ; @version |
---|
| 74 | ; $Id$ |
---|
[118] | 75 | ; |
---|
[59] | 76 | ;- |
---|
[327] | 77 | PRO get_gridparams, in1, in2, in3, in4, in5, in6, in7, in8 $ |
---|
| 78 | , DOUBLE=double |
---|
| 79 | ; |
---|
[59] | 80 | ; file, lonname, latname, lon, lat, jpi, jpj, n_dimensions |
---|
[327] | 81 | ; lon, lat, jpi, jpj, n_dimensions |
---|
[59] | 82 | ; |
---|
[114] | 83 | compile_opt idl2, strictarrsubs |
---|
| 84 | ; |
---|
[59] | 85 | CASE n_params() OF |
---|
| 86 | 8:BEGIN |
---|
| 87 | ; get longitude and latitude |
---|
[271] | 88 | IF size(in1, /type) EQ 7 THEN BEGIN |
---|
| 89 | IF file_test(in1) EQ 0 THEN BEGIN |
---|
| 90 | ras = report('file ' + in1 + ' does not exist') |
---|
| 91 | stop |
---|
| 92 | ENDIF |
---|
| 93 | cdfido = ncdf_open(in1) |
---|
| 94 | ENDIF ELSE cdfido = in1 |
---|
[59] | 95 | ncdf_varget, cdfido, in2, lon |
---|
| 96 | ncdf_varget, cdfido, in3, lat |
---|
[271] | 97 | IF size(in1, /type) EQ 7 THEN ncdf_close, cdfido |
---|
[59] | 98 | n_dimensions = in8 |
---|
| 99 | END |
---|
[118] | 100 | 5:BEGIN |
---|
[59] | 101 | lon = temporary(in1) |
---|
| 102 | lat = temporary(in2) |
---|
| 103 | n_dimensions = in5 |
---|
| 104 | END |
---|
[118] | 105 | ELSE:BEGIN |
---|
[236] | 106 | ras = report('Bad number of input parameters') |
---|
[59] | 107 | stop |
---|
| 108 | end |
---|
| 109 | ENDCASE |
---|
| 110 | ; |
---|
| 111 | sizelon = size(lon) |
---|
| 112 | sizelat = size(lat) |
---|
[118] | 113 | CASE 1 OF |
---|
[59] | 114 | ;------- |
---|
| 115 | ; lon and lat are 1D arrays |
---|
| 116 | ;------- |
---|
[118] | 117 | sizelon[0] EQ 1 AND sizelat[0] EQ 1:BEGIN |
---|
[59] | 118 | ; get jpi and jpj |
---|
| 119 | jpi = sizelon[1] |
---|
| 120 | jpj = sizelat[1] |
---|
| 121 | ; make sure that lon and lat have the good number of dimensions |
---|
[118] | 122 | CASE n_dimensions OF |
---|
[59] | 123 | 1: |
---|
| 124 | 2:BEGIN |
---|
| 125 | ; make lon and lat 2D arrays |
---|
| 126 | lon = temporary(lon) # replicate(1, jpj) |
---|
| 127 | lat = replicate(1, jpi) # temporary(lat) |
---|
| 128 | END |
---|
| 129 | ELSE:stop |
---|
| 130 | ENDCASE |
---|
| 131 | END |
---|
| 132 | ;------- |
---|
| 133 | ; lon is 2D array and lat is 1D array |
---|
| 134 | ;------- |
---|
[118] | 135 | sizelon[0] EQ 2 AND sizelat[0] EQ 1:BEGIN |
---|
[59] | 136 | ; get jpi and jpj |
---|
| 137 | jpi = sizelon[1] |
---|
| 138 | jpj = sizelon[2] |
---|
| 139 | IF jpj NE n_elements(lat) THEN stop |
---|
| 140 | ; make sure that lon and lat have the good number of dimensions |
---|
[118] | 141 | CASE n_dimensions OF |
---|
| 142 | 1:BEGIN |
---|
| 143 | IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN |
---|
[236] | 144 | ras = report('Longitudes are not the same for all latitudes, impossible to extract a 1D array of the longitudes') |
---|
[59] | 145 | stop |
---|
| 146 | ENDIF |
---|
| 147 | lon = lon[*, 0] |
---|
| 148 | END |
---|
| 149 | 2:lat = replicate(1, jpi) # temporary(lat) |
---|
| 150 | ELSE:stop |
---|
| 151 | ENDCASE |
---|
| 152 | END |
---|
| 153 | ;------- |
---|
| 154 | ; lon is 1D array and lat is 2D array |
---|
| 155 | ;------- |
---|
[118] | 156 | sizelon[0] EQ 1 AND sizelat[0] EQ 2:BEGIN |
---|
[59] | 157 | ; get jpi and jpj |
---|
| 158 | jpi = sizelat[1] |
---|
| 159 | jpj = sizelat[2] |
---|
| 160 | IF jpi NE n_elements(lon) THEN stop |
---|
| 161 | ; make sure that lon and lat have the good number of dimensions |
---|
[118] | 162 | CASE n_dimensions OF |
---|
| 163 | 1:BEGIN |
---|
| 164 | IF array_equal(lat, replicate(1, jpi) # lat[0, *]) NE 1 THEN BEGIN |
---|
[236] | 165 | ras = report('Latitudes are not the same for all longitudes, impossible to extract a 1D array of the latitudes') |
---|
[59] | 166 | stop |
---|
| 167 | ENDIF |
---|
| 168 | lat = reform(lat[0, *]) |
---|
| 169 | END |
---|
| 170 | 2:lon = temporary(lon) # replicate(1, jpj) |
---|
| 171 | ELSE:stop |
---|
| 172 | ENDCASE |
---|
| 173 | END |
---|
| 174 | ;------- |
---|
| 175 | ; lon and lat are 2D arrays |
---|
| 176 | ;------- |
---|
[118] | 177 | sizelon[0] EQ 2 AND sizelat[0] EQ 2:BEGIN |
---|
[59] | 178 | ; get jpi and jpj |
---|
| 179 | IF array_equal(sizelon[1:2], sizelat[1:2]) NE 1 THEN stop |
---|
| 180 | jpi = sizelon[1] |
---|
[118] | 181 | jpj = sizelon[2] |
---|
[59] | 182 | ; make sure that lon and lat have the good number of dimensions |
---|
[118] | 183 | CASE n_dimensions OF |
---|
| 184 | 1:BEGIN |
---|
| 185 | IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN |
---|
[236] | 186 | ras = report('Longitudes are not the same for all latitudes, impossible to extract a 1D array of the longitudes') |
---|
[59] | 187 | stop |
---|
| 188 | ENDIF |
---|
| 189 | lon = lon[*, 0] |
---|
[118] | 190 | IF array_equal(lat, replicate(1, jpi) # reform(lat[0, *])) NE 1 THEN BEGIN |
---|
[236] | 191 | ras = report('Latitudes are not the same for all longitudes, impossible to extract a 1D array of the latitudes') |
---|
[59] | 192 | stop |
---|
| 193 | ENDIF |
---|
| 194 | lat = reform(lat[0, *]) |
---|
| 195 | END |
---|
| 196 | 2: |
---|
| 197 | ELSE:stop |
---|
| 198 | ENDCASE |
---|
| 199 | END |
---|
| 200 | ;------- |
---|
| 201 | ; lon and lat are not 1D and/or 2D arrays |
---|
| 202 | ;------- |
---|
[236] | 203 | ELSE: BEGIN |
---|
| 204 | ras = report('Longitudes and latitudes are not 1D and/or 2D arrays') |
---|
| 205 | stop |
---|
| 206 | END |
---|
[59] | 207 | ENDCASE |
---|
| 208 | ; |
---|
| 209 | ;------- |
---|
| 210 | ; double keyword |
---|
| 211 | ;------- |
---|
[118] | 212 | if keyword_set(double) then BEGIN |
---|
[59] | 213 | lon = double(temporary(lon)) |
---|
| 214 | lat = double(temporary(lat)) |
---|
| 215 | ENDIF |
---|
| 216 | ; |
---|
| 217 | ; give back the right outparameters. |
---|
| 218 | ; |
---|
| 219 | |
---|
| 220 | CASE n_params() OF |
---|
| 221 | 8:BEGIN |
---|
| 222 | in4 = temporary(lon) |
---|
| 223 | in5 = temporary(lat) |
---|
| 224 | in6 = temporary(jpi) |
---|
| 225 | in7 = temporary(jpj) |
---|
| 226 | END |
---|
| 227 | 5:BEGIN |
---|
| 228 | in1 = temporary(lon) |
---|
| 229 | in2 = temporary(lat) |
---|
| 230 | in3 = temporary(jpi) |
---|
| 231 | in4 = temporary(jpj) |
---|
| 232 | END |
---|
| 233 | ENDCASE |
---|
| 234 | ; |
---|
| 235 | |
---|
| 236 | return |
---|
| 237 | END |
---|