[UP]


Manual Reference Pages  - closest (3)

NAME

closest(3f) - [M_math:geometry] find the data point that is closest to the target point

CONTENTS

Synopsis
Description
Options
Returns
Example

SYNOPSIS

function closest(xtarget,ytarget,x,y) result(location)

   real, dimension(:), intent(in)  :: x, y
   real                            :: xtarget, ytarget
   integer                         :: location

DESCRIPTION

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.

OPTIONS

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

RETURNS

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

EXAMPLE


closest (3) March 11, 2021
Generated by manServer 1.08 from b038fe9c-dac6-4087-bac2-9cc5aedb5933 using man macros.