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

NAG FL Interface Introduction
Example description
    Program f04lefe

!     F04LEF Example Program Text

!     Mark 30.2 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: f01lef, f04lef, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: lambda, tol
      Integer                          :: ifail, job, n
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:), b(:), c(:), d(:), y(:), z(:)
      Integer, Allocatable             :: ipiv(:)
!     .. Executable Statements ..
      Write (nout,*) 'F04LEF Example Program Results'
      Write (nout,*)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n
      Allocate (a(n),b(n),c(n),d(n),y(n),z(n),ipiv(n))
      Read (nin,*) a(1:n)
      If (n>1) Then
        Read (nin,*) b(2:n)
        Read (nin,*) c(2:n)
      End If
      tol = 5.0E-5_nag_wp
      lambda = 0.0E0_nag_wp

!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call f01lef(n,a,lambda,b,c,tol,d,ipiv,ifail)

      If (ipiv(n)/=0) Then
        Write (nout,*) 'Matrix is singular or nearly singular'
        Write (nout,99999) 'Diagonal element', ipiv(n), 'is small'
      Else
        Read (nin,*) y(1:n)
        z(1:n) = y(1:n)
        job = 1

        ifail = 0
        Call f04lef(job,n,a,b,c,d,ipiv,y,tol,ifail)

        Write (nout,*)
        Write (nout,*) 'Solution vector for T*X = Y'
        Write (nout,99998) y(1:n)
        job = 2

        ifail = 0
        Call f04lef(job,n,a,b,c,d,ipiv,z,tol,ifail)

        Write (nout,*)
        Write (nout,*) 'Solution vector for transpose(T)*X = Y'
        Write (nout,99998) z(1:n)
      End If

99999 Format (1X,A,I4,A)
99998 Format (1X,5F9.3)
    End Program f04lefe