      SUBROUTINE SPLINE(S,X,Y,N,IN,T,IL,VL,IU,VU,E,U)                   00000100
C     X,Y ARRAY OF IND. & DEPEN. VAR.,S THE ARGUMENT TO BE INTERPOLATED 00000200
C     T THE INTERPOLATED VALUE,N THE DIMENSION OF (X,Y)                 00000300
C     IN=1 DETERMINES SPLINE FUNC,IN=2 INTERPOLATES SPLINE FNC          00000400
C     IL,IU=1 PARABOLIC RUNOUT CONDITIONS AT LOWER & UPPER BOUND.       00000500
C     IL,IU=2 1ST DERIVATIVE  (VL,VU) AT LOWER OR UPPER BOUND RESP.     00000600
C     IL,IU=3 2ND DERIVATIVE  (VL,VU) AT LOWER OR UPPER BOUND RESP.     00000700
      DIMENSION X(1), Y(1), E(1),U(1)                                   00000800
      IF(IN.EQ.2) GO TO 40                                              00000900
      N1=N-1                                                            00001000
      B1=X(2)-X(1)                                                      00001100
      C1=(Y(2)-Y(1))/B1                                                 00001200
      GO TO (12,14,16),IL                                               00001300
   12 E(1)=1.0                                                          00001400
      U(1)=0.0                                                          00001500
      GO TO 18                                                          00001600
   14 E(1)=-.5                                                          00001700
      U(1)=(C1-VL)/2./B1                                                00001800
      GO TO 18                                                          00001900
   16 E(1)=0.                                                           00002000
      U(1)=VL/12.                                                       00002100
   18 DO 20 J=2,N1                                                      00002200
      B2=X(J+1)-X(J)                                                    00002300
      C2=(Y(J+1)-Y(J))/B2                                               00002400
      B=X(J+1)-X(J-1)                                                   00002500
      D=(C2-C1)/B                                                       00002600
      C=B1/B                                                            00002700
      B1=B2                                                             00002800
      C1=C2                                                             00002900
      P=C*E(J-1)+2.0                                                    00003000
      E(J)=(C-1.0)/P                                                    00003100
   20 U(J)=(D-C*U(J-1))/P                                               00003200
      IF(IU.EQ.2) GO TO 24                                              00003300
      IF(IU.EQ.1) E(N)=U(N1)/(1.0-E(N1))                                00003400
      IF(IU.EQ.3) E(N)=VU/12.0                                          00003500
      GO TO 26                                                          00003600
   24 C2=VU-(Y(N)-Y(N1))/(X(N)-X(N1))                                   00003700
      E(N)=(C2/(X(N)-X(N1))-U(N1))/(2.0E0+E(N1))                        00003800
   26 DO 30 KK=1,N1                                                     00003900
      K=N-KK                                                            00004000
      E(K)=E(K)*E(K+1)+U(K)                                             00004100
      IF(IN.EQ.0) GO TO 30                                              00004200
C     ARRAY U CONTAINS THE DERIVATIVES OF THE SPLINE FUNCTION AT THE    00004300
C        KNOTS                                                          00004400
      B2=X(K+1)-X(K)                                                    00004500
      U(K)=(Y(K+1)-Y(K))/B2-B2*(E(K)*2+E(K+1))                          00004600
   30 CONTINUE                                                          00004700
      IF(IN.EQ.0) GO TO 40                                              00004800
      B2=X(N)-X(N1)                                                     00004900
      U(N)=(E(N1)+2.0D0*E(N))*B2+(Y(N)-Y(N1))/B2                        00005000
   40 IF (X(1).GT.X(N)) GO TO 50                                        00005100
      IDIR=0                                                            00005200
      MLB=0                                                             00005300
      MUB=N                                                             00005400
      GO TO 60                                                          00005500
   50 IDIR=1                                                            00005600
      MLB=N                                                             00005700
      MUB=0                                                             00005800
   60 IF (S.GE.X(MUB+IDIR)) GO TO 100                                   00005900
      IF (S.LE.X(MLB+1-IDIR)) GO TO 110                                 00006000
      ML=MLB                                                            00006100
      MU=MUB                                                            00006200
      GO TO 80                                                          00006300
   70 IF (IABS(MU-ML).LE.1) GO TO 120                                   00006400
   80 MAV=(ML+MU)/2                                                     00006500
      IF(S.LT.X(MAV)) MU=MAV                                            00006600
      IF(S.GE.X(MAV)) ML=MAV                                            00006700
      GO TO 70                                                          00006800
  100 MU=MUB+2*IDIR                                                     00006900
      GO TO 130                                                         00007000
  110 MU=MLB+2*(1-IDIR)                                                 00007100
      GO TO 130                                                         00007200
  120 MU=MU+IDIR                                                        00007300
  130 T=(E(MU-1)*((X(MU)-S)**3)+E(MU)*((S-X(MU-1))**3)+                 00007400
     1   (Y(MU-1)-E(MU-1)*((X(MU)-X(MU-1))**2))*(X(MU)-S)+              00007500
     2 (Y(MU)-E(MU)*((X(MU)-X(MU-1))**2))*(S-X(MU-1)))/(X(MU)-X(MU-1))  00007600
      RETURN                                                            00007700
      END                                                               00007800
