SUBROUTINE LA_TEST_SGGES(JOBVSL, JOBVSR, SORT, SELECT, N, A, LDA, B, LDB, SDIM, &
&   ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, WORK, LWORK, BWORK, INFO)
!
!  -- LAPACK95 interface driver routine (version 1.1) --
!     UNI-C, Denmark;
!     September 25, 1999
!
!  .. Use Statements ..
   USE LA_PRECISION, ONLY: WP => SP
   USE F95_LAPACK, ONLY: LA_GGES
!  .. Implicit Statement ..
   IMPLICIT NONE
!  .. Scalar Arguments ..
   INTEGER, INTENT(IN) :: N, LDA, LDB, LDVSL, LDVSR, LWORK
   INTEGER, INTENT(INOUT) :: INFO
   INTEGER, INTENT(OUT) :: SDIM
   CHARACTER*1, INTENT(IN) :: JOBVSL, JOBVSR, SORT
!  .. 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)
   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 => SP
     REAL(WP), INTENT(IN) :: ALPHAR, ALPHAI, BETA
   END FUNCTION SELECT
 END INTERFACE
 OPTIONAL :: SELECT   
      
!  .. Parameters ..
 CHARACTER(LEN=8),  PARAMETER :: SRNAME = 'LA_GGES '
 CHARACTER(LEN=14), PARAMETER :: SRNAMT = 'LA_TEST_SGGES '
!  .. 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; ISORT = SORT
   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)
       ISORT = 'N'; IJOBVSL = 'V'; IJOBVSR = 'N'
       IVSL1 = IA1 - 1
       CALL LA_GGES( 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),  SDIM=SDIM, &
     &   INFO=INFO)
       CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
       RETURN
       CASE (7)
       ISORT = 'N'; IJOBVSL = 'N'; IJOBVSR = 'V' 
       IVSR1 = IA1 - 1
       CALL LA_GGES( 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)
       CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
       RETURN 
       CASE(:-1, 8:)
       CALL UESTOP(SRNAMT)
   END SELECT

   IF (LSAME(ISORT, 'N')) THEN
      IF (LSAME(IJOBVSL,'V')) THEN
        IF (LSAME (IJOBVSR, 'V')) THEN
          CALL LA_GGES( 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),SDIM=SDIM,  &
     &      INFO=INFO)
        ELSE
          CALL LA_GGES( 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), SDIM=SDIM, & 
     &      INFO=INFO)    
        END IF
      ELSE 
        IF (LSAME (IJOBVSR, 'V')) THEN
          CALL LA_GGES( 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), &
     &      SDIM=SDIM, INFO = INFO)
        ELSE
          CALL LA_GGES( A(1:IA1,1:IA2), B(1:IB1, 1:IB2), &
     &      ALPHAR=ALPHAR(1: IALPHAR), ALPHAI=ALPHAI(1:IALPHAI), &
     &      BETA=BETA(1: IBETA), SDIM=SDIM, INFO = INFO)
        END IF
      END IF
      ELSE
        IF (LSAME(IJOBVSL,'V')) THEN
          IF (LSAME (IJOBVSR, 'V')) THEN
            CALL LA_GGES( 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)    
          ELSE
            CALL LA_GGES( 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_GGES( 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_GGES( 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
CALL LA_AUX_AA01( I, CTEST, ETEST, SRNAMT )
END SUBROUTINE LA_TEST_SGGES
