        FUNCTION NEIGH( X0, X, NX )

C       Find the index of the nearest neighbor to a point X0
C       in a vector X with NX elements.

        REAL X( NX )

        NEIGH = 1
        DIST  = 1.0E20

        DO IX = 1, NX
           IF ( ABS( X( IX ) - X0 ) .LT. DIST ) THEN
              NEIGH = IX
              DIST = ABS( X( IX ) - X0 )
           ENDIF
        END DO
 
        RETURN
        END
