closest(3f) - [M_math:geometry] find the data point that is closest to the target point
Synopsis
Description
Options
Returns
Example
function closest(xtarget,ytarget,x,y) result(location)
real, dimension(:), intent(in) :: x, y real :: xtarget, ytarget integer :: location
Given a set of X and Y values and a target point, find the index of the closest point to the target from the points described by the <X,Y> values. The X and Y arrays are assumed to be the same size.
XTARGET X coordinate of target point YTARGET Y coordinate of target point X array of X values that defines a set of points Y array of Y values that defines a set of points
Sample program
program demo_closest use M_math, only : closest implicit none real,allocatable :: x(:),y(:) real :: x1, y1 integer :: id x=[ 11.0, 100.0, -22.34, 26.4, -50.66 ] y=[-21.0, 150.0, -82.00, 40.0, 350.00 ] x1=30.0 y1=44.0 id=closest(x1,y1,x,y) write(*,*)Closest point: , x(id), y(id), at index ,id end program demo_closest
Nemo Release 3.1 | closest (3) | February 23, 2025 |