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

Last change on this file since 327 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

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