Program f11dbfe

!     F11DBF Example Program Text

!     Mark 26.1 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: f11daf, f11dbf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: dtol
      Integer                          :: i, ifail, la, lfill, liwork, n, nnz, &
                                          nnzc, npivm
      Character (1)                    :: check, milu, pstrat, trans
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:), x(:), y(:)
      Integer, Allocatable             :: icol(:), idiag(:), ipivp(:),         &
                                          ipivq(:), irow(:), istr(:), iwork(:)
!     .. Executable Statements ..
      Write (nout,*) 'F11DBF Example Program Results'
      Write (nout,*)

!     Skip heading in data file

      Read (nin,*)

!     Read order of matrix and number of nonzero entries

      Read (nin,*) n
      Read (nin,*) nnz
      la = 2*nnz
      liwork = 7*n + 2
      Allocate (a(la),x(n),y(n),icol(la),idiag(n),ipivp(n),ipivq(n),irow(la),  &
        istr(n+1),iwork(liwork))

!     Read the matrix A

      Do i = 1, nnz
        Read (nin,*) a(i), irow(i), icol(i)
      End Do

!     Read the vector y

      Read (nin,*) y(1:n)

!     Calculate LU factorization

      lfill = -1
      dtol = 0.E0_nag_wp
      pstrat = 'C'
      milu = 'N'

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call f11daf(n,nnz,a,la,irow,icol,lfill,dtol,pstrat,milu,ipivp,ipivq,     &
        istr,idiag,nnzc,npivm,iwork,liwork,ifail)

!     Check value of npivm

      If (npivm>0) Then

        Write (nout,*) 'Factorization is not complete'

      Else

!       Solve P L D U x = y

        trans = 'N'
        check = 'C'

        ifail = 0
        Call f11dbf(trans,n,a,la,irow,icol,ipivp,ipivq,istr,idiag,check,y,x,   &
          ifail)

!       Output results

        Write (nout,*) ' Solution of linear system'
        Write (nout,'(E16.4)') x(1:n)

      End If

    End Program f11dbfe