    PROGRAM nag_sym_eig_ex16

      ! Example Program Text for nag_sym_eig
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_write_mat, ONLY : nag_write_gen_mat
      USE nag_sym_eig, ONLY : nag_key_cmplx, nag_sym_tridiag_reduc, &
       nag_sym_tridiag_eig_all
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j, n
      CHARACTER (1) :: uplo
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: d(:), e(:)
      COMPLEX (wp), ALLOCATABLE :: a(:), z(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sym_eig_ex16'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) uplo
      READ (nag_std_in,*) n

      ALLOCATE (a(n*(n+1)/2),d(n),e(n-1),z(n,n)) ! allocate storage

      SELECT CASE (uplo)
      CASE ('L','l')
        DO i = 1, n
          READ (nag_std_in,*) (a(i+(2*n-j)*(j-1)/2),j=1,i)
        END DO
      CASE ('U','u')
        DO i = 1, n
          READ (nag_std_in,*) (a(i+j*(j-1)/2),j=i,n)
        END DO
      END SELECT

      ! Reduce A to real symmetric tridiagonal form

      CALL nag_sym_tridiag_reduc(uplo,a,d,e,q=z)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Diagonal of the tridiagonal matrix T'
      WRITE (nag_std_out,'(12X,5(F6.3:,10X))') d
      WRITE (nag_std_out,*) 'Super-diagonal of the tridiagonal matrix T'
      WRITE (nag_std_out,'(12X,5(F6.3:,10X))') e

      ! Compute all the eigenvalues and eigenvectors of A

      CALL nag_sym_tridiag_eig_all(nag_key_cmplx,d,e,z_tridiag=.FALSE.,z=z)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Eigenvalues'
      WRITE (nag_std_out,'(12X,5(F6.3:,10X))') d
      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(z,format='(F6.3)',title='Eigenvectors')

      DEALLOCATE (a,d,e,z)         ! Deallocate storage

    END PROGRAM nag_sym_eig_ex16
