! F08PAF Example Program Text ! Mark 23 Release. NAG Copyright 2011. MODULE f08pafe_mod ! F08PAF Example Program Module: ! Parameters and User-defined Routines ! .. Use Statements .. USE nag_library, ONLY : nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6 CONTAINS FUNCTION select(wr,wi) ! Logical function select for use with DGEES (F08PAF) ! Returns the value .TRUE. if the eigenvalue is real ! .. Implicit None Statement .. IMPLICIT NONE ! .. Function Return Value .. LOGICAL :: select ! .. Scalar Arguments .. REAL (KIND=nag_wp), INTENT (IN) :: wi, wr ! .. Local Scalars .. LOGICAL :: d ! .. Executable Statements .. IF (wi==0.0_nag_wp) THEN d = .TRUE. ELSE d = .FALSE. END IF select = d RETURN END FUNCTION select END MODULE f08pafe_mod PROGRAM f08pafe ! F08PAF Example Main Program ! .. Use Statements .. USE nag_library, ONLY : dgees, dgemm, nag_wp, x04caf USE f08pafe_mod, ONLY : nb, nin, nout, select ! .. Implicit None Statement .. IMPLICIT NONE ! .. Local Scalars .. REAL (KIND=nag_wp) :: alpha, beta INTEGER :: i, ifail, info, lda, ldc, ldd, & ldvs, lwork, n, sdim ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), c(:,:), d(:,:), vs(:,:), & wi(:), work(:), wr(:) REAL (KIND=nag_wp) :: dummy(1) LOGICAL, ALLOCATABLE :: bwork(:) ! .. Intrinsic Functions .. INTRINSIC max, nint ! .. Executable Statements .. WRITE (nout,*) 'F08PAF Example Program Results' WRITE (nout,*) FLUSH (nout) ! Skip heading in data file READ (nin,*) READ (nin,*) n lda = n ldc = n ldd = n ldvs = n ALLOCATE (a(lda,n),c(ldc,n),d(ldd,n),vs(ldvs,n),wi(n),wr(n),bwork(n)) ! Use routine workspace query to get optimal workspace. lwork = -1 ! The NAG name equivalent of dgees is f08paf CALL dgees('Vectors (Schur)','Sort',select,n,a,lda,sdim,wr,wi,vs,ldvs, & dummy,lwork,bwork,info) ! Make sure that there is enough workspace for blocksize nb. lwork = max((nb+2)*n,nint(dummy(1))) ALLOCATE (work(lwork)) ! Read the matrix 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 x04caf('General',' ',n,n,a,lda,'Matrix A',ifail) WRITE (nout,*) FLUSH (nout) ! Find the Schur factorization ! The NAG name equivalent of dgees is f08paf CALL dgees('Vectors (Schur)','Sort',select,n,a,lda,sdim,wr,wi,vs,ldvs, & work,lwork,bwork,info) IF (info==0 .OR. info==(n+2)) THEN ! Compute Z * T * Z**T from Schur factorization of A alpha = 1._nag_wp beta = 0._nag_wp CALL dgemm('N','N',n,n,n,alpha,vs,ldvs,a,lda,beta,c,ldc) CALL dgemm('N','T',n,n,n,alpha,c,ldc,vs,ldvs,beta,d,ldd) ! Print matrix A, as computed from Schur factorization ifail = 0 CALL x04caf('General',' ',n,n,d,ldd, & 'Matrix A recreated from Schur factorization Z*T*Z^T',ifail) ELSE WRITE (nout,99999) 'Failure in DGEES. INFO = ', info END IF 99999 FORMAT (1X,A,I4) 99998 FORMAT (1X,2A/1X,A) END PROGRAM f08pafe