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

NAG AD Library Introduction
Example description
    Program f07ce_p0w_fe

!     F07CE_P0W_F Example Program Text
!     Mark 30.3 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use iso_c_binding, Only: c_ptr
      Use nagad_library, Only: f07cd_p0w_f, f07ce_p0w_f
      Use nag_library, Only: nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Type (c_ptr)                     :: ad_handle
      Integer                          :: i, ifail, n, nrhs
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: d(:), dl(:), du(:), du2(:), x(:,:)
      Integer, Allocatable             :: ipiv(:)
!     .. Executable Statements ..
      Write (nout,*) 'F07CE_P0W_F Example Program Results'
      Write (nout,*)
      Flush (nout)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n, nrhs
      Allocate (x(n,nrhs),d(n),dl(n-1),du(n-1),du2(n-2),ipiv(n))

!     Read the tridiagonal matrix A from data file
      Read (nin,*) du(1:n-1)
      Read (nin,*) d(1:n)
      Read (nin,*) dl(1:n-1)

!     Read the right hand matrix B
      Read (nin,*)(x(i,1:nrhs),i=1,n)

!     Factorize the tridiagonal matrix A
      ifail = 0
      Call f07cd_p0w_f(ad_handle,n,dl,d,du,du2,ipiv,ifail)

!     Solve the equations AX = B
      ifail = 0
      Call f07ce_p0w_f(ad_handle,'N',n,nrhs,dl,d,du,du2,ipiv,x,n,ifail)

!     Print the solution
      ifail = 0
      Call x04caf('General',' ',n,nrhs,x,n,'Solution(s)',ifail)

    End Program f07ce_p0w_fe