NAG Library Manual, Mark 28.4
Program f08ga_t1w_fe

!     F08GA_T1W_F Example Program Text
!     Mark 28.4 Release. NAG Copyright 2022.

!     .. Use Statements ..
Use iso_c_binding, Only: c_ptr
x10ab_t1w_f, Assignment (=)
Use nag_library, Only: nag_wp, x02ajf, x04caf
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
Character (1), Parameter         :: uplo = 'U'
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: eerrbd, eps
Integer                          :: i, ifail, info, j, n
!     .. Local Arrays ..
Type (nagad_t1w_w_rtype), Allocatable :: ap(:), ap_in(:), w(:), work(:), &
w_in(:)
Real (Kind=nag_wp), Allocatable  :: dwda(:,:), wr(:)
!     .. Intrinsic Procedures ..
Intrinsic                        :: abs, max
!     .. Executable Statements ..
Write (nout,*) 'F08GA_T1W_F Example Program Results'
Write (nout,*)
!     Skip heading in data file

Allocate (ap((n*(n+1))/2),w(n),w_in(n),work(3*n))
Allocate (ap_in((n*(n+1))/2),dwda(n,n),wr(n))

ifail = 0

!     Read the upper triangular part of the matrix A from data file

ap_in = 0.0_nag_wp
w_in = 0.0_nag_wp

Do j = 1, n

ap = ap_in
w = w_in
ap(j*(j+1)/2)%tangent = 1.0_nag_wp
!       Solve the symmetric eigenvalue problem
!       The NAG name equivalent of dspev_t1w is f08ga_t1w_f

If (info/=0) Then
Write (nout,99997) 'Failure in dspev_t1w. info =', info
Go To 100
End If

If (j==1) Then
wr(1:n) = w(1:n)%value
End If

Do i = 1, n
dwda(i,j) = w(i)%tangent
End Do

End Do

Write (nout,*) 'Eigenvalues'
Write (nout,99999) wr(1:n)

!     Get the machine precision, EPS and compute the approximate
!     error bound for the computed eigenvalues.  Note that for
!     the 2-norm, max( abs(W(i)) ) = norm(A), and since the
!     eigenvalues are returned in ascending order
!     max( abs(W(i)) ) = max( abs(W(1)), abs(W(n)))

eps = x02ajf()
eerrbd = eps*max(abs(wr(1)),abs(wr(n)))

!     Print the approximate error bound for the eigenvalues

Write (nout,*)
Write (nout,*) 'Error estimate for the eigenvalues'
Write (nout,99998) eerrbd

Write (nout,*)
Write (nout,*) 'Derivatives of eigenvalues w.r.t. diagonal of A'
ifail = 0
Call x04caf('General',' ',n,n,dwda,n,'dW_i/dA_jj',ifail)

100   Continue