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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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