    PROGRAM f07jafe

!      F07JAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dptsv, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: info, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: b(:), d(:), e(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07JAF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n

       ALLOCATE (b(n),d(n),e(n-1))

!      Read the lower bidiagonal part of the tridiagonal matrix A and
!      the right hand side b from data file

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

!      Solve the equations Ax = b for x

!      The NAG name equivalent of dptsv is f07jaf
       CALL dptsv(n,1,d,e,b,n,info)

       IF (info==0) THEN

!         Print solution

          WRITE (nout,*) 'Solution'
          WRITE (nout,99999) b(1:n)

!         Print details of factorization

          WRITE (nout,*)
          WRITE (nout,*) 'Diagonal elements of the diagonal matrix D'
          WRITE (nout,99999) d(1:n)
          WRITE (nout,*)
          WRITE (nout,*) 'Sub-diagonal elements of the Cholesky factor L'
          WRITE (nout,99999) e(1:n-1)

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

99999  FORMAT (1X,7F11.4)
99998  FORMAT (1X,A,I3,A)
    END PROGRAM f07jafe
