    Program f08yffe

!     F08YFF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
