    PROGRAM f07jufe

!      F07JUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x02ajf, zlanht => f06upf, zptcon, zpttrf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: anorm, rcond
       INTEGER                         :: info, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: e(:)
       REAL (KIND=nag_wp), ALLOCATABLE :: d(:), rwork(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07JUF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n

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

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

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

!      Compute the 1-norm of A
!      f06upf is the NAG name equivalent of the LAPACK auxiliary zlanht
       anorm = zlanht('1-norm',n,d,e)

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

       IF (info==0) THEN

!         Estimate the condition number of A
!         The NAG name equivalent of zptcon is f07juf
          CALL zptcon(n,d,e,anorm,rcond,rwork,info)

!         Print the estimated condition number

          IF (rcond>=x02ajf()) THEN
             WRITE (nout,99999) 'Estimate of condition number = ', &
                1.0E0_nag_wp/rcond
          ELSE
             WRITE (nout,99999) 'A is singular to working precision. RCOND = ' &
                , rcond
          END IF

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

99999  FORMAT (1X,A,1P,E10.2)
99998  FORMAT (1X,A,I3,A)
    END PROGRAM f07jufe
