    PROGRAM f03bnfe

!      F03BNF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f03bnf, nag_wp, x04daf, zgetrf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       REAL (KIND=nag_wp), PARAMETER   :: two = 2.0_nag_wp
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       COMPLEX (KIND=nag_wp)           :: d
       INTEGER                         :: i, ifail, info, lda, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:)
       INTEGER                         :: id(2)
       INTEGER, ALLOCATABLE            :: ipiv(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          aimag, real
!      .. Executable Statements ..
       WRITE (nout,*) 'F03BNF Example Program Results'

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

       READ (nin,*) n
       lda = n
       ALLOCATE (a(lda,n),ipiv(n))

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

!      LU Factorize A
!      The NAG name equivalent of zgetrf is f07arf
       CALL zgetrf(n,n,a,lda,ipiv,info)
       WRITE (nout,*)
       FLUSH (nout)

       ifail = 0
       CALL x04daf('g','n',n,n,a,lda,'Array A after factorization',ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Pivots'
       WRITE (nout,99999) ipiv(1:n)
       WRITE (nout,*)
       FLUSH (nout)

       ifail = 0
       CALL f03bnf(n,a,lda,ipiv,d,id,ifail)

       WRITE (nout,99998) d, id
       WRITE (nout,*)
       WRITE (nout,99997) two**id(1)*real(d), two**id(2)*aimag(d)

99999  FORMAT (1X,8(1X,I13))
99998  FORMAT (1X,'D = (',F13.5,',',F13.5,'), ID = (',I0,', ',I0,')')
99997  FORMAT (1X,'Value of determinant = (',E13.5,',',E13.5,')')
    END PROGRAM f03bnfe
