    Program f07adfe

!     F07ADF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: dgetrf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, info, lda, m, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:)
      Integer, Allocatable             :: ipiv(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: min
!     .. Executable Statements ..
      Write (nout,*) 'F07ADF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) m, n
      lda = m
      Allocate (a(lda,n),ipiv(n))

!     Read A from data file

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

!     Factorize A

!     The NAG name equivalent of dgetrf is f07adf
      Call dgetrf(m,n,a,lda,ipiv,info)

!     Print details of factorization

      Write (nout,*)
      Flush (nout)

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call x04caf('General',' ',m,n,a,lda,'Details of factorization',ifail)

!     Print pivot indices

      Write (nout,*)
      Write (nout,*) 'IPIV'
      Write (nout,99999) ipiv(1:min(m,n))

      If (info/=0) Write (nout,*) 'The factor U is singular'

99999 Format ((3X,7I11))
    End Program f07adfe
