;+ ; ; @file_comments ;find the closetest point of (P0) within a list of np1 points ;P1 Which can be on a sphere ; ; @categories Maps ; ; @examples ; IDL> Result = neighbor(lon0, lat0, lon1, lat1) ; ;@param p0lon {in}{required} scalar. longitudes of point P0. ;@param p0lat {in}{required} scalar. latitudes of point P0. ; ; @keyword RADIANS if set, inputs and angular outputs are in radians, otherwise ;degrees. ; @keyword DISTANCE dis, to get back the distances between P0 and the np1 ; points P1 in the variable dis. ; @keyword /SPHERE to activate if points are located on a sphere. ; ; @returns ; index giving the P1[index] point that is the closetest point ; of (P0) ; ; @examples ; IDL> print, neighbor(-105.15,40.02,[-0.07,100,50],[51.30,20,0], $ ; distance=dis) ; 0 ; IDL> print, dis ; 105.684 206.125 160.228 ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; October 2003 ;- FUNCTION neighbor, p0lon, p0lat, neighlon, neighlat, sphere = sphere, distance = distance, radians = radians ; ; somme checks IF n_elements(p0lon) NE 1 THEN MESSAGE, 'Sorry p0lon must be a scalar' p0lon = p0lon[0] IF n_elements(p0lat) NE 1 THEN MESSAGE, 'Sorry p0lat must be a scalar' p0lat = p0lat[0] nneig = n_elements(neighlon) IF n_elements(neighlat) NE nneig THEN $ MESSAGE, 'neighlon and neighlat must have the same number of elements' ; distance between P0 and the others points IF keyword_set(sphere) THEN BEGIN IF sphere NE 1 THEN radius = sphere distance = Map_nPoints(p0lon, p0lat, neighlon, neighlat $ , radius = radius, radians = radians) ENDIF ELSE BEGIN distance = (neighlon-p0lon)^2+(neighlat-p0lat)^2 IF arg_present(distance) THEN distance = sqrt(distance) ENDELSE RETURN, where(distance EQ min(distance)) END