--- 
:name: zggsvd
:md5sum: 9dac70b38c11dc008b1cd1e000dc4156
:category: :subroutine
:arguments: 
- jobu: 
    :type: char
    :intent: input
- jobv: 
    :type: char
    :intent: input
- jobq: 
    :type: char
    :intent: input
- m: 
    :type: integer
    :intent: input
- n: 
    :type: integer
    :intent: input
- p: 
    :type: integer
    :intent: input
- k: 
    :type: integer
    :intent: output
- l: 
    :type: integer
    :intent: output
- a: 
    :type: doublecomplex
    :intent: input/output
    :dims: 
    - lda
    - n
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: doublecomplex
    :intent: input/output
    :dims: 
    - ldb
    - n
- ldb: 
    :type: integer
    :intent: input
- alpha: 
    :type: doublereal
    :intent: output
    :dims: 
    - n
- beta: 
    :type: doublereal
    :intent: output
    :dims: 
    - n
- u: 
    :type: doublecomplex
    :intent: output
    :dims: 
    - ldu
    - m
- ldu: 
    :type: integer
    :intent: input
- v: 
    :type: doublecomplex
    :intent: output
    :dims: 
    - ldv
    - p
- ldv: 
    :type: integer
    :intent: input
- q: 
    :type: doublecomplex
    :intent: output
    :dims: 
    - ldq
    - n
- ldq: 
    :type: integer
    :intent: input
- work: 
    :type: doublecomplex
    :intent: workspace
    :dims: 
    - MAX(3*n,m
    - p)+n
- rwork: 
    :type: doublereal
    :intent: workspace
    :dims: 
    - 2*n
- iwork: 
    :type: integer
    :intent: output
    :dims: 
    - n
- info: 
    :type: integer
    :intent: output
:substitutions: 
  m: lda
  p: ldb
  ldq: "lsame_(&jobq,\"Q\") ? MAX(1,n) : 1"
  ldu: "lsame_(&jobu,\"U\") ? MAX(1,m) : 1"
  ldv: "lsame_(&jobv,\"V\") ? MAX(1,p) : 1"
:fortran_help: "      SUBROUTINE ZGGSVD( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B, LDB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ, WORK, RWORK, IWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  ZGGSVD computes the generalized singular value decomposition (GSVD)\n\
  *  of an M-by-N complex matrix A and P-by-N complex matrix B:\n\
  *\n\
  *        U'*A*Q = D1*( 0 R ),    V'*B*Q = D2*( 0 R )\n\
  *\n\
  *  where U, V and Q are unitary matrices, and Z' means the conjugate\n\
  *  transpose of Z.  Let K+L = the effective numerical rank of the\n\
  *  matrix (A',B')', then R is a (K+L)-by-(K+L) nonsingular upper\n\
  *  triangular matrix, D1 and D2 are M-by-(K+L) and P-by-(K+L) \"diagonal\"\n\
  *  matrices and of the following structures, respectively:\n\
  *\n\
  *  If M-K-L >= 0,\n\
  *\n\
  *                      K  L\n\
  *         D1 =     K ( I  0 )\n\
  *                  L ( 0  C )\n\
  *              M-K-L ( 0  0 )\n\
  *\n\
  *                    K  L\n\
  *         D2 =   L ( 0  S )\n\
  *              P-L ( 0  0 )\n\
  *\n\
  *                  N-K-L  K    L\n\
  *    ( 0 R ) = K (  0   R11  R12 )\n\
  *              L (  0    0   R22 )\n\
  *  where\n\
  *\n\
  *    C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),\n\
  *    S = diag( BETA(K+1),  ... , BETA(K+L) ),\n\
  *    C**2 + S**2 = I.\n\
  *\n\
  *    R is stored in A(1:K+L,N-K-L+1:N) on exit.\n\
  *\n\
  *  If M-K-L < 0,\n\
  *\n\
  *                    K M-K K+L-M\n\
  *         D1 =   K ( I  0    0   )\n\
  *              M-K ( 0  C    0   )\n\
  *\n\
  *                      K M-K K+L-M\n\
  *         D2 =   M-K ( 0  S    0  )\n\
  *              K+L-M ( 0  0    I  )\n\
  *                P-L ( 0  0    0  )\n\
  *\n\
  *                     N-K-L  K   M-K  K+L-M\n\
  *    ( 0 R ) =     K ( 0    R11  R12  R13  )\n\
  *                M-K ( 0     0   R22  R23  )\n\
  *              K+L-M ( 0     0    0   R33  )\n\
  *\n\
  *  where\n\
  *\n\
  *    C = diag( ALPHA(K+1), ... , ALPHA(M) ),\n\
  *    S = diag( BETA(K+1),  ... , BETA(M) ),\n\
  *    C**2 + S**2 = I.\n\
  *\n\
  *    (R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored\n\
  *    ( 0  R22 R23 )\n\
  *    in B(M-K+1:L,N+M-K-L+1:N) on exit.\n\
  *\n\
  *  The routine computes C, S, R, and optionally the unitary\n\
  *  transformation matrices U, V and Q.\n\
  *\n\
  *  In particular, if B is an N-by-N nonsingular matrix, then the GSVD of\n\
  *  A and B implicitly gives the SVD of A*inv(B):\n\
  *                       A*inv(B) = U*(D1*inv(D2))*V'.\n\
  *  If ( A',B')' has orthnormal columns, then the GSVD of A and B is also\n\
  *  equal to the CS decomposition of A and B. Furthermore, the GSVD can\n\
  *  be used to derive the solution of the eigenvalue problem:\n\
  *                       A'*A x = lambda* B'*B x.\n\
  *  In some literature, the GSVD of A and B is presented in the form\n\
  *                   U'*A*X = ( 0 D1 ),   V'*B*X = ( 0 D2 )\n\
  *  where U and V are orthogonal and X is nonsingular, and D1 and D2 are\n\
  *  ``diagonal''.  The former GSVD form can be converted to the latter\n\
  *  form by taking the nonsingular matrix X as\n\
  *\n\
  *                        X = Q*(  I   0    )\n\
  *                              (  0 inv(R) )\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  JOBU    (input) CHARACTER*1\n\
  *          = 'U':  Unitary matrix U is computed;\n\
  *          = 'N':  U is not computed.\n\
  *\n\
  *  JOBV    (input) CHARACTER*1\n\
  *          = 'V':  Unitary matrix V is computed;\n\
  *          = 'N':  V is not computed.\n\
  *\n\
  *  JOBQ    (input) CHARACTER*1\n\
  *          = 'Q':  Unitary matrix Q is computed;\n\
  *          = 'N':  Q is not computed.\n\
  *\n\
  *  M       (input) INTEGER\n\
  *          The number of rows of the matrix A.  M >= 0.\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The number of columns of the matrices A and B.  N >= 0.\n\
  *\n\
  *  P       (input) INTEGER\n\
  *          The number of rows of the matrix B.  P >= 0.\n\
  *\n\
  *  K       (output) INTEGER\n\
  *  L       (output) INTEGER\n\
  *          On exit, K and L specify the dimension of the subblocks\n\
  *          described in Purpose.\n\
  *          K + L = effective numerical rank of (A',B')'.\n\
  *\n\
  *  A       (input/output) COMPLEX*16 array, dimension (LDA,N)\n\
  *          On entry, the M-by-N matrix A.\n\
  *          On exit, A contains the triangular matrix R, or part of R.\n\
  *          See Purpose for details.\n\
  *\n\
  *  LDA     (input) INTEGER\n\
  *          The leading dimension of the array A. LDA >= max(1,M).\n\
  *\n\
  *  B       (input/output) COMPLEX*16 array, dimension (LDB,N)\n\
  *          On entry, the P-by-N matrix B.\n\
  *          On exit, B contains part of the triangular matrix R if\n\
  *          M-K-L < 0.  See Purpose for details.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of the array B. LDB >= max(1,P).\n\
  *\n\
  *  ALPHA   (output) DOUBLE PRECISION array, dimension (N)\n\
  *  BETA    (output) DOUBLE PRECISION array, dimension (N)\n\
  *          On exit, ALPHA and BETA contain the generalized singular\n\
  *          value pairs of A and B;\n\
  *            ALPHA(1:K) = 1,\n\
  *            BETA(1:K)  = 0,\n\
  *          and if M-K-L >= 0,\n\
  *            ALPHA(K+1:K+L) = C,\n\
  *            BETA(K+1:K+L)  = S,\n\
  *          or if M-K-L < 0,\n\
  *            ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0\n\
  *            BETA(K+1:M) = S, BETA(M+1:K+L) = 1\n\
  *          and\n\
  *            ALPHA(K+L+1:N) = 0\n\
  *            BETA(K+L+1:N)  = 0\n\
  *\n\
  *  U       (output) COMPLEX*16 array, dimension (LDU,M)\n\
  *          If JOBU = 'U', U contains the M-by-M unitary matrix U.\n\
  *          If JOBU = 'N', U is not referenced.\n\
  *\n\
  *  LDU     (input) INTEGER\n\
  *          The leading dimension of the array U. LDU >= max(1,M) if\n\
  *          JOBU = 'U'; LDU >= 1 otherwise.\n\
  *\n\
  *  V       (output) COMPLEX*16 array, dimension (LDV,P)\n\
  *          If JOBV = 'V', V contains the P-by-P unitary matrix V.\n\
  *          If JOBV = 'N', V is not referenced.\n\
  *\n\
  *  LDV     (input) INTEGER\n\
  *          The leading dimension of the array V. LDV >= max(1,P) if\n\
  *          JOBV = 'V'; LDV >= 1 otherwise.\n\
  *\n\
  *  Q       (output) COMPLEX*16 array, dimension (LDQ,N)\n\
  *          If JOBQ = 'Q', Q contains the N-by-N unitary matrix Q.\n\
  *          If JOBQ = 'N', Q is not referenced.\n\
  *\n\
  *  LDQ     (input) INTEGER\n\
  *          The leading dimension of the array Q. LDQ >= max(1,N) if\n\
  *          JOBQ = 'Q'; LDQ >= 1 otherwise.\n\
  *\n\
  *  WORK    (workspace) COMPLEX*16 array, dimension (max(3*N,M,P)+N)\n\
  *\n\
  *  RWORK   (workspace) DOUBLE PRECISION array, dimension (2*N)\n\
  *\n\
  *  IWORK   (workspace/output) INTEGER array, dimension (N)\n\
  *          On exit, IWORK stores the sorting information. More\n\
  *          precisely, the following loop will sort ALPHA\n\
  *             for I = K+1, min(M,K+L)\n\
  *                 swap ALPHA(I) and ALPHA(IWORK(I))\n\
  *             endfor\n\
  *          such that ALPHA(1) >= ALPHA(2) >= ... >= ALPHA(N).\n\
  *\n\
  *  INFO    (output) INTEGER\n\
  *          = 0:  successful exit.\n\
  *          < 0:  if INFO = -i, the i-th argument had an illegal value.\n\
  *          > 0:  if INFO = 1, the Jacobi-type procedure failed to\n\
  *                converge.  For further details, see subroutine ZTGSJA.\n\
  *\n\
  *  Internal Parameters\n\
  *  ===================\n\
  *\n\
  *  TOLA    DOUBLE PRECISION\n\
  *  TOLB    DOUBLE PRECISION\n\
  *          TOLA and TOLB are the thresholds to determine the effective\n\
  *          rank of (A',B')'. Generally, they are set to\n\
  *                   TOLA = MAX(M,N)*norm(A)*MAZHEPS,\n\
  *                   TOLB = MAX(P,N)*norm(B)*MAZHEPS.\n\
  *          The size of TOLA and TOLB may affect the size of backward\n\
  *          errors of the decomposition.\n\
  *\n\n\
  *  Further Details\n\
  *  ===============\n\
  *\n\
  *  2-96 Based on modifications by\n\
  *     Ming Gu and Huan Ren, Computer Science Division, University of\n\
  *     California at Berkeley, USA\n\
  *\n\
  *  =====================================================================\n\
  *\n\
  *     .. Local Scalars ..\n      LOGICAL            WANTQ, WANTU, WANTV\n      INTEGER            I, IBND, ISUB, J, NCYCLE\n      DOUBLE PRECISION   ANORM, BNORM, SMAX, TEMP, TOLA, TOLB, ULP, UNFL\n\
  *     ..\n\
  *     .. External Functions ..\n      LOGICAL            LSAME\n      DOUBLE PRECISION   DLAMCH, ZLANGE\n      EXTERNAL           LSAME, DLAMCH, ZLANGE\n\
  *     ..\n\
  *     .. External Subroutines ..\n      EXTERNAL           DCOPY, XERBLA, ZGGSVP, ZTGSJA\n\
  *     ..\n\
  *     .. Intrinsic Functions ..\n      INTRINSIC          MAX, MIN\n\
  *     ..\n"
