    PROGRAM f08fsfe

!      F08FSF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. 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(:)
!      .. 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

       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)

!      Print tridiagonal form

       WRITE (nout,*)
       WRITE (nout,*) 'Diagonal'
       WRITE (nout,99999) d(1:n)
       WRITE (nout,*) 'Off-diagonal'
       WRITE (nout,99999) e(1:n-1)

99999  FORMAT (1X,8F9.4)
    END PROGRAM f08fsfe
