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

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

improvements/corrections of some *.pro headers + replace some message by some report

  • 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
[242]8; 2) given longitude and latitude arrays, get their dimensions and make
[136]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;
[136]24; @param in1 {in}{required}
[163]25; Case 1: the name of the netcdf file
[242]26; Case 2: 1d or 2d arrays defining longitudes and latitudes.
[163]27; Out: the variable that will contain the longitudes
[59]28;
[136]29; @param in2 {in}{required}
[163]30; Case 1: the name of the variable that contains the longitude in the NetCDF file
[242]31; Case 2: 1d or 2d arrays defining longitudes and latitudes.
[163]32;         Note that these arrays are also outputs and can therefore be modified.
33; Out: the variable that will contain the latitudes
[136]34;
35; @param in3 {in}{required}
[163]36; Case 1: the name of the variable that contains the latitude in the NetCDF file
37; Case 2: the number of points in the longitudinal direction.
[136]38;
39; @param in4 {out}
[163]40; Case 1: the number of points in the longitudinal direction
41; Case 2: the number of points in the latitudinal direction
[136]42;
43; @param in5 {out}
[163]44; Case 1: the number of points in the latitudinal direction
45; Case 2: 1 or 2 to specify if lon and lat should be 1D (jpi or jpj)
46; arrays or 2D arrays (jpi,jpj). Note that of  n_dimensions = 1, then the
[238]47; grid must be regular (each longitude must be the same for all latitudes
48; and each latitude should be the same for all longitudes).
[136]49;
50; @param in6 {out}
51; the variable that will contain the longitudes
52;
53; @param in7 {out}
54; the variable that will contain the latitudes
55;
56; @param in8 {out}
57; 1 or 2 to specify if lon and lat should be 1D (jpi or jpj)
58;
59; @keyword DOUBLE
60; use double precision to perform the computation
61;
[118]62; @examples
63;
64; 1) IDL> ncdf_get_gridparams, 'coordinates_ORCA_R05.nc', 'glamt', 'gphit' $
[59]65;            , olon, olat, jpio, jpjo, 2
66;
[118]67; 2) IDL> ncdf_get_gridparams, olon, olat, jpio, jpjo, 2
[59]68;
[101]69; @history
[118]70;  November 2005: Sebastien Masson (smasson\@lodyc.jussieu.fr)
71;
[231]72; @version
73; $Id$
[118]74;
[59]75;-
76;
77PRO get_gridparams, in1,   in2,   in3,     in4, in5, in6, in7, in8, DOUBLE = double
78;                  file, lonname, latname, lon, lat, jpi, jpj, n_dimensions
79;                   lon,   lat,   jpi,     jpj, n_dimensions
80;
[114]81  compile_opt idl2, strictarrsubs
82;
[59]83  CASE n_params() OF
84    8:BEGIN
85; get longitude and latitude
[118]86      IF file_test(in1) EQ 0 THEN BEGIN
[236]87        ras = report('file ' + in1 + ' does not exist')
[59]88        stop
89      ENDIF
90      cdfido = ncdf_open(in1)
91      ncdf_varget, cdfido, in2, lon
92      ncdf_varget, cdfido, in3, lat
[118]93      ncdf_close, cdfido
[59]94      n_dimensions = in8
95    END
[118]96    5:BEGIN
[59]97      lon = temporary(in1)
98      lat = temporary(in2)
99      n_dimensions = in5
100    END
[118]101    ELSE:BEGIN
[236]102      ras = report('Bad number of input parameters')
[59]103      stop
104    end
105  ENDCASE
106;
107  sizelon = size(lon)
108  sizelat = size(lat)
[118]109  CASE 1 OF
[59]110;-------
111; lon and lat are 1D arrays
112;-------
[118]113    sizelon[0] EQ 1 AND sizelat[0] EQ 1:BEGIN
[59]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]118      CASE n_dimensions OF
[59]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;-------
[118]131    sizelon[0] EQ 2 AND sizelat[0] EQ 1:BEGIN
[59]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
[118]137      CASE n_dimensions OF
138        1:BEGIN
139          IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN
[236]140            ras = report('Longitudes are not the same for all latitudes, impossible to extract a 1D array of the longitudes')
[59]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;-------
[118]152    sizelon[0] EQ 1 AND sizelat[0] EQ 2:BEGIN
[59]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
[118]158      CASE n_dimensions OF
159        1:BEGIN
160          IF array_equal(lat, replicate(1, jpi) # lat[0, *]) NE 1 THEN BEGIN
[236]161            ras = report('Latitudes are not the same for all longitudes, impossible to extract a 1D array of the latitudes')
[59]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;-------
[118]173    sizelon[0] EQ 2 AND sizelat[0] EQ 2:BEGIN
[59]174; get jpi and jpj
175      IF array_equal(sizelon[1:2], sizelat[1:2]) NE 1 THEN stop
176      jpi = sizelon[1]
[118]177      jpj = sizelon[2]
[59]178; make sure that lon and lat have the good number of dimensions
[118]179      CASE n_dimensions OF
180        1:BEGIN
181          IF array_equal(lon, lon[*, 0] # replicate(1, jpj)) NE 1 THEN BEGIN
[236]182            ras = report('Longitudes are not the same for all latitudes, impossible to extract a 1D array of the longitudes')
[59]183            stop
184          ENDIF
185          lon = lon[*, 0]
[118]186          IF array_equal(lat, replicate(1, jpi) # reform(lat[0, *])) NE 1 THEN BEGIN
[236]187            ras = report('Latitudes are not the same for all longitudes, impossible to extract a 1D array of the latitudes')
[59]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;-------
[236]199    ELSE: BEGIN
200             ras = report('Longitudes and latitudes are not 1D and/or 2D arrays')
201             stop
202          END
[59]203  ENDCASE
204;
205;-------
206; double keyword
207;-------
[118]208  if keyword_set(double) then BEGIN
[59]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.