    Program f04agfe

!     F04AGF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
