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

NAG FL Interface Introduction
Example description
    Program f08fsfe

!     F08FSF Example Program Text

!     Mark 30.1 Release. NAG Copyright 2024.

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

!     Read A from data file and copy A into C

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

!     Reduce A to tridiagonal form
!     The NAG name equivalent of zhetrd is f08fsf
      Call zhetrd(uplo,n,a,lda,d,e,tau,work,lwork,info)

      If (info==0) Then
!       Print the diagonal and off-diagonal of tridiagonal T.
!       The absolute value of E is printed since this can vary by a change of
!       sign (corresponding to multiplying through a column of Q by -1).

        Write (nout,*)
        Write (nout,*)                                                         &
          'Diagonal and off-diagonal elements of tridiagonal form'
        Write (nout,*)
        Write (nout,99999) 'i', 'D', 'E'
        Do i = 1, n - 1
          Write (nout,99998) i, d(i), abs(e(i))
        End Do
        Write (nout,99998) n, d(n)

      Else
        Write (nout,99997) info
      End If

99999 Format (5X,A,9X,A,12X,A)
99998 Format (1X,I5,2(1X,F12.5))
99997 Format (1X,'** ZHETRD/F08FSF retuned with INFO = ',I10)

    End Program f08fsfe