    PROGRAM nag_sym_gen_eig_ex06

      ! Example Program Text for nag_sym_gen_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_gen_eig, ONLY : nag_sym_gen_eig_sel
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j, n, type
      REAL (wp) :: vl, vu
      CHARACTER (1) :: uplo
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: a(:), b(:)
      REAL (wp), POINTER :: lambda(:), z(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sym_gen_eig_ex06'

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

      ALLOCATE (a(n*(n+1)/2),b(n*(n+1)/2)) ! Allocate storage

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

      ! Compute eigenvalues and eigenvectors

      CALL nag_sym_gen_eig_sel(uplo,a,b,lambda,type=type,vl=vl,vu=vu,z=z)

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

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

      DEALLOCATE (a,b,lambda,z)    ! Deallocate storage

      NULLIFY (lambda,z)

    END PROGRAM nag_sym_gen_eig_ex06
