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

NAG FL Interface Introduction
Example description
    Program f04ccfe

!     F04CCF Example Program Text

!     Mark 30.1 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: f04ccf, nag_wp, x04dbf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: errbnd, rcond
      Integer                          :: i, ierr, ifail, ldb, n, nrhs
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: b(:,:), d(:), dl(:), du(:), du2(:)
      Integer, Allocatable             :: ipiv(:)
      Character (1)                    :: clabs(1), rlabs(1)
!     .. Executable Statements ..
      Write (nout,*) 'F04CCF Example Program Results'
      Write (nout,*)
      Flush (nout)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n, nrhs
      ldb = n
      Allocate (b(ldb,nrhs),d(n),dl(n-1),du(n-1),du2(n-2),ipiv(n))
!     Read A and B from data file

      Read (nin,*) du(1:n-1)
      Read (nin,*) d(1:n)
      Read (nin,*) dl(1:n-1)
      Read (nin,*)(b(i,1:nrhs),i=1,n)

!     Solve the equations AX = B for X

!     ifail: behaviour on error exit
!            =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 1
      Call f04ccf(n,nrhs,dl,d,du,du2,ipiv,b,ldb,rcond,errbnd,ifail)

      If (ifail==0) Then
!       Print solution, estimate of condition number and approximate
!       error bound

        ierr = 0
        Call x04dbf('General',' ',n,nrhs,b,ldb,'Bracketed',' ','Solution',     &
          'Integer',rlabs,'Integer',clabs,80,0,ierr)

        Write (nout,*)
        Write (nout,*) 'Estimate of condition number'
        Write (nout,99999) 1.0E0_nag_wp/rcond
        Write (nout,*)
        Write (nout,*) 'Estimate of error bound for computed solutions'
        Write (nout,99999) errbnd
      Else If (ifail==n+1) Then
!       Matrix A is numerically singular.  Print estimate of
!       reciprocal of condition number and solution
        Write (nout,*)
        Write (nout,*) 'Estimate of reciprocal of condition number'
        Write (nout,99999) rcond
        Write (nout,*)
        Flush (nout)

        ierr = 0
        Call x04dbf('General',' ',n,nrhs,b,ldb,'Bracketed',' ','Solution',     &
          'Integer',rlabs,'Integer',clabs,80,0,ierr)

      Else If (ifail>0 .And. ifail<=n) Then
!       The upper triangular matrix U is exactly singular.  Print
!       details of factorization
        Write (nout,*) 'Details of factorization'
        Write (nout,*)
        Write (nout,*) ' Second superdiagonal of U'
        Write (nout,99998) du2(1:n-2)
        Write (nout,*)
        Write (nout,*) ' First superdiagonal of U'
        Write (nout,99998) du(1:n-1)
        Write (nout,*)
        Write (nout,*) ' Main diagonal of U'
        Write (nout,99998) d(1:n)
        Write (nout,*)
        Write (nout,*) ' Multipliers'
        Write (nout,99998) dl(1:n-1)
        Write (nout,*)
        Write (nout,*) ' Vector of interchanges'
        Write (nout,99997) ipiv(1:n)
      Else
        Write (nout,99996) ifail
      End If

99999 Format (8X,1P,E9.1)
99998 Format (4(1X,'(',F7.4,',',F7.4,')',:))
99997 Format (1X,8I9)
99996 Format (1X,' ** F04CCF returned with IFAIL = ',I5)
    End Program f04ccfe