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

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

some improvements and corrections in some .pro file according to
aspell and idldoc log file

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1;+
2;
3; @file_comments
4; find the closetest point of (P0) within a list of np1 points
5; P1 Which can be on a sphere
6;
7; @categories Maps
8;
9; @param p0lon {in}{required}
10; scalar. longitudes of point P0.
11;
12; @param p0lat {in}{required}
13; scalar. latitudes of point P0.
14;
15; @param neighlon {in}{optional}
16;
17; @param neighlat {in}{optional}
18;
19; @keyword RADIANS
20; if set, inputs and angular outputs are in radians, otherwise degrees.
21;
22; @keyword DISTANCE
23; dis, to get back the distances between P0 and the np1 points P1 in the
24; variable dis.
25;
26; @keyword SPHERE to activate if points are located on a sphere.
27;
28; @returns
29; index giving the P1[index] point that is the closest point of (P0)
30;
31; @examples
32; IDL> print, neighbor(-105.15,40.02,[-0.07,100,50],[51.30,20,0], $
33; IDL> distance=dis)
34;                  0
35; IDL> print, dis
36;             105.684      206.125      160.228
37;
38; @history
39; Sebastien Masson (smasson\@lodyc.jussieu.fr)
40;                  October 2003
41;
42; @version $Id$
43;
44;-
45FUNCTION neighbor, p0lon, p0lat, neighlon, neighlat, sphere = sphere, distance = distance, radians = radians
46;
47  compile_opt idl2, strictarrsubs
48;
49; somme checks
50  IF  n_elements(p0lon) NE 1 THEN MESSAGE, 'Sorry p0lon must be a scalar'
51  p0lon = p0lon[0]
52  IF  n_elements(p0lat) NE 1 THEN MESSAGE, 'Sorry p0lat must be a scalar'
53  p0lat = p0lat[0]
54  nneig = n_elements(neighlon)
55  IF  n_elements(neighlat) NE nneig  THEN $
56    MESSAGE, 'neighlon and neighlat must have the same number of elements'
57; distance between P0 and the others points
58  IF keyword_set(sphere) THEN BEGIN
59    IF sphere NE 1 THEN radius = sphere
60    distance = Map_nPoints(p0lon, p0lat, neighlon, neighlat $
61                       , radius = radius, radians = radians)
62  ENDIF ELSE BEGIN
63    distance = (neighlon-p0lon)^2+(neighlat-p0lat)^2
64    IF arg_present(distance) THEN distance = sqrt(distance)
65  ENDELSE
66  RETURN, where(distance EQ min(distance))
67END
Note: See TracBrowser for help on using the repository browser.