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