```    Program f07ca_a1w_fe

!     F07CA_A1W_F Example Program Text
!     Mark 27 Release. NAG Copyright 2019.

!     .. Use Statements ..
Use iso_c_binding, Only: c_ptr
x10aa_a1w_f, x10ab_a1w_f, x10ac_a1w_f,          &
Assignment (=)
Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6, nrhs = 1
!     .. Local Scalars ..
Integer                          :: i, ifail, mode, n
!     .. Local Arrays ..
Type (nagad_a1w_w_rtype), Allocatable :: b(:), d(:), df(:), dl(:),       &
dlf(:), du(:), duf(:), x(:)
Real (Kind=nag_wp), Allocatable  :: dxdb(:), dxdd(:), dxddl(:), dxddu(:)
!     .. Executable Statements ..
Write (nout,*) 'F07CA_A1W_F Example Program Results'
Write (nout,*)
!     Skip heading in data file

Allocate (b(n),d(n),dl(n-1),du(n-1))
Allocate (x(n),df(n),dlf(n-1),duf(n-1))
Allocate (dxdb(n),dxdd(n),dxddl(n-1),dxddu(n-1))

!     Read the tridiagonal matrix A and the right hand side B from
!     data file and initialize AD arrays

du(1:n-1) = dxddu(1:n-1)
d(1:n) = dxdd(1:n)
dl(1:n-1) = dxddl(1:n-1)
b(1:n) = dxdb(1:n)

!     Create AD configuration data object
ifail = 0

ifail = 0

!     Register variables to differentiate w.r.t.

dlf = dl
df = d
duf = du
x = b

!     Solve the equations Ax = b for x

!     The NAG name equivalent of dgtsv_a1w is f07ca_a1w_f
ifail = 0

If (ifail==0) Then

!       Print primal solution

Write (nout,*) 'Solution'
Write (nout,99999) x(1:n)%value

Else
Write (nout,99998) 'Element U(', ifail, ',', ifail, ') is zero'
Go To 100
End If

99999 Format ((1X,7F11.4))
99998 Format (1X,A,I0,A,I0,A)

Write (nout,*)
Write (nout,*) ' Derivatives calculated: First order adjoints'
Write (nout,*) ' Computational mode    : symbolic'
Else
Write (nout,*) ' Computational mode    : algorithmic'
End If

Write (nout,*)
Write (nout,*) ' Derivatives of solution w.r.t. inputs:'

!     Setup evaluation of derivatives via adjoints
Do i = 1, n
ifail = 0

!       Get derivatives

Write (nout,*)
Write (nout,'(1X,A,I0)') '  Solution point ', i
Write (nout,99997) '      dx/d(du) ', dxddu
Write (nout,99996) '      dx/d(d)  ', dxdd
Write (nout,99996) '      dx/d(dl) ', dxddl
Write (nout,99996) '      dx/d(b)  ', dxdb
End Do
99997 Format (1X,A,10X,6(1X,F9.2))
99996 Format (1X,A,7(1X,F9.2))

!     Remove computational data object and tape
100   Continue