PROGRAM f08spfe ! F08SPF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : nag_wp, x04daf, zhegvx ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. REAL (KIND=nag_wp), PARAMETER :: zero = 0.0E+0_nag_wp INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: abstol, vl, vu INTEGER :: i, ifail, il, info, iu, lda, ldb, & ldz, lwork, m, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), work(:), z(:,:) COMPLEX (KIND=nag_wp) :: dummy(1) REAL (KIND=nag_wp), ALLOCATABLE :: rwork(:), w(:) INTEGER, ALLOCATABLE :: iwork(:), jfail(:) ! .. Intrinsic Functions .. INTRINSIC max, nint, real ! .. Executable Statements .. WRITE (nout,*) 'F08SPF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) READ (nin,*) n lda = n ldb = n ldz = n m = n ALLOCATE (a(lda,n),b(ldb,n),z(ldz,m),rwork(7*n),w(n),iwork(5*n), & jfail(n)) ! Read the lower and upper bounds of the interval to be searched. READ (nin,*) vl, vu ! Use routine workspace query to get optimal workspace. lwork = -1 ! The NAG name equivalent of zhegvx is f08spf CALL zhegvx(1,'Vectors','Values in range','Upper',n,a,lda,b,ldb,vl,vu, & il,iu,abstol,m,w,z,ldz,dummy,lwork,rwork,iwork,jfail,info) ! Make sure that there is enough workspace for blocksize nb. lwork = max((nb+1)*n,nint(real(dummy(1)))) ALLOCATE (work(lwork)) ! Read the upper triangular parts of the matrices A and B READ (nin,*) (a(i,i:n),i=1,n) READ (nin,*) (b(i,i:n),i=1,n) ! 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) ! The NAG name equivalent of zhegvx is f08spf CALL zhegvx(1,'Vectors','Values in range','Upper',n,a,lda,b,ldb,vl,vu, & il,iu,abstol,m,w,z,ldz,work,lwork,rwork,iwork,jfail,info) IF (info>=0 .AND. info<=n) THEN ! Print solution WRITE (nout,99999) 'Number of eigenvalues found =', m WRITE (nout,*) WRITE (nout,*) 'Eigenvalues' WRITE (nout,99998) w(1:m) FLUSH (nout) ! Normalize the eigenvectors DO i = 1, m z(1:n,i) = z(1:n,i)/z(1,i) END DO ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04daf('General',' ',n,m,z,ldz,'Selected eigenvectors',ifail) IF (info>0) THEN WRITE (nout,99999) 'INFO eigenvectors failed to converge, INFO =' & , info WRITE (nout,*) 'Indices of eigenvectors that did not converge' WRITE (nout,99997) jfail(1:m) END IF ELSE IF (info>n .AND. info<=2*n) THEN i = info - n WRITE (nout,99996) 'The leading minor of order ', i, & ' of B is not positive definite' ELSE WRITE (nout,99999) 'Failure in ZHEGVX. INFO =', info END IF 99999 FORMAT (1X,A,I5) 99998 FORMAT (3X,(8F8.4)) 99997 FORMAT (3X,(8I8)) 99996 FORMAT (1X,A,I4,A) END PROGRAM f08spfe