    PROGRAM f07tufe

!      F07TUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x02ajf, ztrcon
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
       CHARACTER (1), PARAMETER        :: diag = 'N', norm = '1'
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: rcond
       INTEGER                         :: i, info, lda, n
       CHARACTER (1)                   :: uplo
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), work(:)
       REAL (KIND=nag_wp), ALLOCATABLE :: rwork(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07TUF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       lda = n
       ALLOCATE (a(lda,n),work(2*n),rwork(n))

!      Read A from data file

       READ (nin,*) uplo
       IF (uplo=='U') THEN
          READ (nin,*) (a(i,i:n),i=1,n)
       ELSE IF (uplo=='L') THEN
          READ (nin,*) (a(i,1:i),i=1,n)
       END IF

!      Estimate condition number
!      The NAG name equivalent of ztrcon is f07tuf
       CALL ztrcon(norm,uplo,diag,n,a,lda,rcond,work,rwork,info)

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

99999  FORMAT (1X,A,1P,E10.2)
    END PROGRAM f07tufe
