    PROGRAM f08yffe

!      F08YFF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dtgexc, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
       LOGICAL, PARAMETER              :: wantq = .FALSE., wantz = .FALSE.
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, ifst, ilst, info, lda,     &
                                          ldb, ldq, ldz, lwork, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), q(:,:), work(:),     &
                                          z(:,:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F08YFF Example Program Results'
       WRITE (nout,*)
       FLUSH (nout)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       ldq = 1
       ldz = 1
       lda = n
       ldb = n
       lwork = 4*n + 16
       ALLOCATE (a(lda,n),b(ldb,n),q(ldq,1),work(lwork),z(ldz,1))

!      Read A and B from data file

       READ (nin,*) (a(i,1:n),i=1,n)
       READ (nin,*) (b(i,1:n),i=1,n)

!      Read the row indices

       READ (nin,*) ifst, ilst

!      Reorder A and B

!      The NAG name equivalent of dtgexc is f08yff
       CALL dtgexc(wantq,wantz,n,a,lda,b,ldb,q,ldq,z,ldz,ifst,ilst,work,lwork, &
          info)

       IF (info/=0) THEN
          WRITE (nout,99999) info, ilst
          WRITE (nout,*)
          FLUSH (nout)
       END IF

!      Print reordered generalized Schur form

!      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,'Reordered Schur matrix A',ifail)

       WRITE (nout,*)
       FLUSH (nout)

       ifail = 0
       CALL x04caf('General',' ',n,n,b,ldb,'Reordered Schur matrix B',ifail)

99999  FORMAT (' Reordering could not be completed. INFO = ',I3,' ILST = ',I5)
    END PROGRAM f08yffe
