--- 
:name: cggesx
:md5sum: 2f0b8d24265696a975f64dcdb1eefeec
:category: :subroutine
:arguments: 
- jobvsl: 
    :type: char
    :intent: input
- jobvsr: 
    :type: char
    :intent: input
- sort: 
    :type: char
    :intent: input
- selctg: 
    :intent: external procedure
    :block_type: logical
    :block_arg_num: 2
    :block_arg_type: complex
- sense: 
    :type: char
    :intent: input
- n: 
    :type: integer
    :intent: input
- a: 
    :type: complex
    :intent: input/output
    :dims: 
    - lda
    - n
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: complex
    :intent: input/output
    :dims: 
    - ldb
    - n
- ldb: 
    :type: integer
    :intent: input
- sdim: 
    :type: integer
    :intent: output
- alpha: 
    :type: complex
    :intent: output
    :dims: 
    - n
- beta: 
    :type: complex
    :intent: output
    :dims: 
    - n
- vsl: 
    :type: complex
    :intent: output
    :dims: 
    - ldvsl
    - n
- ldvsl: 
    :type: integer
    :intent: input
- vsr: 
    :type: complex
    :intent: output
    :dims: 
    - ldvsr
    - n
- ldvsr: 
    :type: integer
    :intent: input
- rconde: 
    :type: real
    :intent: output
    :dims: 
    - "2"
- rcondv: 
    :type: real
    :intent: output
    :dims: 
    - "2"
- work: 
    :type: complex
    :intent: output
    :dims: 
    - MAX(1,lwork)
- lwork: 
    :type: integer
    :intent: input
    :option: true
    :default: "n==0 ? 1 : (lsame_(&sense,\"E\")||lsame_(&sense,\"V\")||lsame_(&sense,\"B\")) ? MAX(2*n,n*n/2) : 2*n"
- rwork: 
    :type: real
    :intent: workspace
    :dims: 
    - 8*n
- iwork: 
    :type: integer
    :intent: output
    :dims: 
    - MAX(1,liwork)
- liwork: 
    :type: integer
    :intent: input
    :option: true
    :default: "(lsame_(&sense,\"N\")||n==0) ? 1 : n+2"
- bwork: 
    :type: logical
    :intent: workspace
    :dims: 
    - "lsame_(&sort,\"N\") ? 0 : n"
- info: 
    :type: integer
    :intent: output
:substitutions: 
  ldvsl: "lsame_(&jobvsl,\"V\") ? n : 1"
  ldvsr: "lsame_(&jobvsr,\"V\") ? n : 1"
:fortran_help: "      SUBROUTINE CGGESX( JOBVSL, JOBVSR, SORT, SELCTG, SENSE, N, A, LDA, B, LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, RCONDE, RCONDV, WORK, LWORK, RWORK, IWORK, LIWORK, BWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  CGGESX computes for a pair of N-by-N complex nonsymmetric matrices\n\
  *  (A,B), the generalized eigenvalues, the complex Schur form (S,T),\n\
  *  and, optionally, the left and/or right matrices of Schur vectors (VSL\n\
  *  and VSR).  This gives the generalized Schur factorization\n\
  *\n\
  *       (A,B) = ( (VSL) S (VSR)**H, (VSL) T (VSR)**H )\n\
  *\n\
  *  where (VSR)**H is the conjugate-transpose of VSR.\n\
  *\n\
  *  Optionally, it also orders the eigenvalues so that a selected cluster\n\
  *  of eigenvalues appears in the leading diagonal blocks of the upper\n\
  *  triangular matrix S and the upper triangular matrix T; computes\n\
  *  a reciprocal condition number for the average of the selected\n\
  *  eigenvalues (RCONDE); and computes a reciprocal condition number for\n\
  *  the right and left deflating subspaces corresponding to the selected\n\
  *  eigenvalues (RCONDV). The leading columns of VSL and VSR then form\n\
  *  an orthonormal basis for the corresponding left and right eigenspaces\n\
  *  (deflating subspaces).\n\
  *\n\
  *  A generalized eigenvalue for a pair of matrices (A,B) is a scalar w\n\
  *  or a ratio alpha/beta = w, such that  A - w*B is singular.  It is\n\
  *  usually represented as the pair (alpha,beta), as there is a\n\
  *  reasonable interpretation for beta=0 or for both being zero.\n\
  *\n\
  *  A pair of matrices (S,T) is in generalized complex Schur form if T is\n\
  *  upper triangular with non-negative diagonal and S is upper\n\
  *  triangular.\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  JOBVSL  (input) CHARACTER*1\n\
  *          = 'N':  do not compute the left Schur vectors;\n\
  *          = 'V':  compute the left Schur vectors.\n\
  *\n\
  *  JOBVSR  (input) CHARACTER*1\n\
  *          = 'N':  do not compute the right Schur vectors;\n\
  *          = 'V':  compute the right Schur vectors.\n\
  *\n\
  *  SORT    (input) CHARACTER*1\n\
  *          Specifies whether or not to order the eigenvalues on the\n\
  *          diagonal of the generalized Schur form.\n\
  *          = 'N':  Eigenvalues are not ordered;\n\
  *          = 'S':  Eigenvalues are ordered (see SELCTG).\n\
  *\n\
  *  SELCTG  (external procedure) LOGICAL FUNCTION of two COMPLEX arguments\n\
  *          SELCTG must be declared EXTERNAL in the calling subroutine.\n\
  *          If SORT = 'N', SELCTG is not referenced.\n\
  *          If SORT = 'S', SELCTG is used to select eigenvalues to sort\n\
  *          to the top left of the Schur form.\n\
  *          Note that a selected complex eigenvalue may no longer satisfy\n\
  *          SELCTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since\n\
  *          ordering may change the value of complex eigenvalues\n\
  *          (especially if the eigenvalue is ill-conditioned), in this\n\
  *          case INFO is set to N+3 see INFO below).\n\
  *\n\
  *  SENSE   (input) CHARACTER*1\n\
  *          Determines which reciprocal condition numbers are computed.\n\
  *          = 'N' : None are computed;\n\
  *          = 'E' : Computed for average of selected eigenvalues only;\n\
  *          = 'V' : Computed for selected deflating subspaces only;\n\
  *          = 'B' : Computed for both.\n\
  *          If SENSE = 'E', 'V', or 'B', SORT must equal 'S'.\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The order of the matrices A, B, VSL, and VSR.  N >= 0.\n\
  *\n\
  *  A       (input/output) COMPLEX array, dimension (LDA, N)\n\
  *          On entry, the first of the pair of matrices.\n\
  *          On exit, A has been overwritten by its generalized Schur\n\
  *          form S.\n\
  *\n\
  *  LDA     (input) INTEGER\n\
  *          The leading dimension of A.  LDA >= max(1,N).\n\
  *\n\
  *  B       (input/output) COMPLEX array, dimension (LDB, N)\n\
  *          On entry, the second of the pair of matrices.\n\
  *          On exit, B has been overwritten by its generalized Schur\n\
  *          form T.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of B.  LDB >= max(1,N).\n\
  *\n\
  *  SDIM    (output) INTEGER\n\
  *          If SORT = 'N', SDIM = 0.\n\
  *          If SORT = 'S', SDIM = number of eigenvalues (after sorting)\n\
  *          for which SELCTG is true.\n\
  *\n\
  *  ALPHA   (output) COMPLEX array, dimension (N)\n\
  *  BETA    (output) COMPLEX array, dimension (N)\n\
  *          On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the\n\
  *          generalized eigenvalues.  ALPHA(j) and BETA(j),j=1,...,N  are\n\
  *          the diagonals of the complex Schur form (S,T).  BETA(j) will\n\
  *          be non-negative real.\n\
  *\n\
  *          Note: the quotients ALPHA(j)/BETA(j) may easily over- or\n\
  *          underflow, and BETA(j) may even be zero.  Thus, the user\n\
  *          should avoid naively computing the ratio alpha/beta.\n\
  *          However, ALPHA will be always less than and usually\n\
  *          comparable with norm(A) in magnitude, and BETA always less\n\
  *          than and usually comparable with norm(B).\n\
  *\n\
  *  VSL     (output) COMPLEX array, dimension (LDVSL,N)\n\
  *          If JOBVSL = 'V', VSL will contain the left Schur vectors.\n\
  *          Not referenced if JOBVSL = 'N'.\n\
  *\n\
  *  LDVSL   (input) INTEGER\n\
  *          The leading dimension of the matrix VSL. LDVSL >=1, and\n\
  *          if JOBVSL = 'V', LDVSL >= N.\n\
  *\n\
  *  VSR     (output) COMPLEX array, dimension (LDVSR,N)\n\
  *          If JOBVSR = 'V', VSR will contain the right Schur vectors.\n\
  *          Not referenced if JOBVSR = 'N'.\n\
  *\n\
  *  LDVSR   (input) INTEGER\n\
  *          The leading dimension of the matrix VSR. LDVSR >= 1, and\n\
  *          if JOBVSR = 'V', LDVSR >= N.\n\
  *\n\
  *  RCONDE  (output) REAL array, dimension ( 2 )\n\
  *          If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the\n\
  *          reciprocal condition numbers for the average of the selected\n\
  *          eigenvalues.\n\
  *          Not referenced if SENSE = 'N' or 'V'.\n\
  *\n\
  *  RCONDV  (output) REAL array, dimension ( 2 )\n\
  *          If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the\n\
  *          reciprocal condition number for the selected deflating\n\
  *          subspaces.\n\
  *          Not referenced if SENSE = 'N' or 'E'.\n\
  *\n\
  *  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK))\n\
  *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n\
  *\n\
  *  LWORK   (input) INTEGER\n\
  *          The dimension of the array WORK.\n\
  *          If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B',\n\
  *          LWORK >= MAX(1,2*N,2*SDIM*(N-SDIM)), else\n\
  *          LWORK >= MAX(1,2*N).  Note that 2*SDIM*(N-SDIM) <= N*N/2.\n\
  *          Note also that an error is only returned if\n\
  *          LWORK < MAX(1,2*N), but if SENSE = 'E' or 'V' or 'B' this may\n\
  *          not be large enough.\n\
  *\n\
  *          If LWORK = -1, then a workspace query is assumed; the routine\n\
  *          only calculates the bound on the optimal size of the WORK\n\
  *          array and the minimum size of the IWORK array, returns these\n\
  *          values as the first entries of the WORK and IWORK arrays, and\n\
  *          no error message related to LWORK or LIWORK is issued by\n\
  *          XERBLA.\n\
  *\n\
  *  RWORK   (workspace) REAL array, dimension ( 8*N )\n\
  *          Real workspace.\n\
  *\n\
  *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))\n\
  *          On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK.\n\
  *\n\
  *  LIWORK  (input) INTEGER\n\
  *          The dimension of the array WORK.\n\
  *          If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise\n\
  *          LIWORK >= N+2.\n\
  *\n\
  *          If LIWORK = -1, then a workspace query is assumed; the\n\
  *          routine only calculates the bound on the optimal size of the\n\
  *          WORK array and the minimum size of the IWORK array, returns\n\
  *          these values as the first entries of the WORK and IWORK\n\
  *          arrays, and no error message related to LWORK or LIWORK is\n\
  *          issued by XERBLA.\n\
  *\n\
  *  BWORK   (workspace) LOGICAL array, dimension (N)\n\
  *          Not referenced if SORT = 'N'.\n\
  *\n\
  *  INFO    (output) INTEGER\n\
  *          = 0:  successful exit\n\
  *          < 0:  if INFO = -i, the i-th argument had an illegal value.\n\
  *          = 1,...,N:\n\
  *                The QZ iteration failed.  (A,B) are not in Schur\n\
  *                form, but ALPHA(j) and BETA(j) should be correct for\n\
  *                j=INFO+1,...,N.\n\
  *          > N:  =N+1: other than QZ iteration failed in CHGEQZ\n\
  *                =N+2: after reordering, roundoff changed values of\n\
  *                      some complex eigenvalues so that leading\n\
  *                      eigenvalues in the Generalized Schur form no\n\
  *                      longer satisfy SELCTG=.TRUE.  This could also\n\
  *                      be caused due to scaling.\n\
  *                =N+3: reordering failed in CTGSEN.\n\
  *\n\n\
  *  =====================================================================\n\
  *\n"
