*     F08XNF Example Program Text
*     Mark 21 Release. NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NB, NMAX
      PARAMETER        (NB=64,NMAX=10)
      INTEGER          LDA, LDB, LDVSL, LDVSR, LWORK
      PARAMETER        (LDA=NMAX,LDB=NMAX,LDVSL=NMAX,LDVSR=NMAX,
     +                 LWORK=NMAX+NMAX*NB)
*     .. Local Scalars ..
      INTEGER          I, IFAIL, INFO, J, LWKOPT, N, SDIM
*     .. Local Arrays ..
      COMPLEX *16      A(LDA,NMAX), ALPHA(NMAX), B(LDB,NMAX),
     +                 BETA(NMAX), VSL(LDVSL,NMAX), VSR(LDVSR,NMAX),
     +                 WORK(LWORK)
      DOUBLE PRECISION RWORK(8*NMAX)
      LOGICAL          BWORK(NMAX)
      CHARACTER        CLABS(1), RLABS(1)
*     .. External Functions ..
      LOGICAL          F08XNZ
      EXTERNAL         F08XNZ
*     .. External Subroutines ..
      EXTERNAL         X04DBF, ZGGES
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F08XNF Example Program Results'
      WRITE (NOUT,*)
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N
      IF (N.LE.NMAX) THEN
*
*        Read in the matrices A and B
*
         READ (NIN,*) ((A(I,J),J=1,N),I=1,N)
         READ (NIN,*) ((B(I,J),J=1,N),I=1,N)
*
*        Find the generalized Schur form
*
         CALL ZGGES('Vectors (left)','Vectors (right)','No sort',F08XNZ,
     +              N,A,LDA,B,LDB,SDIM,ALPHA,BETA,VSL,LDVSL,VSR,LDVSR,
     +              WORK,LWORK,RWORK,BWORK,INFO)
*
         IF (INFO.GT.0) THEN
            WRITE (NOUT,99999) 'Failure in ZGGES. INFO =', INFO
         ELSE
*
*           Print out the factors of the generalized Schur factorization
*
            IFAIL = 0
            CALL X04DBF('General',' ',N,N,A,LDA,'Bracketed','F7.3',
     +                  'Generalized Schur matrix S','Integer',RLABS,
     +                  'Integer',CLABS,80,0,IFAIL)
*
            WRITE (NOUT,*)
            CALL X04DBF('General',' ',N,N,B,LDB,'Bracketed','F7.3',
     +                  'Generalized Schur matrix T','Integer',RLABS,
     +                  'Integer',CLABS,80,0,IFAIL)
*
            WRITE (NOUT,*)
            CALL X04DBF('General',' ',N,N,VSL,LDVSL,'Bracketed','F7.4',
     +                  'Matrix of left generalized Schur vectors',
     +                  'Integer',RLABS,'Integer',CLABS,80,0,IFAIL)
*
            WRITE (NOUT,*)
            CALL X04DBF('General',' ',N,N,VSR,LDVSR,'Bracketed','F7.4',
     +                  'Matrix of right generalized Schur vectors',
     +                  'Integer',RLABS,'Integer',CLABS,80,0,IFAIL)
*
            LWKOPT = WORK(1)
            IF (LWORK.LT.LWKOPT) THEN
               WRITE (NOUT,*)
               WRITE (NOUT,99998) 'Optimum workspace required = ',
     +           LWKOPT, 'Workspace provided         = ', LWORK
            END IF
         END IF
      ELSE
         WRITE (NOUT,*)
         WRITE (NOUT,*) 'NMAX too small'
      END IF
      STOP
*
99999 FORMAT (1X,A,I4)
99998 FORMAT (1X,A,I5,/1X,A,I5)
      END
