NAG Library Manual, Mark 29.3
```    Program g02aa_t1w_fe

!     G02AA_T1W_F Example Program Text
!     Mark 29.3 Release. NAG Copyright 2023.

!     .. Use Statements ..
Use iso_c_binding, Only: c_ptr
x10ab_t1w_f, Assignment (=)
Use nag_library, Only: nag_wp, x04caf
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: dx
Integer                          :: feval, i, ifail, iter, j, k, l, ldg, &
ldx, maxit, maxits, n
!     .. Local Arrays ..
Type (nagad_t1w_w_rtype), Allocatable :: g(:,:), g_in(:,:), x(:,:)
Real (Kind=nag_wp), Allocatable  :: dxdg(:,:)
!     .. Executable Statements ..
Write (nout,*) 'G02AA_T1W_F Example Program Results'
Write (nout,*)
Flush (nout)

!     Skip heading in data file

!     Read in the problem size

ldg = n
ldx = n
Allocate (g(ldg,n),x(ldx,n),g_in(ldg,n),dxdg(n,n))

g_in(1:n,1:n) = 0.0_nag_wp
!     Read in the matrix G

ifail = 0
!     Use the defaults for ERRTOL, MAXITS and MAXIT
errtol = 0.0E0_nag_wp
maxits = 0
maxit = 0

g = g_in

outer: Do i = 1, n
Do j = 1, n
g(i,j)%tangent = 1.0_nag_wp

!         Calculate nearest correlation matrix
x(1:n,1:n) = 0.0_nag_wp
ifail = 0
feval,nrmgrd,ifail)

If (i==1 .And. j==1) Then
!              Display results
ifail = 0
Call x04caf('General',' ',n,n,x%value,ldx,                         &
'Nearest Correlation Matrix',ifail)
Write (nout,*)
Write (nout,99999) ' Number of Newton steps taken:', iter
Write (nout,99998) ' Number of function evaluations:', feval
Write (nout,*)
End If

dx = 0.0_nag_wp
Do k = 1, n
Do l = 1, n
dx = dx + x(k,l)%tangent
End Do
End Do
dxdg(i,j) = dx

g = g_in

End Do

End Do outer

Call x04caf('General',' ',n,n,dxdg,n,' (1,...,1)^T * dx/dg',ifail)