    PROGRAM f07jefe

!      F07JEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dpttrf, dpttrs, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, info, ldb, n, nrhs
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: b(:,:), d(:), e(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07JEF Example Program Results'
       WRITE (nout,*)
       FLUSH (nout)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, nrhs
       ldb = n
       ALLOCATE (b(ldb,nrhs),d(n),e(n-1))

!      Read the upper bidiagonal part of the tridiagonal matrix A from
!      data file

       READ (nin,*) e(1:n-1)
       READ (nin,*) d(1:n)

!      Read the right hand matrix B

       READ (nin,*) (b(i,1:nrhs),i=1,n)

!      Factorize the tridiagonal matrix A
!      The NAG name equivalent of dpttrf is f07jdf
       CALL dpttrf(n,d,e,info)

       IF (info==0) THEN

!         Solve the equations AX = B
!         The NAG name equivalent of dpttrs is f07jef
          CALL dpttrs(n,nrhs,d,e,b,ldb,info)

!         Print the solution

!         ifail: behaviour on error exit
!                =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
          ifail = 0
          CALL x04caf('General',' ',n,nrhs,b,ldb,'Solution(s)',ifail)

       ELSE
          WRITE (nout,99999) 'The leading minor of order ', info, &
             ' is not positive definite'
       END IF

99999  FORMAT (1X,A,I3,A)
    END PROGRAM f07jefe
