    PROGRAM f07nufe

!      F07NUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x02ajf, zlansy => f06uff, zsycon, zsytrf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: anorm, rcond
       INTEGER                         :: i, info, lda, lwork, n
       CHARACTER (1)                   :: uplo
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), work(:)
       REAL (KIND=nag_wp), ALLOCATABLE :: rwork(:)
       INTEGER, ALLOCATABLE            :: ipiv(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07NUF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       lda = n
       lwork = 64*n
       ALLOCATE (a(lda,n),work(lwork),rwork(n),ipiv(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

!      Compute norm of A
!      f06uff is the NAG name equivalent of the LAPACK auxiliary zlansy
       anorm = zlansy('1-norm',uplo,n,a,lda,rwork)

!      Factorize A
!      The NAG name equivalent of zsytrf is f07nrf
       CALL zsytrf(uplo,n,a,lda,ipiv,work,lwork,info)

       WRITE (nout,*)
       IF (info==0) THEN

!         Estimate condition number
!         The NAG name equivalent of zsycon is f07nuf
          CALL zsycon(uplo,n,a,lda,ipiv,anorm,rcond,work,info)

          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
       ELSE
          WRITE (nout,*) 'The factor D is singular'
       END IF

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