    PROGRAM nag_sym_eig_ex12

      ! 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_sym_eig, ONLY : nag_sym_tridiag_reduc, nag_sym_tridiag_eig_val, &
       nag_sym_tridiag_eig_vec, nag_sym_tridiag_orth
      USE nag_write_mat, ONLY : nag_write_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND, SIZE
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, n
      REAL (wp) :: vl, vu
      CHARACTER (1) :: uplo
      ! .. Local Arrays ..
      INTEGER, POINTER :: block(:)
      REAL (wp), ALLOCATABLE :: a(:,:), d(:), e(:), tau(:), z(:,:)
      REAL (wp), POINTER :: lambda(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sym_eig_ex12'

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

      ALLOCATE (a(n,n),d(n),e(n-1),tau(n)) ! Allocate storage

      SELECT CASE (uplo)
      CASE ('L','l')
        READ (nag_std_in,*) (a(i,:i),i=1,n)
      CASE ('U','u')
        READ (nag_std_in,*) (a(i,i:),i=1,n)
      END SELECT

      ! Reduce A to real symmetric tridiagonal form

      CALL nag_sym_tridiag_reduc(uplo,a,d,e,tau=tau)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Diagonal of the tridiagonal matrix T'
      WRITE (nag_std_out,'(2X,6(F9.3:))') d
      WRITE (nag_std_out,*) 'Super-diagonal of the tridiagonal matrix T'
      WRITE (nag_std_out,'(2X,6(F9.3:))') e

      ! Compute the selected eigenvalues of T

      CALL nag_sym_tridiag_eig_val(d,e,lambda,vl=vl,vu=vu,block=block)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Selected eigenvalues'
      WRITE (nag_std_out,'(2X,6(F9.3:))') lambda

      ALLOCATE (z(n,SIZE(lambda))) ! Allocate storage for eigenvectors

      ! Compute the selected eigenvectors of T

      CALL nag_sym_tridiag_eig_vec(d,e,lambda,block=block,z=z)

      ! Transform the eigenvectors of T into eigenvectors of A

      CALL nag_sym_tridiag_orth(uplo,a,tau,c=z)

      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(z,format='(F9.3)',title='Selected eigenvectors')

      DEALLOCATE (a,d,e,block,lambda,tau,z) ! Deallocate storage

      NULLIFY (block,lambda)

    END PROGRAM nag_sym_eig_ex12
