;+ ; ; @file_comments ; find the closest point of (P0) within a list of np1 points ; P1 which can be on a sphere ; ; @categories ; Maps ; ; @param p0lon {in}{required} {type=scalar} ; longitudes of point P0. ; ; @param p0lat {in}{required} {type=scalar} ; latitudes of point P0. ; ; @param neighlon {in}{optional} ; ; @param neighlat {in}{optional} ; ; @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 closest 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 ; ; @version ; $Id$ ; ;- FUNCTION neighbor, p0lon, p0lat, neighlon, neighlat $ , SPHERE=sphere, DISTANCE=distance, RADIANS=radians ; compile_opt idl2, strictarrsubs ; ; some checks IF n_elements(p0lon) NE 1 THEN ras = report('Sorry p0lon must be a scalar') p0lon = p0lon[0] IF n_elements(p0lat) NE 1 THEN ras = report('Sorry p0lat must be a scalar') p0lat = p0lat[0] nneig = n_elements(neighlon) IF n_elements(neighlat) NE nneig THEN $ ras = report('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