    Program f03aefe

!     F03AEF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: f03aef, 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, lda, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), p(:)
!     .. Executable Statements ..
      Write (nout,*) 'F03AEF Example Program Results'

!     Skip heading in data file
      Read (nin,*)

      Read (nin,*) n
      lda = n
      Allocate (a(lda,n),p(n))

      Read (nin,*)(a(i,1:n),i=1,n)

      ifail = 0
      Call f03aef(n,a,lda,p,d1,id,ifail)

      Write (nout,*)
      Write (nout,*) 'Array A after factorization'

      Do i = 1, n
        Write (nout,99999) a(i,1:n)
      End Do

      Write (nout,*)
      Write (nout,*) 'Array P'
      Write (nout,99999) p(1:n)
      Write (nout,*)
      Write (nout,99998) 'D1 = ', d1, '     ID = ', id
      Write (nout,*)
      Write (nout,99998) 'Value of determinant = ', d1*2.0E0_nag_wp**id

99999 Format (1X,8F9.4)
99998 Format (1X,A,F9.4,A,I2)
    End Program f03aefe
