PROGRAM f08ntfe ! F08NTF Example Program Text ! Mark 23 Release. NAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : nag_wp, x04dbf, zgehrd, zgemm, zhseqr, zunghr ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. COMPLEX (KIND=nag_wp) :: alpha, beta INTEGER :: i, ifail, info, lda, ldc, ldd, ldz, & lwork, n ! .. Local Arrays .. COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), c(:,:), d(:,:), tau(:), & w(:), work(:), z(:,:) CHARACTER (1) :: clabs(1), rlabs(1) ! .. Intrinsic Functions .. INTRINSIC cmplx ! .. Executable Statements .. WRITE (nout,*) 'F08NTF Example Program Results' WRITE (nout,*) FLUSH (nout) ! Skip heading in data file READ (nin,*) READ (nin,*) n lda = n ldc = n ldd = n ldz = n lwork = 64*(n-1) ALLOCATE (a(lda,n),c(ldc,n),d(ldd,n),tau(n),w(n),work(lwork),z(ldz,n)) ! Read A from data file READ (nin,*) (a(i,1:n),i=1,n) ! Print matrix A ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 CALL x04dbf('General',' ',n,n,a,lda,'Bracketed','F7.4','Matrix A', & 'Integer',rlabs,'Integer',clabs,80,0,ifail) WRITE (nout,*) FLUSH (nout) ! Reduce A to upper Hessenberg form H = (Q**H)*A*Q ! The NAG name equivalent of zgehrd is f08nsf CALL zgehrd(n,1,n,a,lda,tau,work,lwork,info) ! Copy A into Z z(1:n,1:n) = a(1:n,1:n) ! Form Q explicitly, storing the result in Z ! The NAG name equivalent of zunghr is f08ntf CALL zunghr(n,1,n,z,ldz,tau,work,lwork,info) ! Calculate the Schur factorization of H = Y*T*(Y**H) and form ! Q*Y explicitly, storing the result in Z ! Note that A = Z*T*(Z**H), where Z = Q*Y ! The NAG name equivalent of zhseqr is f08psf CALL zhseqr('Schur form','Vectors',n,1,n,a,lda,w,z,ldz,work,lwork,info) ! 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,a,lda,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 A re-created from Schur factorization Z*T*Z^H','Integer', & rlabs,'Integer',clabs,80,0,ifail) END PROGRAM f08ntfe