    PROGRAM f08qtfe

!      F08QTF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x04dbf, ztrexc
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, ifst, ilst, info, ldq,     &
                                          ldt, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: q(:,:), t(:,:)
       CHARACTER (1)                   :: clabs(1), rlabs(1)
!      .. Executable Statements ..
       WRITE (nout,*) 'F08QTF Example Program Results'
       WRITE (nout,*)
       FLUSH (nout)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       ldq = 1
       ldt = n
       ALLOCATE (q(ldq,1),t(ldt,n))

!      Read T from data file

       READ (nin,*) (t(i,1:n),i=1,n)

!      Read the row indices

       READ (nin,*) ifst, ilst

!      Reorder the Schur factor T

!      The NAG name equivalent of ztrexc is f08qtf
       CALL ztrexc('No update',n,t,ldt,q,ldq,ifst,ilst,info)
       IF (info/=0) THEN
          WRITE (nout,99999) info, ilst
          WRITE (nout,*)
          FLUSH (nout)
       END IF

!      Print reordered Schur form

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL x04dbf('General',' ',n,n,t,ldt,'Bracketed','F7.4', &
          'Reordered Schur form','Integer',rlabs,'Integer',clabs,80,0,ifail)

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