      SUBROUTINE SPLINE(X,Y,N,YP1,YPN,Y2)
C      implicit DOUBLE PRECISION (a-h,o-z)
      PARAMETER (NMAX=20000)
      DIMENSION X(N),Y(N),Y2(N),U(NMAX)
      IF (YP1.GT..99E30) THEN
        Y2(1)=0.
        U(1)=0.
      ELSE
        Y2(1)=-0.5
        U(1)=(3./(X(2)-X(1)))*((Y(2)-Y(1))/(X(2)-X(1))-YP1)
      ENDIF
      DO 11 I=2,N-1
        SIG=(X(I)-X(I-1))/(X(I+1)-X(I-1))
        P=SIG*Y2(I-1)+2.
        Y2(I)=(SIG-1.)/P
        U(I)=(6.*((Y(I+1)-Y(I))/(X(I+1)-X(I))-(Y(I)-Y(I-1))
     *      /(X(I)-X(I-1)))/(X(I+1)-X(I-1))-SIG*U(I-1))/P
11    CONTINUE
      IF (YPN.GT..99E30) THEN
        QN=0.
        UN=0.
      ELSE
        QN=0.5
        UN=(3./(X(N)-X(N-1)))*(YPN-(Y(N)-Y(N-1))/(X(N)-X(N-1)))
      ENDIF
      Y2(N)=(UN-QN*U(N-1))/(QN*Y2(N-1)+1.)
      DO 12 K=N-1,1,-1
        Y2(K)=Y2(K)*Y2(K+1)+U(K)
12    CONTINUE
      RETURN
      END

c******************************************************************

      SUBROUTINE SPLINT(XA,YA,Y2A,N,X,Y)
C	implicit DOUBLE PRECISION (a-h,o-z)
      DIMENSION XA(N),YA(N),Y2A(N)
      KLO=1
      KHI=N
1     IF (KHI-KLO.GT.1) THEN
        K=(KHI+KLO)/2
        IF(XA(K).GT.X)THEN
          KHI=K
        ELSE
          KLO=K
        ENDIF
      GOTO 1
      ENDIF
      H=XA(KHI)-XA(KLO)
      IF (H.EQ.0.) PAUSE 'Bad XA input.'
      A=(XA(KHI)-X)/H
      B=(X-XA(KLO))/H
      Y=A*YA(KLO)+B*YA(KHI)+
     *      ((A**3-A)*Y2A(KLO)+(B**3-B)*Y2A(KHI))*(H**2)/6.
      RETURN
      END

      SUBROUTINE QSPLINT(XA,YA,Y2A,N,X,Y,KLO)
C      implicit DOUBLE PRECISION (a-h,o-z)
      DIMENSION XA(N),YA(N),Y2A(N)
      KHI=KLO+1
      H=XA(KHI)-XA(KLO)
      IF (H.EQ.0.) PAUSE 'Bad XA input.'
      A=(XA(KHI)-X)/H
      B=(X-XA(KLO))/H
      Y=A*YA(KLO)+B*YA(KHI)+
     *      ((A**3-A)*Y2A(KLO)+(B**3-B)*Y2A(KHI))*(H**2)/6.
      RETURN
      END

      SUBROUTINE LININT(XA,YA,N,X,Y)
C	implicit DOUBLE PRECISION (a-h,o-z)
      DIMENSION XA(N),YA(N)
      KLO=1
      KHI=N
1     IF (KHI-KLO.GT.1) THEN
        K=(KHI+KLO)/2
        IF(XA(K).GT.X)THEN
          KHI=K
        ELSE
          KLO=K
        ENDIF
      GOTO 1
      ENDIF
      H=XA(KHI)-XA(KLO)
C      IF (H.EQ.0.) PAUSE 'Bad XA input.'
      Y=(X-XA(KLO))/H*(YA(KHI)-YA(KLO)) + YA(KLO)
      RETURN
      END

      SUBROUTINE LOGINT(XA,YA,N,X,Y)
C	implicit DOUBLE PRECISION (a-h,o-z)
      DIMENSION XA(N),YA(N)
      DOUBLE PRECISION LXAKLO, LYAKLO
      KLO=1
      KHI=N
1     IF (KHI-KLO.GT.1) THEN
        K=(KHI+KLO)/2
        IF(XA(K).GT.X)THEN
          KHI=K
        ELSE
          KLO=K
        ENDIF
      GOTO 1
      ENDIF
       if (x .le. 0 .or. xa(klo) .le. 0 .or. ya(klo) .le. 0
     &  .or. xa(khi) .le. 0 .or. ya(khi) .le. 0) then
          y = 0
          return
       end if
      LXAKLO = LOG(XA(KLO))
      LYAKLO = LOG(YA(KLO))
      H=LOG(XA(KHI))-LXAKLO
C      IF (H.EQ.0.) PAUSE 'Bad XA input.'
      Y=(LOG(X)-LXAKLO)/H*(LOG(YA(KHI))-LYAKLO) + LYAKLO
      Y = EXP(Y)
      RETURN
      END

