*     F08TPF Example Program Text
*     Mark 21.  NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, MMAX
      PARAMETER        (NMAX=10,MMAX=5)
      INTEGER          LDZ
      PARAMETER        (LDZ=NMAX)
      CHARACTER        UPLO
      PARAMETER        (UPLO='U')
      DOUBLE PRECISION ZERO
      PARAMETER        (ZERO=0.0D+0)
*     .. Local Scalars ..
      DOUBLE PRECISION ABSTOL, VL, VU
      INTEGER          I, IFAIL, IL, INFO, IU, J, M, N
*     .. Local Arrays ..
      COMPLEX *16      AP((NMAX*(NMAX+1))/2), BP((NMAX*(NMAX+1))/2),
     +                 WORK(2*NMAX), Z(LDZ,MMAX)
      DOUBLE PRECISION RWORK(7*NMAX), W(NMAX)
      INTEGER          INDEX(NMAX), IWORK(5*NMAX)
*     .. External Subroutines ..
      EXTERNAL         X04DAF, ZHPGVX
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F08TPF Example Program Results'
      WRITE (NOUT,*)
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N
      IF (N.LE.NMAX) THEN
*
*        Read the lower and upper bounds of the interval to be searched,
*        and read the upper or lower triangular parts of the matrices A
*        and B from data file
*
         READ (NIN,*) VL, VU
         IF (UPLO.EQ.'U') THEN
            READ (NIN,*) ((AP(I+(J*(J-1))/2),J=I,N),I=1,N)
            READ (NIN,*) ((BP(I+(J*(J-1))/2),J=I,N),I=1,N)
         ELSE IF (UPLO.EQ.'L') THEN
            READ (NIN,*) ((AP(I+((2*N-J)*(J-1))/2),J=1,I),I=1,N)
            READ (NIN,*) ((BP(I+((2*N-J)*(J-1))/2),J=1,I),I=1,N)
         END IF
*
*        Set the absolute error tolerance for eigenvalues.  With ABSTOL
*        set to zero, the default value is used instead
*
         ABSTOL = ZERO
*
*        Solve the generalized Hermitian eigenvalue problem
*        A*x = lambda*B*x (ITYPE = 1)
*
         CALL ZHPGVX(1,'Vectors','Values in range',UPLO,N,AP,BP,VL,VU,
     +               IL,IU,ABSTOL,M,W,Z,LDZ,WORK,RWORK,IWORK,INDEX,INFO)
*
         IF (INFO.GE.0 .AND. INFO.LE.N .AND. M.LE.MMAX) THEN
*
*           Print solution
*
            WRITE (NOUT,99999) 'Number of eigenvalues found =', M
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Eigenvalues'
            WRITE (NOUT,99998) (W(J),J=1,M)
*
            IFAIL = 0
            CALL X04DAF('General',' ',N,M,Z,LDZ,'Selected eigenvectors',
     +                  IFAIL)
            IF (INFO.GT.0) THEN
               WRITE (NOUT,99999)
     +           'INFO eigenvectors failed to converge, INFO =', INFO
               WRITE (NOUT,*)
     +           'Indices of eigenvectors that did not converge'
               WRITE (NOUT,99997) (INDEX(J),J=1,M)
            END IF
         ELSE IF (INFO.GT.N .AND. INFO.LE.2*N) THEN
            I = INFO - N
            WRITE (NOUT,99996) 'The leading minor of order ', I,
     +        ' of B is not positive definite'
         ELSE IF (M.GT.MMAX) THEN
            WRITE (NOUT,99995) 'M greater than MMAX, M =', M,
     +        ', MMAX =', MMAX
         ELSE
            WRITE (NOUT,99999) 'Failure in ZHPGVX. INFO =', INFO
         END IF
      ELSE
         WRITE (NOUT,*)
         WRITE (NOUT,*) 'NMAX too small'
      END IF
      STOP
*
99999 FORMAT (1X,A,I5)
99998 FORMAT (3X,(8F8.4))
99997 FORMAT (3X,(8I8))
99996 FORMAT (1X,A,I4,A)
99995 FORMAT (1X,A,I5,A,I5)
      END
