    PROGRAM f04agfe

!      F04AGF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f03aef, f04agf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: d1
       INTEGER                         :: i, id, ifail, ir, lda, ldb, ldx, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), p(:), x(:,:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F04AGF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       ir = 1
       lda = n
       ldb = n
       ldx = n
       ALLOCATE (a(lda,n),b(ldb,ir),p(n),x(ldx,ir))
       READ (nin,*) (a(i,1:n),i=1,n), (b(i,1:ir),i=1,n)

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
!      Cholesky decomposition
       CALL f03aef(n,a,lda,p,d1,id,ifail)

!      Approximate solution of linear equations
       ifail = 0
       CALL f04agf(n,ir,a,lda,p,b,ldb,x,ldx)

       WRITE (nout,*) ' Solution'
       DO i = 1, n
          WRITE (nout,99999) x(i,1:ir)
       END DO

99999  FORMAT (1X,8F9.4)
    END PROGRAM f04agfe
