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

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

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