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

NAG FL Interface Introduction
Example description
    Program f08ssfe

!     F08SSF Example Program Text

!     Mark 29.2 Release. NAG Copyright 2023.

!     .. Use Statements ..
      Use nag_library, Only: dsterf, nag_wp, zhegst, zhetrd, zpotrf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, info, lda, ldb, lwork, n
      Character (1)                    :: uplo
!     .. Local Arrays ..
      Complex (Kind=nag_wp), Allocatable :: a(:,:), b(:,:), tau(:), work(:)
      Real (Kind=nag_wp), Allocatable  :: d(:), e(:)
!     .. Executable Statements ..
      Write (nout,*) 'F08SSF Example Program Results'
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) n
      lda = n
      ldb = n
      lwork = 64*n
      Allocate (a(lda,n),b(ldb,n),tau(n),work(lwork),d(n),e(n-1))

!     Read A and B from data file

      Read (nin,*) uplo
      If (uplo=='U') Then
        Read (nin,*)(a(i,i:n),i=1,n)
        Read (nin,*)(b(i,i:n),i=1,n)
      Else If (uplo=='L') Then
        Read (nin,*)(a(i,1:i),i=1,n)
        Read (nin,*)(b(i,1:i),i=1,n)
      End If

!     Compute the Cholesky factorization of B
!     The NAG name equivalent of zpotrf is f07frf
      Call zpotrf(uplo,n,b,ldb,info)

      Write (nout,*)
      If (info>0) Then
        Write (nout,*) 'B is not positive definite.'
      Else

!       Reduce the problem to standard form C*y = lambda*y, storing
!       the result in A
!       The NAG name equivalent of zhegst is f08ssf
        Call zhegst(1,uplo,n,a,lda,b,ldb,info)

!       Reduce C to tridiagonal form T = (Q**H)*C*Q
!       The NAG name equivalent of zhetrd is f08fsf
        Call zhetrd(uplo,n,a,lda,d,e,tau,work,lwork,info)

!       Calculate the eigenvalues of T (same as C)
!       The NAG name equivalent of dsterf is f08jff
        Call dsterf(n,d,e,info)

        If (info>0) Then
          Write (nout,*) 'Failure to converge.'
        Else

!         Print eigenvalues

          Write (nout,*) 'Eigenvalues'
          Write (nout,99999) d(1:n)
        End If
      End If

99999 Format (3X,(9F8.4))
    End Program f08ssfe