c=======================================================================
c purpose: for array xx of size n, find j such that xx(j) is nearest x


      subroutine nearest(xx,n,x,j) 2,1
      dimension xx(*)
      call locate(xx,n,x,k)
      j=k
      if(abs(x-xx(k+1)).lt.abs(x-xx(k))) j=k+1
      return
      end