PROGRAM f08fnfe ! F08FNF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : ddisna, nag_wp, x02ajf, x04daf, zheev ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: eerrbd, eps INTEGER :: i, ifail, info, lda, lwork, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), work(:) COMPLEX (KIND=nag_wp) :: dummy(1) REAL (KIND=nag_wp), ALLOCATABLE :: rcondz(:), rwork(:), w(:), zerrbd(:) ! .. Intrinsic Functions .. INTRINSIC abs, max, nint, real ! .. Executable Statements .. WRITE (nout,*) 'F08FNF Example Program Results' WRITE (nout,*) ! Skip heading in data file READ (nin,*) READ (nin,*) n lda = n ALLOCATE (a(lda,n),rcondz(n),rwork(3*n-2),w(n),zerrbd(n)) ! Use routine workspace query to get optimal workspace. ! The NAG name equivalent of zheev is f08fnf lwork = -1 CALL zheev('Vectors','Upper',n,a,lda,w,dummy,lwork,rwork,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 part of the matrix A from data file READ (nin,*) (a(i,i:n),i=1,n) ! Solve the Hermitian eigenvalue problem ! The NAG name equivalent of zheev is f08fnf CALL zheev('Vectors','Upper',n,a,lda,w,work,lwork,rwork,info) IF (info==0) THEN ! Print solution WRITE (nout,*) 'Eigenvalues' WRITE (nout,99999) w(1:n) WRITE (nout,*) FLUSH (nout) ! Normalize the eigenvectors DO i = 1, n a(1:n,i) = a(1:n,i)/a(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,n,a,lda,'Eigenvectors',ifail) ! Get the machine precision, EPS and compute the approximate ! error bound for the computed eigenvalues. Note that for ! the 2-norm, max( abs(W(i)) ) = norm(A), and since the ! eigenvalues are returned in descending order ! max( abs(W(i)) ) = max( abs(W(1)), abs(W(n))) eps = x02ajf() eerrbd = eps*max(abs(w(1)),abs(w(n))) ! Call DDISNA (F08FLF) to estimate reciprocal condition ! numbers for the eigenvectors CALL ddisna('Eigenvectors',n,n,w,rcondz,info) ! Compute the error estimates for the eigenvectors DO i = 1, n zerrbd(i) = eerrbd/rcondz(i) END DO ! Print the approximate error bounds for the eigenvalues ! and vectors WRITE (nout,*) WRITE (nout,*) 'Error estimate for the eigenvalues' WRITE (nout,99998) eerrbd WRITE (nout,*) WRITE (nout,*) 'Error estimates for the eigenvectors' WRITE (nout,99998) zerrbd(1:n) ELSE WRITE (nout,99997) 'Failure in ZHEEV. INFO =', info END IF 99999 FORMAT (3X,(8F8.4)) 99998 FORMAT (4X,1P,6E11.1) 99997 FORMAT (1X,A,I4) END PROGRAM f08fnfe