Program f08jlfe
! F08JLF Example Program Text
! Mark 30.0 Release. NAG Copyright 2024.
! .. Use Statements ..
Use nag_library, Only: dstegr, nag_wp, x04caf
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Real (Kind=nag_wp), Parameter :: vl = 0.0E0_nag_wp
Real (Kind=nag_wp), Parameter :: vu = 0.0E0_nag_wp
Integer, Parameter :: il = 0, iu = 0, nin = 5, nout = 6
Character (1), Parameter :: range = 'A'
! .. Local Scalars ..
Real (Kind=nag_wp) :: abstol
Integer :: i, ifail, info, ldz, liwork, lwork, &
m, n
Character (1) :: jobz
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: d(:), e(:), w(:), work(:), z(:,:)
Integer, Allocatable :: isuppz(:), iwork(:)
! .. Executable Statements ..
Write (nout,*) 'F08JLF Example Program Results'
Write (nout,*)
! Skip heading in data file
Read (nin,*)
Read (nin,*) n
ldz = n
liwork = 10*n
lwork = 18*n
Allocate (d(n),e(n),w(n),work(lwork),z(ldz,n),isuppz(2*n),iwork(liwork))
! Read the symmetric tridiagonal matrix T from data file, first
! the diagonal elements, then the off diagonal elements and then
! JOBV ('N' - eigenvalues only, 'V' - vectors as well)
Read (nin,*) d(1:n)
Read (nin,*) e(1:n-1)
Read (nin,*) jobz
! Calculate all the eigenvalues of T. Set ABSTOL to zero so that
! the default value is used.
abstol = 0.0E0_nag_wp
! The NAG name equivalent of dstegr is f08jlf
Call dstegr(jobz,range,n,d,e,vl,vu,il,iu,abstol,m,w,z,ldz,isuppz,work, &
lwork,iwork,liwork,info)
If (info==0) Then
! Print eigenvalues and eigenvectors
Write (nout,*) 'Eigenvalues'
Write (nout,99999) w(1:m)
Write (nout,*)
Flush (nout)
! Standardize the eigenvectors so that first elements are non-negative.
Do i = 1, m
If (z(1,i)<0.0_nag_wp) Then
z(1:n,i) = -z(1:n,i)
End If
End Do
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
Call x04caf('General',' ',n,m,z,ldz,'Eigenvectors',ifail)
Else
Write (nout,99998) 'Failure to compute an eigenvalue, INFO = ', info
End If
99999 Format ((3X,8F8.4))
99998 Format (1X,A,I10)
End Program f08jlfe