    PROGRAM f03aefe

!      F03AEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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