PROGRAM f08pefe ! F08PEF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : dgemm, dhseqr, nag_wp, x04caf, x04cbf ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: alpha, beta INTEGER :: i, ifail, info, ldc, ldd, ldh, ldz, & lwork, n ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: c(:,:), d(:,:), h(:,:), wi(:), & work(:), wr(:), z(:,:) ! .. Executable Statements .. WRITE (nout,*) 'F08PEF Example Program Results' ! Skip heading in data file READ (nin,*) READ (nin,*) n ldc = n ldd = n ldh = n ldz = n lwork = n ALLOCATE (c(ldc,n),d(ldd,n),h(ldh,n),wi(n),work(lwork),wr(n),z(ldz,n)) ! Read H from data file READ (nin,*) (h(i,1:n),i=1,n) ! Print Matrix H ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04caf('General',' ',n,n,h,ldh,'Matrix H',ifail) ! Calculate the eigenvalues and Schur factorization of H ! The NAG name equivalent of dhseqr is f08pef CALL dhseqr('Schur form','Initialize Z',n,1,n,h,ldh,wr,wi,z,ldz,work, & lwork,info) WRITE (nout,*) IF (info>0) THEN WRITE (nout,*) 'Failure to converge.' ELSE ! Compute Z * T * Z**T from Schur factorization of H alpha = 1._nag_wp beta = 0._nag_wp CALL dgemm('N','N',n,n,n,alpha,z,ldz,h,ldh,beta,c,ldc) CALL dgemm('N','T',n,n,n,alpha,c,ldc,z,ldz,beta,d,ldd) ! Print matrix H, as computed from Schur factorization ifail = 0 CALL x04cbf('General',' ',n,n,d,ldd,'F8.4', & 'Matrix H recreated from Schur factorization Z*T*Z^T','I','','I', & '',80,0,ifail) WRITE (nout,*) FLUSH (nout) WRITE (nout,*) 'Eigenvalues' WRITE (nout,99999) (' (',wr(i),',',wi(i),')',i=1,n) END IF 99999 FORMAT (1X,A,F8.4,A,F8.4,A) END PROGRAM f08pefe