NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program f08jyfe

!     F08JYF Example Program Text

!     Mark 30.0 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: nag_wp, x04daf, zstegr
!     .. 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 ..
      Complex (Kind=nag_wp), Allocatable :: z(:,:)
      Real (Kind=nag_wp), Allocatable  :: d(:), e(:), w(:), work(:)
      Integer, Allocatable             :: isuppz(:), iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: real
!     .. Executable Statements ..
      Write (nout,*) 'F08JYF Example Program Results'
      Write (nout,*)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n
      ldz = n
      liwork = 10*n
      lwork = 18*n
      Allocate (z(ldz,n),d(n),e(n),w(n),work(lwork),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 zstegr is f08jyf
      Call zstegr(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 (real(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 x04daf('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 f08jyfe