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

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

corrections of some misspellings in some *.pro

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