%N nearest %F $MIR/src/subs/nearest.for
%D Calculate the nearest neighbour in a list of 2D coordinates
%P rjs
%: miscellaneous
%B
        subroutine nearest(x,y,indx,n,ip,mnmax)

        implicit none
        integer n
        real x(n),y(n),mnmax(n,5)
        integer indx(n),ip(n,5)

  Determine nearest neighbours. The input arrays x,y, contain the
  coordinates of points. On output, indx contains the index of the
  closest other point.

  Inputs:
    n          Number of points.
    x,y        The coordinates of the points.
  Output:
    indx       An integer array, giving the index of the nearest neighbour.
               The nearest point to x(i),y(i) is x(indx(i)),y(indx(i)).
  Scratch:
    mnmax      Real scratch array of size 5*n.
    ip         Integer scratch array of size 5*n.
