PROGRAM f08frfe ! F08FRF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : nag_wp, x04daf, zheevr ! .. 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, ldz, & liwork, lrwork, lwork, m, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), work(:), z(:,:) COMPLEX (KIND=nag_wp) :: dummy(1) REAL (KIND=nag_wp) :: rdum(1) REAL (KIND=nag_wp), ALLOCATABLE :: rwork(:), w(:) INTEGER :: idum(1) INTEGER, ALLOCATABLE :: isuppz(:), iwork(:) ! .. Intrinsic Functions .. INTRINSIC max, nint, real ! .. Executable Statements .. WRITE (nout,*) 'F08FRF Example Program Results' WRITE (nout,*) ! Skip heading in data file and read N and the lower and upper ! indices of the smallest and largest eigenvalues to be found READ (nin,*) READ (nin,*) n, il, iu lda = n ldz = n m = n ALLOCATE (a(lda,n),z(ldz,m),w(n),isuppz(2*m)) ! Use routine workspace query to get optimal workspace. lwork = -1 liwork = -1 lrwork = -1 ! The NAG name equivalent of zheevr is f08frf CALL zheevr('Vectors','I','Upper',n,a,lda,vl,vu,il,iu,abstol,m,w,z,ldz, & isuppz,dummy,lwork,rdum,lrwork,idum,liwork,info) ! Make sure that there is enough workspace for blocksize nb. lwork = max((nb+1)*n,nint(real(dummy(1)))) lrwork = max(24*n,nint(rdum(1))) liwork = max(10*n,idum(1)) ALLOCATE (work(lwork),rwork(lrwork),iwork(liwork)) ! Read the upper triangular part of the matrix A from data file READ (nin,*) (a(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 symmetric eigenvalue problem ! The NAG name equivalent of zheevr is f08frf CALL zheevr('Vectors','I','Upper',n,a,lda,vl,vu,il,iu,abstol,m,w,z,ldz, & isuppz,work,lwork,rwork,lrwork,iwork,liwork,info) IF (info==0) THEN ! Print solution WRITE (nout,*) 'Selected eigenvalues' WRITE (nout,99999) 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) ELSE WRITE (nout,99998) 'Failure in ZHEEVR. INFO =', info END IF 99999 FORMAT (3X,(8F8.4)) 99998 FORMAT (1X,A,I5) END PROGRAM f08frfe