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

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

improvements/corrections of some *.pro headers

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