      SUBROUTINE DECOM3(IOPT,A,B,N)
C     
C     IOPT=0 => DO DECOMPOSITION AND FORWARD-BACKWARD SUBSTITUTION
C     1 => DO ONLY DECOMPOSITION
C     2 => DO ONLY FBS
C     
C     A PROGRAM TO PERFORM LU-DECOMPOSITION OF SYMMETRIC POSITIVE DEFINITE
C     MATRIX
C     
CDEP  
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      DIMENSION A(N,N),B(N)
C     
C..    PERFORM DECOMPOSITION A TO L*U IN EQUATION: A*X=B <=> L*U*X=B
C     
 100  CONTINUE
      IF (IOPT.EQ.2) GOTO 200
      DO 1 K=1,N-1
         RECIP=1/A(K,K)
         DO 11 I=K+1,N
            T=A(I,K)*RECIP
            DO 111 J=I,N
               A(J,I)=A(J,I)-T*A(J,K)
 111        CONTINUE
 11      CONTINUE
 1    CONTINUE
 200  CONTINUE
C     
      IF (IOPT.EQ.1) RETURN
C     
C..    SOLVE: L*Y=B
C     
      DO 22 I=2,N
         T=B(I)
         DO 2 K=1,I-1
            T=T-A(I,K)*B(K)/A(K,K)
 2       CONTINUE
         B(I)=T
 22   CONTINUE
      B(N)=B(N)/A(N,N)
C     
C..    SOLVE: U*X=Y
C     
      DO 4 I=N-1,1,-1
         T=B(I)
         DO 3 K=I+1,N
            T=T-A(K,I)*B(K)
 3       CONTINUE
         B(I)=T/A(I,I)
 4    CONTINUE
C..   END  
      RETURN
      END   
