subroutine closest_point_brute ( m, nr, r, s, near_index, & near_dist ) c*********************************************************************72 c cc closest_point_brute() finds the nearest R point to each S point. c c Discussion: c c We are given R, a set of NR points in M dimensions. c c We are given S, a point in M dimensions. c c We seek the index J of the point R(J) c which is nearest to S over all points in R. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 15 August 2024 c c Author: c c John Burkardt c c Input: c c integer M, the spatial dimension. c c integer NR, the number of data points. c c double precision R(M,NR), the data points. c c double precision S(M), the sample point. c c Output: c c integer near_index, the index of the nearest data point. c c double precision near_dist, the distance of the nearest data point. c implicit none integer m integer nr double precision dist_sq integer i integer jr double precision near_dist integer near_index double precision r(m,nr) double precision s(m) near_dist = huge ( near_dist ) near_index = -1 do jr = 1, nr dist_sq = 0.0D+00 do i = 1, m dist_sq = dist_sq + ( r(i,jr) - s(i) ) ** 2 end do if ( dist_sq < near_dist ) then near_dist = dist_sq near_index = jr end if end do near_dist = sqrt ( near_dist ) return end