C **********************************************************************
C *                                                                    *
C *                                                                    *
       SUBROUTINE THOMAS(N)
C *                                                                    *
C *                                                                    *
C **********************************************************************
C
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      INTEGER*4 NMAX
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      PARAMETER (NMAX=10000)
      COMMON/COEFTHOM/A(NMAX),B(NMAX),C(NMAX),D(NMAX)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      COMMON/RESULTF/FI(NMAX)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      DIMENSION BPRIME(NMAX),DPRIME(NMAX)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      BPRIME(2)=B(2)-A(2)*C(1)/B(1)
      DPRIME(2)=D(2)-A(2)*D(1)/B(1)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      DO 10 J=3,N
         BPRIME(J)=B(J)-A(J)*C(J-1)/BPRIME(J-1)
         DPRIME(J)=D(J)-A(J)*DPRIME(J-1)/BPRIME(J-1)
 10   CONTINUE
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      FI(N)=DPRIME(N)/BPRIME(N)
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7--
      DO 20 J=N-1,2,-1
         FI(J)=( DPRIME(J) -C(J)*FI(J+1) ) / BPRIME(J)
 20   CONTINUE
C---+---1-----+----2----+----3----+----4----+----5----+----6----+----7--
      FI(1)= ( D(1) -C(1)* FI(2) ) /B(1)
      RETURN
      END
