00001 SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
00002 $ LDZ, J1, N1, N2, WORK, LWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 LOGICAL WANTQ, WANTZ
00011 INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
00012
00013
00014 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
00015 $ WORK( * ), Z( LDZ, * )
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
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
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
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
00159 DOUBLE PRECISION DLAMCH
00160 EXTERNAL DLAMCH
00161
00162
00163 EXTERNAL DGEMM, DGEQR2, DGERQ2, DLACPY, DLAGV2, DLARTG,
00164 $ DLASET, DLASSQ, DORG2R, DORGR2, DORM2R, DORMR2,
00165 $ DROT, DSCAL, DTGSY2
00166
00167
00168 INTRINSIC ABS, MAX, SQRT
00169
00170
00171
00172 INFO = 0
00173
00174
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
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
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
00210
00211
00212
00213
00214
00215
00216
00217 THRESH = MAX( TWENTY*EPS*DNORM, SMLNUM )
00218
00219 IF( M.EQ.2 ) THEN
00220
00221
00222
00223
00224
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
00252
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
00262
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
00288
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
00300
00301 A( J1+1, J1 ) = ZERO
00302 B( J1+1, J1 ) = ZERO
00303
00304
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
00314
00315 RETURN
00316
00317 ELSE
00318
00319
00320
00321
00322
00323
00324
00325
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
00336
00337
00338
00339
00340
00341
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
00355
00356
00357
00358
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
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
00386
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
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
00410
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
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
00432
00433
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
00445
00446 CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, T(2,1), LDST )
00447
00448 IF( WANDS ) THEN
00449
00450
00451
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
00478
00479
00480 CALL DLASET( 'Full', N1, N2, ZERO, ZERO, S(N2+1,1), LDST )
00481
00482
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
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
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
00555
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
00577
00578 RETURN
00579
00580 END IF
00581
00582
00583
00584 70 CONTINUE
00585
00586 INFO = 1
00587 RETURN
00588
00589
00590
00591 END