    Program f04ahfe

!     F04AHF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: f03aff, f04ahf, nag_wp, x02ajf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: d1, eps
      Integer                          :: i, id, ifail, ir, k, lda, ldaa, ldb, &
                                          ldbb, ldx, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), aa(:,:), b(:,:), bb(:,:),    &
                                          p(:), x(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'F04AHF Example Program Results'
      Write (nout,*)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n
      ir = 1
      lda = n
      ldaa = n
      ldb = n
      ldbb = n
      ldx = n
      Allocate (a(lda,n),aa(ldaa,n),b(ldb,ir),bb(ldbb,ir),p(n),x(ldx,ir))
      Read (nin,*)(aa(i,1:n),i=1,n)
      a(1:n,1:n) = aa(1:n,1:n)

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
!     Crout decomposition
      Call f03aff(n,eps,aa,ldaa,d1,id,p,ifail)

      Read (nin,*)(b(i,1:ir),i=1,n)
      eps = x02ajf()

      ifail = 0
!     Accurate solution of linear equations
      Call f04ahf(n,ir,a,lda,aa,ldaa,p,b,ldb,eps,x,ldx,bb,ldbb,k,ifail)

      Write (nout,*) ' Solution'
      Do i = 1, n
        Write (nout,99999) x(i,1:ir)
      End Do

99999 Format (1X,8F9.4)
    End Program f04ahfe
