source: trunk/SRC/Interpolation/get_gridparams.pro @ 138

Last change on this file since 138 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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