    PROGRAM f07ggfe

!      F07GGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dlansp => f06rdf, dppcon, dpptrf, nag_wp, x02ajf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: anorm, rcond
       INTEGER                         :: i, info, j, n
       CHARACTER (1)                   :: uplo
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: ap(:), work(:)
       INTEGER, ALLOCATABLE            :: iwork(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07GGF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n

       ALLOCATE (ap(n*(n+1)/2),work(3*n),iwork(n))

!      Read A from data file

       READ (nin,*) uplo
       IF (uplo=='U') THEN
          READ (nin,*) ((ap(i+j*(j-1)/2),j=i,n),i=1,n)
       ELSE IF (uplo=='L') THEN
          READ (nin,*) ((ap(i+(2*n-j)*(j-1)/2),j=1,i),i=1,n)
       END IF

!      Compute norm of A
!      f06rdf is the NAG name equivalent of the LAPACK auxiliary dlansp
       anorm = dlansp('1-norm',uplo,n,ap,work)

!      Factorize A
!      The NAG name equivalent of dppcon is f07gdf
       CALL dpptrf(uplo,n,ap,info)

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

!         Estimate condition number

!         The NAG name equivalent of dppcon is f07ggf
          CALL dppcon(uplo,n,ap,anorm,rcond,work,iwork,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,*) 'A is not positive definite'
       END IF

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