NAG Library Manual, Mark 29.2
```    Program g02da_t1w_fe

!     G02DA_T1W_F Example Program Text
!     Mark 29.2 Release. NAG Copyright 2023.

!     .. Use Statements ..
Use iso_c_binding, Only: c_ptr
Use nag_library, Only: nag_wp, x04caf
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Real (Kind=nag_wp), Parameter    :: zero = 0.0_nag_wp
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: sav, tlm
Integer                          :: i, idf, ifail, ip, irank, j, ldq,    &
ldx, lwt, m, n
Logical                          :: svd
Character (1)                    :: mean, weight
!     .. Local Arrays ..
Type (nagad_t1w_w_rtype), Allocatable :: b(:), cov(:), h(:), p(:),       &
q(:,:), res(:), se(:), wk(:), wt(:), &
x(:,:), y(:)
Real (Kind=nag_wp), Allocatable  :: dbdy(:,:), dy(:)
Integer, Allocatable             :: isx(:)
!     .. Intrinsic Procedures ..
Intrinsic                        :: count
!     .. Executable Statements ..
Write (nout,*) 'G02DA_T1W_F Example Program Results'
Flush (nout)

!     Skip heading in data file
Read (nin,*) n, m, weight, mean

If (weight=='W' .Or. weight=='w') Then
lwt = n
Else
lwt = 0
End If
ldx = n
Allocate (x(ldx,m),y(n),wt(lwt),isx(m),dy(n))

x(1:n,1:m)%tangent = zero
y(1:n)%tangent = zero
wt(1:lwt)%tangent = zero
If (lwt>0) Then
Else
End If

!     Read in variable inclusion flags

!     Calculate IP
ip = count(isx(1:m)>0)
If (mean=='M' .Or. mean=='m') Then
ip = ip + 1
End If

ldq = n

Allocate (b(ip),cov((ip*ip+ip)/2),h(n),p(ip*(ip+                         &
2)),q(ldq,ip+1),res(n),se(ip),wk(ip*ip+5*(ip-1)),dbdy(n,ip))

!     Use suggested value for tolerance
tol%value = 0.000001E0_nag_wp
tol%tangent = zero

!     Create AD configuration data object
ifail = 0

!     First call for primal results
ifail = -1
se,cov,res,h,q,ldq,svd,irank,p,tol,wk,ifail)
If (ifail/=0) Then
If (ifail/=5) Then
Go To 100
End If
End If
!     Display primal results on first call
If (svd) Then
Write (nout,99999) 'Model not of full rank, rank = ', irank
Write (nout,*)
End If
Write (nout,99998) 'Residual sum of squares = ', rss%value
Write (nout,99999) 'Degrees of freedom      = ', idf
Write (nout,*)
Write (nout,*) 'Variable   Parameter estimate   Standard error'
Write (nout,*)
If (ifail==0) Then
Write (nout,99997)(j,b(j)%value,se(j)%value,j=1,ip)
Else
Write (nout,99996)(j,b(j)%value,j=1,ip)
End If

!     Repeat Tangent linear call for each input y(1:n)
Do i = 1, n
sav = y(i)%value

!       Fit general linear regression model
ifail = -1
b,se,cov,res,h,q,ldq,svd,irank,p,tol,wk,ifail)

!       Get derivative information w.r.t. y(i)
tlm = 0.0_nag_wp
dy(i) = tlm
Do j = 1, ip
tlm = 0.0_nag_wp
dbdy(i,j) = tlm
End Do

!       Reset input y(i)
y(i)%value = sav
End Do

!     Display derivative results
Write (nout,*)
Write (nout,*) ' Derivatives calculated: First order tangent linear'
Write (nout,*) ' Computational mode    : algorithmic'

Write (nout,*)
Write (nout,*) ' Derivatives:'
Write (nout,*)

Write (nout,*) '    i        d(rss)/dy(i) '
Do i = 1, n
Write (nout,99995) i, dy(i)
End Do

Write (nout,*)
ifail = 0
Call x04caf('General',' ',n,ip,dbdy,n,'    db/dy',ifail)

100   Continue

!     Remove computational data object