C**********************************************************************
C     SUBROUTINE INTRP1() PERFORMING CUBIC INTERPOLATION ON 1
C     DIMENSIONAL EQUALLY SPACED GRID.  RETURNS INTERPOLATED VALUE
C     AND FIRST AND SECOND PARTIAL DERIVATIVES IN Y, YX, YXX.
C     INTERPOLATION INSURES CONTINUOUS Y AND YX ACROSS GRIDPOINTS.
C     USES CUBIC EXTRAPOLATION IF BEYOND GRID RANGE (DANGEROUS!).
C
C     AUTHOR: R. JONES  3 FEB 1989
C**********************************************************************

      SUBROUTINE INTRP1(X,XMIN,XMAX,N,GRID,Y,YX,YXX)

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      DIMENSION GRID(0:N)

      H  = ( XMAX - XMIN ) / N
      XX = ( X    - XMIN ) / H
      NN = INT ( XX )
C     Next line insures all elements of GRID used are in range 0-N
      NN = MAX ( 1 , MIN ( N - 2, NN ) )
      ZZ = XX - NN

      D = GRID(NN)
      C = .5D0 * ( GRID(NN+1) - GRID(NN-1) )
      A = C + 2D0 * D - 2D0 * GRID(NN+1) + .5D0 * (GRID(NN+2)-GRID(NN))
      B = GRID(NN+1) - A - C - D

      Y   = (( A * ZZ + B ) * ZZ + C ) * ZZ + D
      YX  = (( 3D0 * A * ZZ + 2D0 * B ) * ZZ + C ) / H
      YXX = ( 6D0 * A * ZZ + 2D0 * B ) / ( H * H )

      RETURN
      END
