SUBROUTINE LA_TEST_DGGESX(JOBVSL, JOBVSR, SORT, SELECT, SENSE, N, A, LDA, B, LDB, SDIM, &
     &  ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, RCONDE, RCONDV, WORK, LWORK, IWORK, &
     &  LIWORK,  BWORK, INFO)
!
!  -- LAPACK95 interface driver routine (version 1.1) --
!     UNI-C, Denmark;
!     September 25, 1999
!
!  .. Use Statements ..
   USE LA_PRECISION, ONLY: WP => DP
   USE F95_LAPACK, ONLY: LA_GGESX
!  .. Implicit Statement ..
   IMPLICIT NONE
!  .. Scalar Arguments ..
   INTEGER, INTENT(IN) :: N, LDA, LDB, LDVSL, LDVSR, LWORK, LIWORK
      INTEGER, INTENT(INOUT) :: INFO
      INTEGER, INTENT(OUT) :: SDIM
      CHARACTER*1, INTENT(IN) :: JOBVSL, JOBVSR, SORT, SENSE
      REAL(WP), INTENT(OUT) :: RCONDE(1:2), RCONDV(1:2) 
!  .. Array Arguments ..
   REAL(WP), INTENT(INOUT) :: A(1:LDA,1:N), B(1:LDB, 1:N)
      REAL(WP), INTENT(OUT):: WORK(1:LWORK)
      LOGICAL :: BWORK(1: N)
      INTEGER :: IWORK (1: LIWORK)
      REAL(WP), INTENT(OUT) :: ALPHAR(1:N), ALPHAI(1:N), BETA(1:N), &
     &  VSL(1: LDVSL, 1:N), VSR(1: LDVSR, 1:N)
      INTERFACE
      LOGICAL FUNCTION SELECT(ALPHAR, ALPHAI, BETA)
      USE LA_PRECISION, ONLY: WP => DP
      REAL(WP), INTENT(IN) :: ALPHAR, ALPHAI, BETA
      END FUNCTION SELECT
      END INTERFACE
      OPTIONAL :: SELECT
!  .. Parameters ..
   CHARACTER(LEN=8),  PARAMETER :: SRNAME = 'LA_GGESX'
   CHARACTER(LEN=14), PARAMETER :: SRNAMT = 'LA_TEST_DGGESX'
!  .. Common blocks ..
   INTEGER :: INFOTC
   COMMON /LINFO95/ INFOTC
!  .. Local Scalars ..
   INTEGER :: I, J, IA1, IA2, IB1, IB2, IALPHAI, IALPHAR, IBETA, IVSL1, &
     &  IVSL2, IVSR1, IVSR2
   CHARACTER*1 :: IJOBVSL, IJOBVSR, ISORT
!  .. Local Arrays ..
   LOGICAL, SAVE :: CTEST = .TRUE., ETEST = .TRUE.
   LOGICAL LSAME
!  .. Executable Statements ..
   IA1 = N; IA2 = N; IJOBVSL = JOBVSL; IJOBVSR = JOBVSR
   IB1 = N; IB2 = N; IALPHAR = N; IALPHAI = N; IBETA = N
   IVSL1 = N; IVSL2 = N; IVSR1 = N; IVSR2 = N
   I = INFO / 100; J = INFO - I*100
   SELECT CASE(I)
     CASE (1)
       IA2 = IA1 - 1
     CASE (2)
       IB1 = IA1 - 1
      CASE (3)
       IALPHAR = IA1 - 1
       CASE (4)
       IALPHAI = IA1 - 1 
       CASE (5)
       IBETA  = IA1 - 1
     CASE (6)
       IVSL1 = IA1 - 1
       CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&        ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&        BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&        VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&        RCONDE=RCONDE, RCONDV=RCONDV, INFO=INFO)
       CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
       RETURN
     CASE (7)
        IVSR1 = IA1 - 1 
       CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&        ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&        BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&        VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&        RCONDE=RCONDE, RCONDV=RCONDV, INFO=INFO) 
       CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
       RETURN
       CASE(:-1, 8:)
       CALL UESTOP(SRNAMT)
   END SELECT

   IF(LSAME(SENSE,'B')) THEN
     IF (LSAME(SORT, 'N')) THEN
       IF (LSAME(IJOBVSL,'V')) THEN
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&            VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&            RCONDE=RCONDE, RCONDV=RCONDV, INFO=INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2),  SELECT=SELECT, & 
&            SDIM=SDIM, RCONDE=RCONDE, RCONDV=RCONDV,INFO=INFO)    
         END IF
       ELSE 
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, &
&            SDIM=SDIM, RCONDE=RCONDE, RCONDV=RCONDV,INFO = INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), SELECT=SELECT, SDIM=SDIM, RCONDE=RCONDE, &
&            RCONDV=RCONDV, INFO = INFO)
         END IF
       END IF
     ELSE
       IF (LSAME(IJOBVSL,'V')) THEN
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&            VSL(1:IVSL1,1:IVSL2), VSR(1:IVSR1,1:IVSR2),  SELECT, SDIM,&
&            RCONDE, RCONDV,INFO)    
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&            VSL(1:IVSL1,1:IVSL2), SELECT=SELECT,  SDIM=SDIM, &
&            RCONDE=RCONDE, RCONDV=RCONDV,INFO=INFO) 
         END IF
       ELSE 
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&            VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&            RCONDE=RCONDE, RCONDV=RCONDV, &
&            INFO = INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&            SELECT=SELECT,  SDIM=SDIM, RCONDE=RCONDE, &
&            RCONDV=RCONDV,INFO = INFO)
         END IF
       END IF
     END IF
   ELSE IF (LSAME (SENSE,'V')) THEN
     IF (LSAME(SORT, 'N')) THEN
       IF (LSAME(IJOBVSL,'V')) THEN
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&            VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&            RCONDV=RCONDV, INFO=INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2),  SELECT=SELECT, & 
&            SDIM=SDIM, RCONDV=RCONDV,INFO=INFO)    
         END IF
       ELSE 
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, &
&            SDIM=SDIM, RCONDV=RCONDV,INFO = INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&            BETA=BETA(1: IBETA), SELECT=SELECT, SDIM=SDIM, &
&            RCONDV=RCONDV,INFO = INFO)
         END IF
       END IF
     ELSE
       IF (LSAME(IJOBVSL,'V')) THEN
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&            VSL(1:IVSL1,1:IVSL2), VSR(1:IVSR1,1:IVSR2),  SELECT, SDIM,&
&            RCONDV=RCONDV, INFO=INFO)    
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&            VSL(1:IVSL1,1:IVSL2), SELECT=SELECT,  SDIM=SDIM, &
&            RCONDV=RCONDV,INFO=INFO) 
         END IF
       ELSE 
         IF (LSAME (IJOBVSR, 'V')) THEN
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&            VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&            RCONDV=RCONDV, INFO = INFO)
         ELSE
           CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&            ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&            SELECT=SELECT,  SDIM=SDIM,  &
&            RCONDV=RCONDV,INFO = INFO)
         END IF
       END IF
     END IF
   ELSE
     IF (LSAME (SENSE, 'E')) THEN
       IF (LSAME(SORT, 'N')) THEN
         IF (LSAME(IJOBVSL,'V')) THEN
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&              VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&              RCONDE=RCONDE, INFO=INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2),  SELECT=SELECT, & 
&              SDIM=SDIM, RCONDE=RCONDE, INFO=INFO)    
           END IF
         ELSE 
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, &
&              SDIM=SDIM, RCONDE=RCONDE, INFO = INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), SELECT=SELECT, SDIM=SDIM, RCONDE=RCONDE, &
&              INFO = INFO)
           END IF
         END IF
       ELSE
         IF (LSAME(IJOBVSL,'V')) THEN
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&              VSL(1:IVSL1,1:IVSL2), VSR(1:IVSR1,1:IVSR2),  SELECT, SDIM,&
&              RCONDE, INFO = INFO)    
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&              VSL(1:IVSL1,1:IVSL2), SELECT=SELECT,  SDIM=SDIM, &
&              RCONDE=RCONDE, INFO=INFO) 
           END IF
         ELSE 
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&              VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&              RCONDE=RCONDE, INFO = INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&              SELECT=SELECT,  SDIM=SDIM, RCONDE=RCONDE, &
&              INFO = INFO)
           END IF
         END IF
       END IF
     ELSE
       IF (LSAME(SORT, 'N')) THEN
         IF (LSAME(IJOBVSL,'V')) THEN
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2), &
&              VSR=VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&              INFO=INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSL=VSL(1:IVSL1,1:IVSL2),  SELECT=SELECT, & 
&              SDIM=SDIM, INFO=INFO)    
           END IF
         ELSE 
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, &
&              SDIM=SDIM, INFO = INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
&              BETA=BETA(1: IBETA), SELECT=SELECT, SDIM=SDIM, INFO = INFO)
           END IF
         END IF
       ELSE
         IF (LSAME(IJOBVSL,'V')) THEN
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&              VSL(1:IVSL1,1:IVSL2), VSR(1:IVSR1,1:IVSR2),  SELECT, SDIM,&
&              INFO = INFO)    
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&              VSL(1:IVSL1,1:IVSL2), SELECT=SELECT,  SDIM=SDIM, &
&              INFO=INFO) 
           END IF
         ELSE 
           IF (LSAME (IJOBVSR, 'V')) THEN
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA),&
&              VSR = VSR(1:IVSR1,1:IVSR2), SELECT=SELECT, SDIM=SDIM, &
&              INFO = INFO)
           ELSE
             CALL LA_GGESX( A(1:IA1,1:IA2), B(1:IB1, 1:IB2),&
&              ALPHAR(1: IALPHAR), ALPHAI(1:IALPHAI), BETA(1: IBETA), &
&              SELECT=SELECT,  SDIM=SDIM, INFO = INFO)
           END IF
         END IF
       END IF
     ENDIF
   ENDIF

CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
END SUBROUTINE LA_TEST_DGGESX

