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

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

start to modify headers of ForOldVersion? *.pro files for better idldoc output

  • Property svn:executable set to *
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 2) given longitude and latitude arrays get their dimensions and make sure
8;      they are 1D or 2D arrays
9;
10; @categories interpolation
11;
12; @examples
13;
14; 1) get_gridparams, file, lonname, latname, lon, lat, jpi, jpj, n_dimensions
15;
16; or
17;
18; 2) get_gridparams, lon, lat, jpi, jpj, n_dimensions
19;
20; 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; @param in6 {out} the variable that will contain the longitudes
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
37; @param in1 {out} the variable that will contain the longitudes
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;    arrays or 2D arrays (jpi,jpj). Note that of  n_dimensions = 1, then the
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' $
49;            , olon, olat, jpio, jpjo, 2
50;
51; 2) ncdf_get_gridparams, olon, olat, jpio, jpjo, 2
52;
53; @history
54;  November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr)
55;
56;-
57;
58;----------------------------------------------------------
59;----------------------------------------------------------
60;
61
62PRO get_gridparams, in1,   in2,   in3,     in4, in5, in6, in7, in8, DOUBLE = double
63;                  file, lonname, latname, lon, lat, jpi, jpj, n_dimensions
64;                   lon,   lat,   jpi,     jpj, n_dimensions
65;
66  CASE n_params() OF
67    8:BEGIN
68; get longitude and latitude
69      IF file_test(in1) EQ 0 THEN BEGIN
70        print, 'file ' + in1 + ' does not exist'
71        stop
72      ENDIF
73      cdfido = ncdf_open(in1)
74      ncdf_varget, cdfido, in2, lon
75      ncdf_varget, cdfido, in3, lat
76      ncdf_close, cdfido
77      n_dimensions = in8
78    END
79    5:BEGIN
80      lon = temporary(in1)
81      lat = temporary(in2)
82      n_dimensions = in5
83    END
84    ELSE:BEGIN
85      print, 'Bad nimber of input parameters'
86      stop
87    end
88  ENDCASE
89;
90  sizelon = size(lon)
91  sizelat = size(lat)
92  CASE 1 OF
93;-------
94; lon and lat are 1D arrays
95;-------
96    sizelon[0] EQ 1 AND sizelat[0] EQ 1:BEGIN
97; get jpi and jpj
98      jpi = sizelon[1]
99      jpj = sizelat[1]
100; make sure that lon and lat have the good number of dimensions
101      CASE n_dimensions OF
102        1:
103        2:BEGIN
104; make lon and lat 2D arrays
105          lon = temporary(lon) # replicate(1, jpj)
106          lat = replicate(1, jpi) # temporary(lat)
107        END
108        ELSE:stop
109      ENDCASE
110    END
111;-------
112; lon is 2D array and lat is 1D array
113;-------
114    sizelon[0] EQ 2 AND sizelat[0] EQ 1:BEGIN
115; get jpi and jpj
116      jpi = sizelon[1]
117      jpj = sizelon[2]
118      IF jpj NE n_elements(lat) THEN stop
119; make sure that lon and lat have the good number of dimensions
120      CASE n_dimensions OF
121        1:BEGIN
122          IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN
123            print, 'Longitudes are not the same for all latitudes, imposible to extract a 1D array of the longitudes'
124            stop
125          ENDIF
126          lon = lon[*, 0]
127        END
128        2:lat = replicate(1, jpi) # temporary(lat)
129        ELSE:stop
130      ENDCASE
131    END
132;-------
133; lon is 1D array and lat is 2D array
134;-------
135    sizelon[0] EQ 1 AND sizelat[0] EQ 2:BEGIN
136; get jpi and jpj
137      jpi = sizelat[1]
138      jpj = sizelat[2]
139      IF jpi NE n_elements(lon) THEN stop
140; make sure that lon and lat have the good number of dimensions
141      CASE n_dimensions OF
142        1:BEGIN
143          IF array_equal(lat, replicate(1, jpi) # lat[0, *]) NE 1 THEN BEGIN
144            print, 'Latitudes are not the same for all longitudes, imposible to extract a 1D array of the latitudes'
145            stop
146          ENDIF
147          lat = reform(lat[0, *])
148        END
149        2:lon = temporary(lon) # replicate(1, jpj)
150        ELSE:stop
151      ENDCASE
152    END
153;-------
154; lon and lat are 2D arrays
155;-------
156    sizelon[0] EQ 2 AND sizelat[0] EQ 2:BEGIN
157; get jpi and jpj
158      IF array_equal(sizelon[1:2], sizelat[1:2]) NE 1 THEN stop
159      jpi = sizelon[1]
160      jpj = sizelon[2]     
161; make sure that lon and lat have the good number of dimensions
162      CASE n_dimensions OF
163        1:BEGIN
164          IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN
165            print, 'Longitudes are not the same for all latitudes, imposible to extract a 1D array of the longitudes'
166            stop
167          ENDIF
168          lon = lon[*, 0]
169          IF array_equal(lat, replicate(1, jpi) # reform(lat[0, *])) NE 1 THEN BEGIN
170            print, 'Latitudes are not the same for all longitudes, imposible to extract a 1D array of the latitudes'
171            stop
172          ENDIF
173        lat = reform(lat[0, *])
174        END
175        2:
176        ELSE:stop
177      ENDCASE
178    END
179;-------
180; lon and lat are not 1D and/or 2D arrays
181;-------
182    ELSE:stop
183  ENDCASE
184;
185;-------
186; double keyword
187;-------
188  if keyword_set(double) then BEGIN
189    lon = double(temporary(lon))
190    lat = double(temporary(lat))
191  ENDIF
192;
193; give back the right outparameters.
194;
195
196  CASE n_params() OF
197    8:BEGIN
198      in4 = temporary(lon)
199      in5 = temporary(lat)
200      in6 = temporary(jpi)
201      in7 = temporary(jpj)
202    END
203    5:BEGIN
204      in1 = temporary(lon)
205      in2 = temporary(lat)
206      in3 = temporary(jpi)
207      in4 = temporary(jpj)
208    END
209  ENDCASE
210;
211
212return
213END
Note: See TracBrowser for help on using the repository browser.