@extract -b incpath.inc
@extract -b @(incd)/type.inc type=@(@type)
@ROUT ggsvd
PROGRAM LA_@(pre)GGSVD_ET_EXAMPLE
@extract -b @(incd)/header.inc -case0
!  .. Use Statements
   USE LA_PRECISION, ONLY: WP => @(upr)P
   USE F90_LAPACK, ONLY: LA_GGSVD
!  .. Implicit Statement ..
   IMPLICIT NONE
!  .. Parameters ..
 @type sreal dreal
      CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.3))'
 @type scplx dcplx sherm dherm
      CHARACTER(LEN=*), PARAMETER :: FMT = '(4(1X,1H(,F7.3,1H,,F7.3,1H):))'
 @type !
   INTEGER, PARAMETER :: NIN=5, NOUT=6
!  .. Local Scalars ..
   INTEGER :: I, INFO, M, P, N, K, L
!  .. Local Arrays ..
   INTEGER :: IWORK(1:50)
   REAL(WP), ALLOCATABLE :: AA(:,:), BB(:,:), ALPHA(:), BETA(:)
   @(type)(WP), ALLOCATABLE :: A(:,:), B(:,:), U(:,:), V(:,:), Q(:,:), DUMMY(:,:)
!  .. Executable Statements ..
   WRITE (NOUT,*) '@(pre)GGSVD ET_Example Program Results.'
   READ ( NIN, * )   ! Skip heading in data file
   READ ( NIN, * ) M, N, P
   PRINT *, 'M = ', M, ' N = ', N, ' P = ', P
   ALLOCATE ( A(M,N), AA(M,N), B(P,N), BB(P,N), ALPHA(N), BETA(N), &
              U(M,M), V(P,P), Q(N,N) )
!
   READ (NIN, *) AA, BB
   A=AA; B=BB
   WRITE(NOUT,*) 'The matrix A:'
   DO I = 1, M; WRITE (NOUT,*) 'I = ', I; WRITE (NOUT,FMT) A(I,:); ENDDO
   WRITE(NOUT,*) 'The matrix B:'
   DO I = 1, P; WRITE (NOUT,*) 'I = ', I; WRITE (NOUT,FMT) B(I,:); ENDDO
!
   WRITE ( NOUT, * )'---------------------------------------------------------'
   WRITE ( NOUT, * )
   WRITE ( NOUT, * )'Details of LA_@(pre)GGSVD LAPACK Subroutine Results.'
   WRITE ( NOUT, * )
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U, V, Q, IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U, V, Q,IWORK, INFO )
   WRITE(NOUT,*) 'INFO = ', INFO, ' K = ', K, ' L = ', L
   WRITE(NOUT,*) ' Alpha'
   WRITE(NOUT,FMT) ALPHA
   WRITE(NOUT,*) ' Beta:'
   WRITE(NOUT,FMT) BETA
   WRITE(NOUT,*) 'U:'
   DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) U(:,I); END DO
   WRITE(NOUT,*) 'V:'
   DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) V(:,I); END DO
   WRITE(NOUT,*) 'Q:'
   DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) Q(:,I); END DO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA, BETA, INFO=INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA, INFO=INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
   WRITE(NOUT,*) ' Alpha'
   WRITE(NOUT,FMT) ALPHA
   WRITE(NOUT,*) ' Beta:'
   WRITE(NOUT,FMT) BETA
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( DUMMY, B, ALPHA, BETA, K, L, U, V, Q, IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( DUMMY, B, ALPHA, BETA, K, L, U, V, Q,IWORK, INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B(:,1:N-1), ALPHA, BETA, K, L, U, V, Q, IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B(:,1:N-1), ALPHA, BETA, K, L, U, V, Q, IWORK,INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA(1:N-1), BETA, K, L, U, V, Q, IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA(1:N-1), BETA, K, L, U, V, Q, IWORK,INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA, BETA(1:N-1), K, L, U, V, Q,IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA(1:N-1), K, L, U, V, Q, IWORK,INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U(1:N,:), V, Q,IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U(1:N,:), V, Q, IWORK,INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSV(:,1:M)D( A, B, ALPHA, BETA, K, L, U, V, Q,IWORK, INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U, V(:,1:M), Q, IWORK,INFO )
   WRITE(NOUT,*) 'INFO = ', INFO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U, V, Q(:,1:P), IWORK,INFO ) '
   A=AA; B=BB
   CALL LA_GGSVD( A, B, ALPHA, BETA, K, L, U, V, Q(:,1:P),IWORK, INFO)
   WRITE(NOUT,*) 'INFO = ', INFO
!
END PROGRAM LA_@(pre)GGSVD_ET_EXAMPLE
