PROGRAM f08psfe ! F08PSF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : nag_wp, x04dbf, zgemm, zhseqr ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. COMPLEX (KIND=nag_wp) :: alpha, beta INTEGER :: i, ifail, info, ldc, ldd, ldh, ldz, & lwork, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: c(:,:), d(:,:), h(:,:), w(:), & work(:), z(:,:) CHARACTER (1) :: clabs(1), rlabs(1) ! .. Intrinsic Functions .. INTRINSIC aimag, cmplx, real ! .. Executable Statements .. WRITE (nout,*) 'F08PSF Example Program Results' WRITE (nout,*) FLUSH (nout) ! 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),w(n),work(lwork),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 x04dbf('General',' ',n,n,h,ldh,'Bracketed','F7.4','Matrix H', & 'Integer',rlabs,'Integer',clabs,80,0,ifail) ! Calculate the eigenvalues and Schur factorization of H ! The NAG name equivalent of zhseqr is f08psf CALL zhseqr('Schur form','Initialize Z',n,1,n,h,ldh,w,z,ldz,work,lwork, & info) WRITE (nout,*) IF (info>0) THEN WRITE (nout,*) 'Failure to converge.' ELSE ! Compute Z * T * Z**H from Schur factorization of A alpha = cmplx(1,kind=nag_wp) beta = cmplx(0,kind=nag_wp) CALL zgemm('N','N',n,n,n,alpha,z,ldz,h,ldh,beta,c,ldc) CALL zgemm('N','C',n,n,n,alpha,c,ldc,z,ldz,beta,d,ldd) ! Print matrix A CALL x04dbf('General',' ',n,n,d,ldd,'Bracketed','F7.4', & 'Matrix H re-created from Schur factorization Z*T*Z^H','Integer', & rlabs,'Integer',clabs,80,0,ifail) WRITE (nout,*) WRITE (nout,*) 'Eigenvalues' WRITE (nout,99999) (' (',real(w(i)),',',aimag(w(i)),')',i=1,n) END IF 99999 FORMAT ((3X,4(A,F7.4,A,F7.4,A:))) END PROGRAM f08psfe