NAG Library Manual, Mark 30.1
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program f11mffe

!     F11MFF Example Program Text

!     Mark 30.1 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: f11mdf, f11mef, f11mff, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Real (Kind=nag_wp), Parameter    :: one = 1.E0_nag_wp
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: flop, thresh
      Integer                          :: i, ifail, j, ldb, n, nnz, nnzl,      &
                                          nnzu, nrhs, nzlmx, nzlumx, nzumx
      Character (1)                    :: spec, trans
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:), b(:,:), lval(:), uval(:)
      Integer, Allocatable             :: icolzp(:), il(:), iprm(:),           &
                                          irowix(:), iu(:)
!     .. Executable Statements ..
      Write (nout,*) 'F11MFF Example Program Results'
      Flush (nout)
!     Skip heading in data file
      Read (nin,*)

!     Read order of matrix and number of right hand sides

      Read (nin,*) n, nrhs
      ldb = n

      Allocate (b(ldb,nrhs),icolzp(n+1),iprm(7*n))

!     Read the matrix A

      Read (nin,*) icolzp(1:n+1)

      nnz = icolzp(n+1) - 1

      Allocate (a(nnz),lval(8*nnz),uval(8*nnz),il(7*n+8*nnz+4),irowix(nnz),    &
        iu(2*n+8*nnz+1))

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

!     Read the right hand sides

      Do j = 1, nrhs
        Read (nin,*) b(1:n,j)
      End Do

!     Calculate COLAMD permutation

      spec = 'M'

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call f11mdf(spec,n,icolzp,irowix,iprm,ifail)

!     Factorise

      thresh = one
      ifail = 0
      nzlmx = 8*nnz
      nzlumx = 8*nnz
      nzumx = 8*nnz

      Call f11mef(n,irowix,a,iprm,thresh,nzlmx,nzlumx,nzumx,il,lval,iu,uval,   &
        nnzl,nnzu,flop,ifail)

!     Solve

      trans = 'N'

      ifail = 0
      Call f11mff(trans,n,iprm,il,lval,iu,uval,nrhs,b,ldb,ifail)

!     Output results
      Write (nout,*)
      Flush (nout)

      Call x04caf('G',' ',n,nrhs,b,ldb,'Solutions',ifail)

    End Program f11mffe