Changeset 118 for trunk/SRC/Interpolation/get_gridparams.pro
- Timestamp:
- 06/27/06 17:47:06 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Interpolation/get_gridparams.pro
- Property svn:keywords set to Id
r114 r118 1 1 ;+ 2 2 ; 3 ; @file_comments 3 ; @file_comments 4 4 ; 1) extract from a NetCDF file the longitude, latidude, and their dimensions 5 ; and make sure it is 1D or 2D arrays 6 ; 7 ; or 2) given longitude and latitude arrays get their dimensions and make sure8 ; they are 1D or 2D arrays5 ; and make sure it is 1D or 2D arrays 6 ; 7 ; or 2) given longitude and latitude arrays get their dimensions and make 8 ; sure they are 1D or 2D arrays 9 9 ; 10 10 ; @categories interpolation 11 11 ; 12 ; @examples 13 ; 12 ; @examples 13 ; 14 14 ; 1) get_gridparams, file, lonname, latname, lon, lat, jpi, jpj, n_dimensions 15 15 ; 16 ; or 16 ; or 17 17 ; 18 18 ; 2) get_gridparams, lon, lat, jpi, jpj, n_dimensions 19 19 ; 20 ; 1) 21 ; @param in1 {in}{required} 22 ; @param in2 {in}{required}the name of the variable that contains the longitude in the NetCDF file23 ; @param in3 {in}{required}the name of the variable that contains the latitude in the NetCDF file24 ; @param in4{out} the number of points in the longitudinal direction25 ; @param in5{out} the number of points in the latitudinal direction20 ; 1) 21 ; @param in1 {in}{required} the name of the netcdf file 22 ; @param in2 {in}{required} the name of the variable that contains the longitude in the NetCDF file 23 ; @param in3 {in}{required} the name of the variable that contains the latitude in the NetCDF file 24 ; @param in4 {out} the number of points in the longitudinal direction 25 ; @param in5 {out} the number of points in the latitudinal direction 26 26 ; @param in6 {out} the variable that will contain the longitudes 27 ; @param in7{out} the variable that will contain the latitudes28 ; 29 ; 30 ; or 31 ; 32 ; 2) 33 ; @param in1 {in}{required} 1d or 2D arrays defining longitudes and latitudes.34 ; @param in2 {in}{required} 1d or 2D arrays defining longitudes and latitudes.35 ; Note that these arrays are also outputs and can therefore be modified. 27 ; @param in7 {out} the variable that will contain the latitudes 28 ; @param in8 {out} 1 or 2 to specify if lon and lat should be 1D (jpi or jpj) 29 ; 30 ; or 31 ; 32 ; 2) 33 ; @param in1 {in}{required} 1d or 2D arrays defining longitudes and latitudes. 34 ; @param in2 {in}{required} 1d or 2D arrays defining longitudes and latitudes. 35 ; Note that these arrays are also outputs and can therefore be modified. 36 36 37 37 ; @param in1 {out} the variable that will contain the longitudes 38 ; @param in2{out} the variable that will contain the latitudes39 ; @param in3{in} the number of points in the longitudinal direction40 ; @param in4{in} the number of points in the latitudinal direction41 ; 38 ; @param in2 {out} the variable that will contain the latitudes 39 ; @param in3 {in} the number of points in the longitudinal direction 40 ; @param in4 {in} the number of points in the latitudinal direction 41 ; @param in5 {in} 1 or 2 to specify if lon and lat should be 1D (jpi or jpj) 42 42 ; arrays or 2D arrays (jpi,jpj). Note that of n_dimensions = 1, then the 43 43 ; grid must be regular (each longitudes must be the same for all latitudes 44 ; and each latitudes should be the sae for all longitudes). 45 ; 46 ; @examples 47 ; 48 ; 1) ncdf_get_gridparams, 'coordinates_ORCA_R05.nc', 'glamt', 'gphit' $ 44 ; and each latitudes should be the sae for all longitudes). 45 ; 46 ; @keyword /DOUBLE use double precision to perform the computation 47 ; 48 ; @examples 49 ; 50 ; 1) IDL> ncdf_get_gridparams, 'coordinates_ORCA_R05.nc', 'glamt', 'gphit' $ 49 51 ; , olon, olat, jpio, jpjo, 2 50 52 ; 51 ; 2) ncdf_get_gridparams, olon, olat, jpio, jpjo, 253 ; 2) IDL> ncdf_get_gridparams, olon, olat, jpio, jpjo, 2 52 54 ; 53 55 ; @history 54 ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) 55 ; 56 ; November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr) 57 ; 58 ; @version $Id$ 59 ; 56 60 ;- 57 61 ; … … 59 63 ;---------------------------------------------------------- 60 64 ; 61 62 65 PRO get_gridparams, in1, in2, in3, in4, in5, in6, in7, in8, DOUBLE = double 63 66 ; file, lonname, latname, lon, lat, jpi, jpj, n_dimensions … … 70 73 8:BEGIN 71 74 ; get longitude and latitude 72 IF file_test(in1) EQ 0 THEN BEGIN 75 IF file_test(in1) EQ 0 THEN BEGIN 73 76 print, 'file ' + in1 + ' does not exist' 74 77 stop … … 77 80 ncdf_varget, cdfido, in2, lon 78 81 ncdf_varget, cdfido, in3, lat 79 ncdf_close, cdfido 82 ncdf_close, cdfido 80 83 n_dimensions = in8 81 84 END 82 5:BEGIN 85 5:BEGIN 83 86 lon = temporary(in1) 84 87 lat = temporary(in2) 85 88 n_dimensions = in5 86 89 END 87 ELSE:BEGIN 90 ELSE:BEGIN 88 91 print, 'Bad nimber of input parameters' 89 92 stop … … 93 96 sizelon = size(lon) 94 97 sizelat = size(lat) 95 CASE 1 OF 98 CASE 1 OF 96 99 ;------- 97 100 ; lon and lat are 1D arrays 98 101 ;------- 99 sizelon[0] EQ 1 AND sizelat[0] EQ 1:BEGIN 102 sizelon[0] EQ 1 AND sizelat[0] EQ 1:BEGIN 100 103 ; get jpi and jpj 101 104 jpi = sizelon[1] 102 105 jpj = sizelat[1] 103 106 ; make sure that lon and lat have the good number of dimensions 104 CASE n_dimensions OF 107 CASE n_dimensions OF 105 108 1: 106 109 2:BEGIN … … 115 118 ; lon is 2D array and lat is 1D array 116 119 ;------- 117 sizelon[0] EQ 2 AND sizelat[0] EQ 1:BEGIN 120 sizelon[0] EQ 2 AND sizelat[0] EQ 1:BEGIN 118 121 ; get jpi and jpj 119 122 jpi = sizelon[1] … … 121 124 IF jpj NE n_elements(lat) THEN stop 122 125 ; make sure that lon and lat have the good number of dimensions 123 CASE n_dimensions OF 124 1:BEGIN 125 IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN 126 CASE n_dimensions OF 127 1:BEGIN 128 IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN 126 129 print, 'Longitudes are not the same for all latitudes, imposible to extract a 1D array of the longitudes' 127 130 stop … … 136 139 ; lon is 1D array and lat is 2D array 137 140 ;------- 138 sizelon[0] EQ 1 AND sizelat[0] EQ 2:BEGIN 141 sizelon[0] EQ 1 AND sizelat[0] EQ 2:BEGIN 139 142 ; get jpi and jpj 140 143 jpi = sizelat[1] … … 142 145 IF jpi NE n_elements(lon) THEN stop 143 146 ; make sure that lon and lat have the good number of dimensions 144 CASE n_dimensions OF 145 1:BEGIN 146 IF array_equal(lat, replicate(1, jpi) # lat[0, *]) NE 1 THEN BEGIN 147 CASE n_dimensions OF 148 1:BEGIN 149 IF array_equal(lat, replicate(1, jpi) # lat[0, *]) NE 1 THEN BEGIN 147 150 print, 'Latitudes are not the same for all longitudes, imposible to extract a 1D array of the latitudes' 148 151 stop … … 157 160 ; lon and lat are 2D arrays 158 161 ;------- 159 sizelon[0] EQ 2 AND sizelat[0] EQ 2:BEGIN 162 sizelon[0] EQ 2 AND sizelat[0] EQ 2:BEGIN 160 163 ; get jpi and jpj 161 164 IF array_equal(sizelon[1:2], sizelat[1:2]) NE 1 THEN stop 162 165 jpi = sizelon[1] 163 jpj = sizelon[2] 164 ; make sure that lon and lat have the good number of dimensions 165 CASE n_dimensions OF 166 1:BEGIN 167 IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN 166 jpj = sizelon[2] 167 ; make sure that lon and lat have the good number of dimensions 168 CASE n_dimensions OF 169 1:BEGIN 170 IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN 168 171 print, 'Longitudes are not the same for all latitudes, imposible to extract a 1D array of the longitudes' 169 172 stop 170 173 ENDIF 171 174 lon = lon[*, 0] 172 IF array_equal(lat, replicate(1, jpi) # reform(lat[0, *])) NE 1 THEN BEGIN 175 IF array_equal(lat, replicate(1, jpi) # reform(lat[0, *])) NE 1 THEN BEGIN 173 176 print, 'Latitudes are not the same for all longitudes, imposible to extract a 1D array of the latitudes' 174 177 stop … … 189 192 ; double keyword 190 193 ;------- 191 if keyword_set(double) then BEGIN 194 if keyword_set(double) then BEGIN 192 195 lon = double(temporary(lon)) 193 196 lat = double(temporary(lat))
Note: See TracChangeset
for help on using the changeset viewer.