--- 
:name: stgex2
:md5sum: 0ff12ef41f70e923d7440270d8c9e9f1
:category: :subroutine
:arguments: 
- wantq: 
    :type: logical
    :intent: input
- wantz: 
    :type: logical
    :intent: input
- n: 
    :type: integer
    :intent: input
- a: 
    :type: real
    :intent: input/output
    :dims: 
    - lda
    - n
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: real
    :intent: input/output
    :dims: 
    - ldb
    - n
- ldb: 
    :type: integer
    :intent: input
- q: 
    :type: real
    :intent: input/output
    :dims: 
    - ldz
    - n
- ldq: 
    :type: integer
    :intent: input
- z: 
    :type: real
    :intent: input/output
    :dims: 
    - ldz
    - n
- ldz: 
    :type: integer
    :intent: input
- j1: 
    :type: integer
    :intent: input
- n1: 
    :type: integer
    :intent: input
- n2: 
    :type: integer
    :intent: input
- work: 
    :type: real
    :intent: workspace
    :dims: 
    - lwork
- lwork: 
    :type: integer
    :intent: input
    :option: true
    :default: MAX(n*(n2+n1), (n2+n1)*(n2+n1)*2)
- info: 
    :type: integer
    :intent: output
:substitutions: 
  lwork: MAX(1,(MAX(n*(n2+n1),(n2+n1)*(n2+n1)*2)))
:fortran_help: "      SUBROUTINE STGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z, LDZ, J1, N1, N2, WORK, LWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  STGEX2 swaps adjacent diagonal blocks (A11, B11) and (A22, B22)\n\
  *  of size 1-by-1 or 2-by-2 in an upper (quasi) triangular matrix pair\n\
  *  (A, B) by an orthogonal equivalence transformation.\n\
  *\n\
  *  (A, B) must be in generalized real Schur canonical form (as returned\n\
  *  by SGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2\n\
  *  diagonal blocks. B is upper triangular.\n\
  *\n\
  *  Optionally, the matrices Q and Z of generalized Schur vectors are\n\
  *  updated.\n\
  *\n\
  *         Q(in) * A(in) * Z(in)' = Q(out) * A(out) * Z(out)'\n\
  *         Q(in) * B(in) * Z(in)' = Q(out) * B(out) * Z(out)'\n\
  *\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  WANTQ   (input) LOGICAL\n\
  *          .TRUE. : update the left transformation matrix Q;\n\
  *          .FALSE.: do not update Q.\n\
  *\n\
  *  WANTZ   (input) LOGICAL\n\
  *          .TRUE. : update the right transformation matrix Z;\n\
  *          .FALSE.: do not update Z.\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The order of the matrices A and B. N >= 0.\n\
  *\n\
  *  A      (input/output) REAL arrays, dimensions (LDA,N)\n\
  *          On entry, the matrix A in the pair (A, B).\n\
  *          On exit, the updated matrix A.\n\
  *\n\
  *  LDA     (input)  INTEGER\n\
  *          The leading dimension of the array A. LDA >= max(1,N).\n\
  *\n\
  *  B      (input/output) REAL arrays, dimensions (LDB,N)\n\
  *          On entry, the matrix B in the pair (A, B).\n\
  *          On exit, the updated matrix B.\n\
  *\n\
  *  LDB     (input)  INTEGER\n\
  *          The leading dimension of the array B. LDB >= max(1,N).\n\
  *\n\
  *  Q       (input/output) REAL array, dimension (LDZ,N)\n\
  *          On entry, if WANTQ = .TRUE., the orthogonal matrix Q.\n\
  *          On exit, the updated matrix Q.\n\
  *          Not referenced if WANTQ = .FALSE..\n\
  *\n\
  *  LDQ     (input) INTEGER\n\
  *          The leading dimension of the array Q. LDQ >= 1.\n\
  *          If WANTQ = .TRUE., LDQ >= N.\n\
  *\n\
  *  Z       (input/output) REAL array, dimension (LDZ,N)\n\
  *          On entry, if WANTZ =.TRUE., the orthogonal matrix Z.\n\
  *          On exit, the updated matrix Z.\n\
  *          Not referenced if WANTZ = .FALSE..\n\
  *\n\
  *  LDZ     (input) INTEGER\n\
  *          The leading dimension of the array Z. LDZ >= 1.\n\
  *          If WANTZ = .TRUE., LDZ >= N.\n\
  *\n\
  *  J1      (input) INTEGER\n\
  *          The index to the first block (A11, B11). 1 <= J1 <= N.\n\
  *\n\
  *  N1      (input) INTEGER\n\
  *          The order of the first block (A11, B11). N1 = 0, 1 or 2.\n\
  *\n\
  *  N2      (input) INTEGER\n\
  *          The order of the second block (A22, B22). N2 = 0, 1 or 2.\n\
  *\n\
  *  WORK    (workspace) REAL array, dimension (MAX(1,LWORK)).\n\
  *\n\
  *  LWORK   (input) INTEGER\n\
  *          The dimension of the array WORK.\n\
  *          LWORK >=  MAX( N*(N2+N1), (N2+N1)*(N2+N1)*2 )\n\
  *\n\
  *  INFO    (output) INTEGER\n\
  *            =0: Successful exit\n\
  *            >0: If INFO = 1, the transformed matrix (A, B) would be\n\
  *                too far from generalized Schur form; the blocks are\n\
  *                not swapped and (A, B) and (Q, Z) are unchanged.\n\
  *                The problem of swapping is too ill-conditioned.\n\
  *            <0: If INFO = -16: LWORK is too small. Appropriate value\n\
  *                for LWORK is returned in WORK(1).\n\
  *\n\n\
  *  Further Details\n\
  *  ===============\n\
  *\n\
  *  Based on contributions by\n\
  *     Bo Kagstrom and Peter Poromaa, Department of Computing Science,\n\
  *     Umea University, S-901 87 Umea, Sweden.\n\
  *\n\
  *  In the current code both weak and strong stability tests are\n\
  *  performed. The user can omit the strong stability test by changing\n\
  *  the internal logical parameter WANDS to .FALSE.. See ref. [2] for\n\
  *  details.\n\
  *\n\
  *  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the\n\
  *      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in\n\
  *      M.S. Moonen et al (eds), Linear Algebra for Large Scale and\n\
  *      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218.\n\
  *\n\
  *  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified\n\
  *      Eigenvalues of a Regular Matrix Pair (A, B) and Condition\n\
  *      Estimation: Theory, Algorithms and Software,\n\
  *      Report UMINF - 94.04, Department of Computing Science, Umea\n\
  *      University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working\n\
  *      Note 87. To appear in Numerical Algorithms, 1996.\n\
  *\n\
  *  =====================================================================\n\
  *  Replaced various illegal calls to SCOPY by calls to SLASET, or by DO\n\
  *  loops. Sven Hammarling, 1/5/02.\n\
  *\n"
