vA <- c(1.0,  2.0,  3.0,
       3.0,  2.0,  1.0,
       4.0,  5.0,  6.0,
       7.0,  8.0,  8.0)

A <- matrix(vA,4,3, byrow=TRUE)

vB <- c(-2.0, -3.0,  3.0,
        4.0,  6.0,  5.0)


B <- matrix(vB,2,3, byrow=TRUE)

if(ncol(A)!=ncol(B))
  {
    stop("A and B matrix does not have the same column number")
  }

gsvd <- .C("GSVD",
           JOBU = as.character('U'),
           JOBV = as.character('V'),
           JOBQ = as.character('Q'),
           M = as.integer(nrow(A)),
           N = as.integer(ncol(A)),
           P = as.integer(nrow(B)),
           K = integer(1),
           L = integer(1),
           A = as.double(A),
           LDA = as.integer(nrow(A)),
           B = as.double(B),
           LDB = as.integer(nrow(B)),
           ALPHA = double(ncol(A)),
           BETA = double(ncol(A)),
           U = double(nrow(A)*nrow(A)),
           LDU = as.integer(nrow(A)),
           V = double(nrow(B)*nrow(B)),
           LDV = as.integer(nrow(B)),
           Q = double(ncol(A)*ncol(A)),
           LDQ = as.integer(ncol(A)),
           WORK = double(max(c(3*ncol(A),nrow(A),nrow(B)))+ncol(A)),
           IWORK = integer(ncol(A)),
           INFO = integer(1),
           PACKAGE="GSVD")

