LAPACK 3.3.1
Linear Algebra PACKage

dtgex2.f

Go to the documentation of this file.
00001       SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
00002      $                   LDZ, J1, N1, N2, WORK, LWORK, INFO )
00003 *
00004 *  -- LAPACK auxiliary routine (version 3.3.1) --
00005 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00006 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00007 *  -- April 2011                                                      --
00008 *
00009 *     .. Scalar Arguments ..
00010       LOGICAL            WANTQ, WANTZ
00011       INTEGER            INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
00012 *     ..
00013 *     .. Array Arguments ..
00014       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
00015      $                   WORK( * ), Z( LDZ, * )
00016 *     ..
00017 *
00018 *  Purpose
00019 *  =======
00020 *
00021 *  DTGEX2 swaps adjacent diagonal blocks (A11, B11) and (A22, B22)
00022 *  of size 1-by-1 or 2-by-2 in an upper (quasi) triangular matrix pair
00023 *  (A, B) by an orthogonal equivalence transformation.
00024 *
00025 *  (A, B) must be in generalized real Schur canonical form (as returned
00026 *  by DGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2
00027 *  diagonal blocks. B is upper triangular.
00028 *
00029 *  Optionally, the matrices Q and Z of generalized Schur vectors are
00030 *  updated.
00031 *
00032 *         Q(in) * A(in) * Z(in)**T = Q(out) * A(out) * Z(out)**T
00033 *         Q(in) * B(in) * Z(in)**T = Q(out) * B(out) * Z(out)**T
00034 *
00035 *
00036 *  Arguments
00037 *  =========
00038 *
00039 *  WANTQ   (input) LOGICAL
00040 *          .TRUE. : update the left transformation matrix Q;
00041 *          .FALSE.: do not update Q.
00042 *
00043 *  WANTZ   (input) LOGICAL
00044 *          .TRUE. : update the right transformation matrix Z;
00045 *          .FALSE.: do not update Z.
00046 *
00047 *  N       (input) INTEGER
00048 *          The order of the matrices A and B. N >= 0.
00049 *
00050 *  A       (input/output) DOUBLE PRECISION array, dimensions (LDA,N)
00051 *          On entry, the matrix A in the pair (A, B).
00052 *          On exit, the updated matrix A.
00053 *
00054 *  LDA     (input) INTEGER
00055 *          The leading dimension of the array A. LDA >= max(1,N).
00056 *
00057 *  B       (input/output) DOUBLE PRECISION array, dimensions (LDB,N)
00058 *          On entry, the matrix B in the pair (A, B).
00059 *          On exit, the updated matrix B.
00060 *
00061 *  LDB     (input) INTEGER
00062 *          The leading dimension of the array B. LDB >= max(1,N).
00063 *
00064 *  Q       (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
00065 *          On entry, if WANTQ = .TRUE., the orthogonal matrix Q.
00066 *          On exit, the updated matrix Q.
00067 *          Not referenced if WANTQ = .FALSE..
00068 *
00069 *  LDQ     (input) INTEGER
00070 *          The leading dimension of the array Q. LDQ >= 1.
00071 *          If WANTQ = .TRUE., LDQ >= N.
00072 *
00073 *  Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
00074 *          On entry, if WANTZ =.TRUE., the orthogonal matrix Z.
00075 *          On exit, the updated matrix Z.
00076 *          Not referenced if WANTZ = .FALSE..
00077 *
00078 *  LDZ     (input) INTEGER
00079 *          The leading dimension of the array Z. LDZ >= 1.
00080 *          If WANTZ = .TRUE., LDZ >= N.
00081 *
00082 *  J1      (input) INTEGER
00083 *          The index to the first block (A11, B11). 1 <= J1 <= N.
00084 *
00085 *  N1      (input) INTEGER
00086 *          The order of the first block (A11, B11). N1 = 0, 1 or 2.
00087 *
00088 *  N2      (input) INTEGER
00089 *          The order of the second block (A22, B22). N2 = 0, 1 or 2.
00090 *
00091 *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)).
00092 *
00093 *  LWORK   (input) INTEGER
00094 *          The dimension of the array WORK.
00095 *          LWORK >=  MAX( 1, N*(N2+N1), (N2+N1)*(N2+N1)*2 )
00096 *
00097 *  INFO    (output) INTEGER
00098 *            =0: Successful exit
00099 *            >0: If INFO = 1, the transformed matrix (A, B) would be
00100 *                too far from generalized Schur form; the blocks are
00101 *                not swapped and (A, B) and (Q, Z) are unchanged.
00102 *                The problem of swapping is too ill-conditioned.
00103 *            <0: If INFO = -16: LWORK is too small. Appropriate value
00104 *                for LWORK is returned in WORK(1).
00105 *
00106 *  Further Details
00107 *  ===============
00108 *
00109 *  Based on contributions by
00110 *     Bo Kagstrom and Peter Poromaa, Department of Computing Science,
00111 *     Umea University, S-901 87 Umea, Sweden.
00112 *
00113 *  In the current code both weak and strong stability tests are
00114 *  performed. The user can omit the strong stability test by changing
00115 *  the internal logical parameter WANDS to .FALSE.. See ref. [2] for
00116 *  details.
00117 *
00118 *  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the
00119 *      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in
00120 *      M.S. Moonen et al (eds), Linear Algebra for Large Scale and
00121 *      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218.
00122 *
00123 *  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified
00124 *      Eigenvalues of a Regular Matrix Pair (A, B) and Condition
00125 *      Estimation: Theory, Algorithms and Software,
00126 *      Report UMINF - 94.04, Department of Computing Science, Umea
00127 *      University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working
00128 *      Note 87. To appear in Numerical Algorithms, 1996.
00129 *
00130 *  =====================================================================
00131 *  Replaced various illegal calls to DCOPY by calls to DLASET, or by DO
00132 *  loops. Sven Hammarling, 1/5/02.
00133 *
00134 *     .. Parameters ..
00135       DOUBLE PRECISION   ZERO, ONE
00136       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00137       DOUBLE PRECISION   TWENTY
00138       PARAMETER          ( TWENTY = 2.0D+01 )
00139       INTEGER            LDST
00140       PARAMETER          ( LDST = 4 )
00141       LOGICAL            WANDS
00142       PARAMETER          ( WANDS = .TRUE. )
00143 *     ..
00144 *     .. Local Scalars ..
00145       LOGICAL            DTRONG, WEAK
00146       INTEGER            I, IDUM, LINFO, M
00147       DOUBLE PRECISION   BQRA21, BRQA21, DDUM, DNORM, DSCALE, DSUM, EPS,
00148      $                   F, G, SA, SB, SCALE, SMLNUM, SS, THRESH, WS
00149 *     ..
00150 *     .. Local Arrays ..
00151       INTEGER            IWORK( LDST )
00152       DOUBLE PRECISION   AI( 2 ), AR( 2 ), BE( 2 ), IR( LDST, LDST ),
00153      $                   IRCOP( LDST, LDST ), LI( LDST, LDST ),
00154      $                   LICOP( LDST, LDST ), S( LDST, LDST ),
00155      $                   SCPY( LDST, LDST ), T( LDST, LDST ),
00156      $                   TAUL( LDST ), TAUR( LDST ), TCPY( LDST, LDST )
00157 *     ..
00158 *     .. External Functions ..
00159       DOUBLE PRECISION   DLAMCH
00160       EXTERNAL           DLAMCH
00161 *     ..
00162 *     .. External Subroutines ..
00163       EXTERNAL           DGEMM, DGEQR2, DGERQ2, DLACPY, DLAGV2, DLARTG,
00164      $                   DLASET, DLASSQ, DORG2R, DORGR2, DORM2R, DORMR2,
00165      $                   DROT, DSCAL, DTGSY2
00166 *     ..
00167 *     .. Intrinsic Functions ..
00168       INTRINSIC          ABS, MAX, SQRT
00169 *     ..
00170 *     .. Executable Statements ..
00171 *
00172       INFO = 0
00173 *
00174 *     Quick return if possible
00175 *
00176       IF( N.LE.1 .OR. N1.LE.0 .OR. N2.LE.0 )
00177      $   RETURN
00178       IF( N1.GT.N .OR. ( J1+N1 ).GT.N )
00179      $   RETURN
00180       M = N1 + N2
00181       IF( LWORK.LT.MAX( 1, N*M, M*M*2 ) ) THEN
00182          INFO = -16
00183          WORK( 1 ) = MAX( 1, N*M, M*M*2 )
00184          RETURN
00185       END IF
00186 *
00187       WEAK = .FALSE.
00188       DTRONG = .FALSE.
00189 *
00190 *     Make a local copy of selected block
00191 *
00192       CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, LI, LDST )
00193       CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, IR, LDST )
00194       CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, S, LDST )
00195       CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, T, LDST )
00196 *
00197 *     Compute threshold for testing acceptance of swapping.
00198 *
00199       EPS = DLAMCH( 'P' )
00200       SMLNUM = DLAMCH( 'S' ) / EPS
00201       DSCALE = ZERO
00202       DSUM = ONE
00203       CALL DLACPY( 'Full', M, M, S, LDST, WORK, M )
00204       CALL DLASSQ( M*M, WORK, 1, DSCALE, DSUM )
00205       CALL DLACPY( 'Full', M, M, T, LDST, WORK, M )
00206       CALL DLASSQ( M*M, WORK, 1, DSCALE, DSUM )
00207       DNORM = DSCALE*SQRT( DSUM )
00208 *
00209 *     THRES has been changed from 
00210 *        THRESH = MAX( TEN*EPS*SA, SMLNUM )
00211 *     to
00212 *        THRESH = MAX( TWENTY*EPS*SA, SMLNUM )
00213 *     on 04/01/10.
00214 *     "Bug" reported by Ondra Kamenik, confirmed by Julie Langou, fixed by
00215 *     Jim Demmel and Guillaume Revy. See forum post 1783.
00216 *
00217       THRESH = MAX( TWENTY*EPS*DNORM, SMLNUM )
00218 *
00219       IF( M.EQ.2 ) THEN
00220 *
00221 *        CASE 1: Swap 1-by-1 and 1-by-1 blocks.
00222 *
00223 *        Compute orthogonal QL and RQ that swap 1-by-1 and 1-by-1 blocks
00224 *        using Givens rotations and perform the swap tentatively.
00225 *
00226          F = S( 2, 2 )*T( 1, 1 ) - T( 2, 2 )*S( 1, 1 )
00227          G = S( 2, 2 )*T( 1, 2 ) - T( 2, 2 )*S( 1, 2 )
00228          SB = ABS( T( 2, 2 ) )
00229          SA = ABS( S( 2, 2 ) )
00230          CALL DLARTG( F, G, IR( 1, 2 ), IR( 1, 1 ), DDUM )
00231          IR( 2, 1 ) = -IR( 1, 2 )
00232          IR( 2, 2 ) = IR( 1, 1 )
00233          CALL DROT( 2, S( 1, 1 ), 1, S( 1, 2 ), 1, IR( 1, 1 ),
00234      $              IR( 2, 1 ) )
00235          CALL DROT( 2, T( 1, 1 ), 1, T( 1, 2 ), 1, IR( 1, 1 ),
00236      $              IR( 2, 1 ) )
00237          IF( SA.GE.SB ) THEN
00238             CALL DLARTG( S( 1, 1 ), S( 2, 1 ), LI( 1, 1 ), LI( 2, 1 ),
00239      $                   DDUM )
00240          ELSE
00241             CALL DLARTG( T( 1, 1 ), T( 2, 1 ), LI( 1, 1 ), LI( 2, 1 ),
00242      $                   DDUM )
00243          END IF
00244          CALL DROT( 2, S( 1, 1 ), LDST, S( 2, 1 ), LDST, LI( 1, 1 ),
00245      $              LI( 2, 1 ) )
00246          CALL DROT( 2, T( 1, 1 ), LDST, T( 2, 1 ), LDST, LI( 1, 1 ),
00247      $              LI( 2, 1 ) )
00248          LI( 2, 2 ) = LI( 1, 1 )
00249          LI( 1, 2 ) = -LI( 2, 1 )
00250 *
00251 *        Weak stability test:
00252 *           |S21| + |T21| <= O(EPS * F-norm((S, T)))
00253 *
00254          WS = ABS( S( 2, 1 ) ) + ABS( T( 2, 1 ) )
00255          WEAK = WS.LE.THRESH
00256          IF( .NOT.WEAK )
00257      $      GO TO 70
00258 *
00259          IF( WANDS ) THEN
00260 *
00261 *           Strong stability test:
00262 *             F-norm((A-QL**T*S*QR, B-QL**T*T*QR)) <= O(EPS*F-norm((A,B)))
00263 *
00264             CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, WORK( M*M+1 ),
00265      $                   M )
00266             CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
00267      $                  WORK, M )
00268             CALL DGEMM( 'N', 'T', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
00269      $                  WORK( M*M+1 ), M )
00270             DSCALE = ZERO
00271             DSUM = ONE
00272             CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
00273 *
00274             CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, WORK( M*M+1 ),
00275      $                   M )
00276             CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
00277      $                  WORK, M )
00278             CALL DGEMM( 'N', 'T', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
00279      $                  WORK( M*M+1 ), M )
00280             CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
00281             SS = DSCALE*SQRT( DSUM )
00282             DTRONG = SS.LE.THRESH
00283             IF( .NOT.DTRONG )
00284      $         GO TO 70
00285          END IF
00286 *
00287 *        Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and
00288 *               (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)).
00289 *
00290          CALL DROT( J1+1, A( 1, J1 ), 1, A( 1, J1+1 ), 1, IR( 1, 1 ),
00291      $              IR( 2, 1 ) )
00292          CALL DROT( J1+1, B( 1, J1 ), 1, B( 1, J1+1 ), 1, IR( 1, 1 ),
00293      $              IR( 2, 1 ) )
00294          CALL DROT( N-J1+1, A( J1, J1 ), LDA, A( J1+1, J1 ), LDA,
00295      $              LI( 1, 1 ), LI( 2, 1 ) )
00296          CALL DROT( N-J1+1, B( J1, J1 ), LDB, B( J1+1, J1 ), LDB,
00297      $              LI( 1, 1 ), LI( 2, 1 ) )
00298 *
00299 *        Set  N1-by-N2 (2,1) - blocks to ZERO.
00300 *
00301          A( J1+1, J1 ) = ZERO
00302          B( J1+1, J1 ) = ZERO
00303 *
00304 *        Accumulate transformations into Q and Z if requested.
00305 *
00306          IF( WANTZ )
00307      $      CALL DROT( N, Z( 1, J1 ), 1, Z( 1, J1+1 ), 1, IR( 1, 1 ),
00308      $                 IR( 2, 1 ) )
00309          IF( WANTQ )
00310      $      CALL DROT( N, Q( 1, J1 ), 1, Q( 1, J1+1 ), 1, LI( 1, 1 ),
00311      $                 LI( 2, 1 ) )
00312 *
00313 *        Exit with INFO = 0 if swap was successfully performed.
00314 *
00315          RETURN
00316 *
00317       ELSE
00318 *
00319 *        CASE 2: Swap 1-by-1 and 2-by-2 blocks, or 2-by-2
00320 *                and 2-by-2 blocks.
00321 *
00322 *        Solve the generalized Sylvester equation
00323 *                 S11 * R - L * S22 = SCALE * S12
00324 *                 T11 * R - L * T22 = SCALE * T12
00325 *        for R and L. Solutions in LI and IR.
00326 *
00327          CALL DLACPY( 'Full', N1, N2, T( 1, N1+1 ), LDST, LI, LDST )
00328          CALL DLACPY( 'Full', N1, N2, S( 1, N1+1 ), LDST,
00329      $                IR( N2+1, N1+1 ), LDST )
00330          CALL DTGSY2( 'N', 0, N1, N2, S, LDST, S( N1+1, N1+1 ), LDST,
00331      $                IR( N2+1, N1+1 ), LDST, T, LDST, T( N1+1, N1+1 ),
00332      $                LDST, LI, LDST, SCALE, DSUM, DSCALE, IWORK, IDUM,
00333      $                LINFO )
00334 *
00335 *        Compute orthogonal matrix QL:
00336 *
00337 *                    QL**T * LI = [ TL ]
00338 *                                 [ 0  ]
00339 *        where
00340 *                    LI =  [      -L              ]
00341 *                          [ SCALE * identity(N2) ]
00342 *
00343          DO 10 I = 1, N2
00344             CALL DSCAL( N1, -ONE, LI( 1, I ), 1 )
00345             LI( N1+I, I ) = SCALE
00346    10    CONTINUE
00347          CALL DGEQR2( M, N2, LI, LDST, TAUL, WORK, LINFO )
00348          IF( LINFO.NE.0 )
00349      $      GO TO 70
00350          CALL DORG2R( M, M, N2, LI, LDST, TAUL, WORK, LINFO )
00351          IF( LINFO.NE.0 )
00352      $      GO TO 70
00353 *
00354 *        Compute orthogonal matrix RQ:
00355 *
00356 *                    IR * RQ**T =   [ 0  TR],
00357 *
00358 *         where IR = [ SCALE * identity(N1), R ]
00359 *
00360          DO 20 I = 1, N1
00361             IR( N2+I, I ) = SCALE
00362    20    CONTINUE
00363          CALL DGERQ2( N1, M, IR( N2+1, 1 ), LDST, TAUR, WORK, LINFO )
00364          IF( LINFO.NE.0 )
00365      $      GO TO 70
00366          CALL DORGR2( M, M, N1, IR, LDST, TAUR, WORK, LINFO )
00367          IF( LINFO.NE.0 )
00368      $      GO TO 70
00369 *
00370 *        Perform the swapping tentatively:
00371 *
00372          CALL DGEMM( 'T', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
00373      $               WORK, M )
00374          CALL DGEMM( 'N', 'T', M, M, M, ONE, WORK, M, IR, LDST, ZERO, S,
00375      $               LDST )
00376          CALL DGEMM( 'T', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
00377      $               WORK, M )
00378          CALL DGEMM( 'N', 'T', M, M, M, ONE, WORK, M, IR, LDST, ZERO, T,
00379      $               LDST )
00380          CALL DLACPY( 'F', M, M, S, LDST, SCPY, LDST )
00381          CALL DLACPY( 'F', M, M, T, LDST, TCPY, LDST )
00382          CALL DLACPY( 'F', M, M, IR, LDST, IRCOP, LDST )
00383          CALL DLACPY( 'F', M, M, LI, LDST, LICOP, LDST )
00384 *
00385 *        Triangularize the B-part by an RQ factorization.
00386 *        Apply transformation (from left) to A-part, giving S.
00387 *
00388          CALL DGERQ2( M, M, T, LDST, TAUR, WORK, LINFO )
00389          IF( LINFO.NE.0 )
00390      $      GO TO 70
00391          CALL DORMR2( 'R', 'T', M, M, M, T, LDST, TAUR, S, LDST, WORK,
00392      $                LINFO )
00393          IF( LINFO.NE.0 )
00394      $      GO TO 70
00395          CALL DORMR2( 'L', 'N', M, M, M, T, LDST, TAUR, IR, LDST, WORK,
00396      $                LINFO )
00397          IF( LINFO.NE.0 )
00398      $      GO TO 70
00399 *
00400 *        Compute F-norm(S21) in BRQA21. (T21 is 0.)
00401 *
00402          DSCALE = ZERO
00403          DSUM = ONE
00404          DO 30 I = 1, N2
00405             CALL DLASSQ( N1, S( N2+1, I ), 1, DSCALE, DSUM )
00406    30    CONTINUE
00407          BRQA21 = DSCALE*SQRT( DSUM )
00408 *
00409 *        Triangularize the B-part by a QR factorization.
00410 *        Apply transformation (from right) to A-part, giving S.
00411 *
00412          CALL DGEQR2( M, M, TCPY, LDST, TAUL, WORK, LINFO )
00413          IF( LINFO.NE.0 )
00414      $      GO TO 70
00415          CALL DORM2R( 'L', 'T', M, M, M, TCPY, LDST, TAUL, SCPY, LDST,
00416      $                WORK, INFO )
00417          CALL DORM2R( 'R', 'N', M, M, M, TCPY, LDST, TAUL, LICOP, LDST,
00418      $                WORK, INFO )
00419          IF( LINFO.NE.0 )
00420      $      GO TO 70
00421 *
00422 *        Compute F-norm(S21) in BQRA21. (T21 is 0.)
00423 *
00424          DSCALE = ZERO
00425          DSUM = ONE
00426          DO 40 I = 1, N2
00427             CALL DLASSQ( N1, SCPY( N2+1, I ), 1, DSCALE, DSUM )
00428    40    CONTINUE
00429          BQRA21 = DSCALE*SQRT( DSUM )
00430 *
00431 *        Decide which method to use.
00432 *          Weak stability test:
00433 *             F-norm(S21) <= O(EPS * F-norm((S, T)))
00434 *
00435          IF( BQRA21.LE.BRQA21 .AND. BQRA21.LE.THRESH ) THEN
00436             CALL DLACPY( 'F', M, M, SCPY, LDST, S, LDST )
00437             CALL DLACPY( 'F', M, M, TCPY, LDST, T, LDST )
00438             CALL DLACPY( 'F', M, M, IRCOP, LDST, IR, LDST )
00439             CALL DLACPY( 'F', M, M, LICOP, LDST, LI, LDST )
00440          ELSE IF( BRQA21.GE.THRESH ) THEN
00441             GO TO 70
00442          END IF
00443 *
00444 *        Set lower triangle of B-part to zero
00445 *
00446          CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, T(2,1), LDST )
00447 *
00448          IF( WANDS ) THEN
00449 *
00450 *           Strong stability test:
00451 *              F-norm((A-QL*S*QR**T, B-QL*T*QR**T)) <= O(EPS*F-norm((A,B)))
00452 *
00453             CALL DLACPY( 'Full', M, M, A( J1, J1 ), LDA, WORK( M*M+1 ),
00454      $                   M )
00455             CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, S, LDST, ZERO,
00456      $                  WORK, M )
00457             CALL DGEMM( 'N', 'N', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
00458      $                  WORK( M*M+1 ), M )
00459             DSCALE = ZERO
00460             DSUM = ONE
00461             CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
00462 *
00463             CALL DLACPY( 'Full', M, M, B( J1, J1 ), LDB, WORK( M*M+1 ),
00464      $                   M )
00465             CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, T, LDST, ZERO,
00466      $                  WORK, M )
00467             CALL DGEMM( 'N', 'N', M, M, M, -ONE, WORK, M, IR, LDST, ONE,
00468      $                  WORK( M*M+1 ), M )
00469             CALL DLASSQ( M*M, WORK( M*M+1 ), 1, DSCALE, DSUM )
00470             SS = DSCALE*SQRT( DSUM )
00471             DTRONG = ( SS.LE.THRESH )
00472             IF( .NOT.DTRONG )
00473      $         GO TO 70
00474 *
00475          END IF
00476 *
00477 *        If the swap is accepted ("weakly" and "strongly"), apply the
00478 *        transformations and set N1-by-N2 (2,1)-block to zero.
00479 *
00480          CALL DLASET( 'Full', N1, N2, ZERO, ZERO, S(N2+1,1), LDST )
00481 *
00482 *        copy back M-by-M diagonal block starting at index J1 of (A, B)
00483 *
00484          CALL DLACPY( 'F', M, M, S, LDST, A( J1, J1 ), LDA )
00485          CALL DLACPY( 'F', M, M, T, LDST, B( J1, J1 ), LDB )
00486          CALL DLASET( 'Full', LDST, LDST, ZERO, ZERO, T, LDST )
00487 *
00488 *        Standardize existing 2-by-2 blocks.
00489 *
00490          DO 50 I = 1, M*M
00491             WORK(I) = ZERO
00492    50    CONTINUE
00493          WORK( 1 ) = ONE
00494          T( 1, 1 ) = ONE
00495          IDUM = LWORK - M*M - 2
00496          IF( N2.GT.1 ) THEN
00497             CALL DLAGV2( A( J1, J1 ), LDA, B( J1, J1 ), LDB, AR, AI, BE,
00498      $                   WORK( 1 ), WORK( 2 ), T( 1, 1 ), T( 2, 1 ) )
00499             WORK( M+1 ) = -WORK( 2 )
00500             WORK( M+2 ) = WORK( 1 )
00501             T( N2, N2 ) = T( 1, 1 )
00502             T( 1, 2 ) = -T( 2, 1 )
00503          END IF
00504          WORK( M*M ) = ONE
00505          T( M, M ) = ONE
00506 *
00507          IF( N1.GT.1 ) THEN
00508             CALL DLAGV2( A( J1+N2, J1+N2 ), LDA, B( J1+N2, J1+N2 ), LDB,
00509      $                   TAUR, TAUL, WORK( M*M+1 ), WORK( N2*M+N2+1 ),
00510      $                   WORK( N2*M+N2+2 ), T( N2+1, N2+1 ),
00511      $                   T( M, M-1 ) )
00512             WORK( M*M ) = WORK( N2*M+N2+1 )
00513             WORK( M*M-1 ) = -WORK( N2*M+N2+2 )
00514             T( M, M ) = T( N2+1, N2+1 )
00515             T( M-1, M ) = -T( M, M-1 )
00516          END IF
00517          CALL DGEMM( 'T', 'N', N2, N1, N2, ONE, WORK, M, A( J1, J1+N2 ),
00518      $               LDA, ZERO, WORK( M*M+1 ), N2 )
00519          CALL DLACPY( 'Full', N2, N1, WORK( M*M+1 ), N2, A( J1, J1+N2 ),
00520      $                LDA )
00521          CALL DGEMM( 'T', 'N', N2, N1, N2, ONE, WORK, M, B( J1, J1+N2 ),
00522      $               LDB, ZERO, WORK( M*M+1 ), N2 )
00523          CALL DLACPY( 'Full', N2, N1, WORK( M*M+1 ), N2, B( J1, J1+N2 ),
00524      $                LDB )
00525          CALL DGEMM( 'N', 'N', M, M, M, ONE, LI, LDST, WORK, M, ZERO,
00526      $               WORK( M*M+1 ), M )
00527          CALL DLACPY( 'Full', M, M, WORK( M*M+1 ), M, LI, LDST )
00528          CALL DGEMM( 'N', 'N', N2, N1, N1, ONE, A( J1, J1+N2 ), LDA,
00529      $               T( N2+1, N2+1 ), LDST, ZERO, WORK, N2 )
00530          CALL DLACPY( 'Full', N2, N1, WORK, N2, A( J1, J1+N2 ), LDA )
00531          CALL DGEMM( 'N', 'N', N2, N1, N1, ONE, B( J1, J1+N2 ), LDB,
00532      $               T( N2+1, N2+1 ), LDST, ZERO, WORK, N2 )
00533          CALL DLACPY( 'Full', N2, N1, WORK, N2, B( J1, J1+N2 ), LDB )
00534          CALL DGEMM( 'T', 'N', M, M, M, ONE, IR, LDST, T, LDST, ZERO,
00535      $               WORK, M )
00536          CALL DLACPY( 'Full', M, M, WORK, M, IR, LDST )
00537 *
00538 *        Accumulate transformations into Q and Z if requested.
00539 *
00540          IF( WANTQ ) THEN
00541             CALL DGEMM( 'N', 'N', N, M, M, ONE, Q( 1, J1 ), LDQ, LI,
00542      $                  LDST, ZERO, WORK, N )
00543             CALL DLACPY( 'Full', N, M, WORK, N, Q( 1, J1 ), LDQ )
00544 *
00545          END IF
00546 *
00547          IF( WANTZ ) THEN
00548             CALL DGEMM( 'N', 'N', N, M, M, ONE, Z( 1, J1 ), LDZ, IR,
00549      $                  LDST, ZERO, WORK, N )
00550             CALL DLACPY( 'Full', N, M, WORK, N, Z( 1, J1 ), LDZ )
00551 *
00552          END IF
00553 *
00554 *        Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and
00555 *                (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)).
00556 *
00557          I = J1 + M
00558          IF( I.LE.N ) THEN
00559             CALL DGEMM( 'T', 'N', M, N-I+1, M, ONE, LI, LDST,
00560      $                  A( J1, I ), LDA, ZERO, WORK, M )
00561             CALL DLACPY( 'Full', M, N-I+1, WORK, M, A( J1, I ), LDA )
00562             CALL DGEMM( 'T', 'N', M, N-I+1, M, ONE, LI, LDST,
00563      $                  B( J1, I ), LDA, ZERO, WORK, M )
00564             CALL DLACPY( 'Full', M, N-I+1, WORK, M, B( J1, I ), LDB )
00565          END IF
00566          I = J1 - 1
00567          IF( I.GT.0 ) THEN
00568             CALL DGEMM( 'N', 'N', I, M, M, ONE, A( 1, J1 ), LDA, IR,
00569      $                  LDST, ZERO, WORK, I )
00570             CALL DLACPY( 'Full', I, M, WORK, I, A( 1, J1 ), LDA )
00571             CALL DGEMM( 'N', 'N', I, M, M, ONE, B( 1, J1 ), LDB, IR,
00572      $                  LDST, ZERO, WORK, I )
00573             CALL DLACPY( 'Full', I, M, WORK, I, B( 1, J1 ), LDB )
00574          END IF
00575 *
00576 *        Exit with INFO = 0 if swap was successfully performed.
00577 *
00578          RETURN
00579 *
00580       END IF
00581 *
00582 *     Exit with INFO = 1 if swap was rejected.
00583 *
00584    70 CONTINUE
00585 *
00586       INFO = 1
00587       RETURN
00588 *
00589 *     End of DTGEX2
00590 *
00591       END
 All Files Functions