PROGRAM f08tbfe ! F08TBF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dspgvx, nag_wp, x04caf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. REAL (KIND=nag_wp), PARAMETER :: zero = 0.0E+0_nag_wp INTEGER, PARAMETER :: nin = 5, nout = 6 CHARACTER (1), PARAMETER :: uplo = 'U' ! .. Local Scalars .. REAL (KIND=nag_wp) :: abstol, vl, vu INTEGER :: i, ifail, il, info, iu, j, ldz, m, n ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: ap(:), bp(:), w(:), work(:), z(:,:) INTEGER, ALLOCATABLE :: iwork(:), jfail(:) ! .. Executable Statements .. WRITE (nout,*) 'F08TBF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) READ (nin,*) n ldz = n m = n ALLOCATE (ap((n*(n+1))/2),bp((n*(n+1))/2),w(n),work(8*n),z(ldz,m),iwork & (5*n),jfail(n)) ! 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=='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=='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 symmetric eigenvalue problem ! A*x = lambda*B*x (itype = 1) ! The NAG name equivalent of dspgvx is f08tbf CALL dspgvx(1,'Vectors','Values in range',uplo,n,ap,bp,vl,vu,il,iu, & abstol,m,w,z,ldz,work,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 x04caf('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 DSPGVX. 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 f08tbfe