00001 SUBROUTINE ZHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
00002 $ ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK,
00003 $ RWORK, INFO )
00004
00005
00006
00007
00008
00009
00010
00011 CHARACTER COMPQ, COMPZ, JOB
00012 INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
00013
00014
00015 DOUBLE PRECISION RWORK( * )
00016 COMPLEX*16 ALPHA( * ), BETA( * ), H( LDH, * ),
00017 $ Q( LDQ, * ), T( LDT, * ), WORK( * ),
00018 $ Z( LDZ, * )
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
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 COMPLEX*16 CZERO, CONE
00191 PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
00192 $ CONE = ( 1.0D+0, 0.0D+0 ) )
00193 DOUBLE PRECISION ZERO, ONE
00194 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00195 DOUBLE PRECISION HALF
00196 PARAMETER ( HALF = 0.5D+0 )
00197
00198
00199 LOGICAL ILAZR2, ILAZRO, ILQ, ILSCHR, ILZ, LQUERY
00200 INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
00201 $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
00202 $ JR, MAXIT
00203 DOUBLE PRECISION ABSB, ANORM, ASCALE, ATOL, BNORM, BSCALE, BTOL,
00204 $ C, SAFMIN, TEMP, TEMP2, TEMPR, ULP
00205 COMPLEX*16 ABI22, AD11, AD12, AD21, AD22, CTEMP, CTEMP2,
00206 $ CTEMP3, ESHIFT, RTDISC, S, SHIFT, SIGNBC, T1,
00207 $ U12, X
00208
00209
00210 LOGICAL LSAME
00211 DOUBLE PRECISION DLAMCH, ZLANHS
00212 EXTERNAL LSAME, DLAMCH, ZLANHS
00213
00214
00215 EXTERNAL XERBLA, ZLARTG, ZLASET, ZROT, ZSCAL
00216
00217
00218 INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX, MIN,
00219 $ SQRT
00220
00221
00222 DOUBLE PRECISION ABS1
00223
00224
00225 ABS1( X ) = ABS( DBLE( X ) ) + ABS( DIMAG( X ) )
00226
00227
00228
00229
00230
00231 IF( LSAME( JOB, 'E' ) ) THEN
00232 ILSCHR = .FALSE.
00233 ISCHUR = 1
00234 ELSE IF( LSAME( JOB, 'S' ) ) THEN
00235 ILSCHR = .TRUE.
00236 ISCHUR = 2
00237 ELSE
00238 ISCHUR = 0
00239 END IF
00240
00241 IF( LSAME( COMPQ, 'N' ) ) THEN
00242 ILQ = .FALSE.
00243 ICOMPQ = 1
00244 ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
00245 ILQ = .TRUE.
00246 ICOMPQ = 2
00247 ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
00248 ILQ = .TRUE.
00249 ICOMPQ = 3
00250 ELSE
00251 ICOMPQ = 0
00252 END IF
00253
00254 IF( LSAME( COMPZ, 'N' ) ) THEN
00255 ILZ = .FALSE.
00256 ICOMPZ = 1
00257 ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
00258 ILZ = .TRUE.
00259 ICOMPZ = 2
00260 ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
00261 ILZ = .TRUE.
00262 ICOMPZ = 3
00263 ELSE
00264 ICOMPZ = 0
00265 END IF
00266
00267
00268
00269 INFO = 0
00270 WORK( 1 ) = MAX( 1, N )
00271 LQUERY = ( LWORK.EQ.-1 )
00272 IF( ISCHUR.EQ.0 ) THEN
00273 INFO = -1
00274 ELSE IF( ICOMPQ.EQ.0 ) THEN
00275 INFO = -2
00276 ELSE IF( ICOMPZ.EQ.0 ) THEN
00277 INFO = -3
00278 ELSE IF( N.LT.0 ) THEN
00279 INFO = -4
00280 ELSE IF( ILO.LT.1 ) THEN
00281 INFO = -5
00282 ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
00283 INFO = -6
00284 ELSE IF( LDH.LT.N ) THEN
00285 INFO = -8
00286 ELSE IF( LDT.LT.N ) THEN
00287 INFO = -10
00288 ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
00289 INFO = -14
00290 ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
00291 INFO = -16
00292 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
00293 INFO = -18
00294 END IF
00295 IF( INFO.NE.0 ) THEN
00296 CALL XERBLA( 'ZHGEQZ', -INFO )
00297 RETURN
00298 ELSE IF( LQUERY ) THEN
00299 RETURN
00300 END IF
00301
00302
00303
00304
00305 IF( N.LE.0 ) THEN
00306 WORK( 1 ) = DCMPLX( 1 )
00307 RETURN
00308 END IF
00309
00310
00311
00312 IF( ICOMPQ.EQ.3 )
00313 $ CALL ZLASET( 'Full', N, N, CZERO, CONE, Q, LDQ )
00314 IF( ICOMPZ.EQ.3 )
00315 $ CALL ZLASET( 'Full', N, N, CZERO, CONE, Z, LDZ )
00316
00317
00318
00319 IN = IHI + 1 - ILO
00320 SAFMIN = DLAMCH( 'S' )
00321 ULP = DLAMCH( 'E' )*DLAMCH( 'B' )
00322 ANORM = ZLANHS( 'F', IN, H( ILO, ILO ), LDH, RWORK )
00323 BNORM = ZLANHS( 'F', IN, T( ILO, ILO ), LDT, RWORK )
00324 ATOL = MAX( SAFMIN, ULP*ANORM )
00325 BTOL = MAX( SAFMIN, ULP*BNORM )
00326 ASCALE = ONE / MAX( SAFMIN, ANORM )
00327 BSCALE = ONE / MAX( SAFMIN, BNORM )
00328
00329
00330
00331
00332 DO 10 J = IHI + 1, N
00333 ABSB = ABS( T( J, J ) )
00334 IF( ABSB.GT.SAFMIN ) THEN
00335 SIGNBC = DCONJG( T( J, J ) / ABSB )
00336 T( J, J ) = ABSB
00337 IF( ILSCHR ) THEN
00338 CALL ZSCAL( J-1, SIGNBC, T( 1, J ), 1 )
00339 CALL ZSCAL( J, SIGNBC, H( 1, J ), 1 )
00340 ELSE
00341 H( J, J ) = H( J, J )*SIGNBC
00342 END IF
00343 IF( ILZ )
00344 $ CALL ZSCAL( N, SIGNBC, Z( 1, J ), 1 )
00345 ELSE
00346 T( J, J ) = CZERO
00347 END IF
00348 ALPHA( J ) = H( J, J )
00349 BETA( J ) = T( J, J )
00350 10 CONTINUE
00351
00352
00353
00354 IF( IHI.LT.ILO )
00355 $ GO TO 190
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 ILAST = IHI
00373 IF( ILSCHR ) THEN
00374 IFRSTM = 1
00375 ILASTM = N
00376 ELSE
00377 IFRSTM = ILO
00378 ILASTM = IHI
00379 END IF
00380 IITER = 0
00381 ESHIFT = CZERO
00382 MAXIT = 30*( IHI-ILO+1 )
00383
00384 DO 170 JITER = 1, MAXIT
00385
00386
00387
00388 IF( JITER.GT.MAXIT )
00389 $ GO TO 180
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 IF( ILAST.EQ.ILO ) THEN
00400 GO TO 60
00401 ELSE
00402 IF( ABS1( H( ILAST, ILAST-1 ) ).LE.ATOL ) THEN
00403 H( ILAST, ILAST-1 ) = CZERO
00404 GO TO 60
00405 END IF
00406 END IF
00407
00408 IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
00409 T( ILAST, ILAST ) = CZERO
00410 GO TO 50
00411 END IF
00412
00413
00414
00415 DO 40 J = ILAST - 1, ILO, -1
00416
00417
00418
00419 IF( J.EQ.ILO ) THEN
00420 ILAZRO = .TRUE.
00421 ELSE
00422 IF( ABS1( H( J, J-1 ) ).LE.ATOL ) THEN
00423 H( J, J-1 ) = CZERO
00424 ILAZRO = .TRUE.
00425 ELSE
00426 ILAZRO = .FALSE.
00427 END IF
00428 END IF
00429
00430
00431
00432 IF( ABS( T( J, J ) ).LT.BTOL ) THEN
00433 T( J, J ) = CZERO
00434
00435
00436
00437 ILAZR2 = .FALSE.
00438 IF( .NOT.ILAZRO ) THEN
00439 IF( ABS1( H( J, J-1 ) )*( ASCALE*ABS1( H( J+1,
00440 $ J ) ) ).LE.ABS1( H( J, J ) )*( ASCALE*ATOL ) )
00441 $ ILAZR2 = .TRUE.
00442 END IF
00443
00444
00445
00446
00447
00448
00449
00450 IF( ILAZRO .OR. ILAZR2 ) THEN
00451 DO 20 JCH = J, ILAST - 1
00452 CTEMP = H( JCH, JCH )
00453 CALL ZLARTG( CTEMP, H( JCH+1, JCH ), C, S,
00454 $ H( JCH, JCH ) )
00455 H( JCH+1, JCH ) = CZERO
00456 CALL ZROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
00457 $ H( JCH+1, JCH+1 ), LDH, C, S )
00458 CALL ZROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
00459 $ T( JCH+1, JCH+1 ), LDT, C, S )
00460 IF( ILQ )
00461 $ CALL ZROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
00462 $ C, DCONJG( S ) )
00463 IF( ILAZR2 )
00464 $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
00465 ILAZR2 = .FALSE.
00466 IF( ABS1( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
00467 IF( JCH+1.GE.ILAST ) THEN
00468 GO TO 60
00469 ELSE
00470 IFIRST = JCH + 1
00471 GO TO 70
00472 END IF
00473 END IF
00474 T( JCH+1, JCH+1 ) = CZERO
00475 20 CONTINUE
00476 GO TO 50
00477 ELSE
00478
00479
00480
00481
00482 DO 30 JCH = J, ILAST - 1
00483 CTEMP = T( JCH, JCH+1 )
00484 CALL ZLARTG( CTEMP, T( JCH+1, JCH+1 ), C, S,
00485 $ T( JCH, JCH+1 ) )
00486 T( JCH+1, JCH+1 ) = CZERO
00487 IF( JCH.LT.ILASTM-1 )
00488 $ CALL ZROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
00489 $ T( JCH+1, JCH+2 ), LDT, C, S )
00490 CALL ZROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
00491 $ H( JCH+1, JCH-1 ), LDH, C, S )
00492 IF( ILQ )
00493 $ CALL ZROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
00494 $ C, DCONJG( S ) )
00495 CTEMP = H( JCH+1, JCH )
00496 CALL ZLARTG( CTEMP, H( JCH+1, JCH-1 ), C, S,
00497 $ H( JCH+1, JCH ) )
00498 H( JCH+1, JCH-1 ) = CZERO
00499 CALL ZROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
00500 $ H( IFRSTM, JCH-1 ), 1, C, S )
00501 CALL ZROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
00502 $ T( IFRSTM, JCH-1 ), 1, C, S )
00503 IF( ILZ )
00504 $ CALL ZROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
00505 $ C, S )
00506 30 CONTINUE
00507 GO TO 50
00508 END IF
00509 ELSE IF( ILAZRO ) THEN
00510
00511
00512
00513 IFIRST = J
00514 GO TO 70
00515 END IF
00516
00517
00518
00519 40 CONTINUE
00520
00521
00522
00523 INFO = 2*N + 1
00524 GO TO 210
00525
00526
00527
00528
00529 50 CONTINUE
00530 CTEMP = H( ILAST, ILAST )
00531 CALL ZLARTG( CTEMP, H( ILAST, ILAST-1 ), C, S,
00532 $ H( ILAST, ILAST ) )
00533 H( ILAST, ILAST-1 ) = CZERO
00534 CALL ZROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
00535 $ H( IFRSTM, ILAST-1 ), 1, C, S )
00536 CALL ZROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
00537 $ T( IFRSTM, ILAST-1 ), 1, C, S )
00538 IF( ILZ )
00539 $ CALL ZROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
00540
00541
00542
00543 60 CONTINUE
00544 ABSB = ABS( T( ILAST, ILAST ) )
00545 IF( ABSB.GT.SAFMIN ) THEN
00546 SIGNBC = DCONJG( T( ILAST, ILAST ) / ABSB )
00547 T( ILAST, ILAST ) = ABSB
00548 IF( ILSCHR ) THEN
00549 CALL ZSCAL( ILAST-IFRSTM, SIGNBC, T( IFRSTM, ILAST ), 1 )
00550 CALL ZSCAL( ILAST+1-IFRSTM, SIGNBC, H( IFRSTM, ILAST ),
00551 $ 1 )
00552 ELSE
00553 H( ILAST, ILAST ) = H( ILAST, ILAST )*SIGNBC
00554 END IF
00555 IF( ILZ )
00556 $ CALL ZSCAL( N, SIGNBC, Z( 1, ILAST ), 1 )
00557 ELSE
00558 T( ILAST, ILAST ) = CZERO
00559 END IF
00560 ALPHA( ILAST ) = H( ILAST, ILAST )
00561 BETA( ILAST ) = T( ILAST, ILAST )
00562
00563
00564
00565 ILAST = ILAST - 1
00566 IF( ILAST.LT.ILO )
00567 $ GO TO 190
00568
00569
00570
00571 IITER = 0
00572 ESHIFT = CZERO
00573 IF( .NOT.ILSCHR ) THEN
00574 ILASTM = ILAST
00575 IF( IFRSTM.GT.ILAST )
00576 $ IFRSTM = ILO
00577 END IF
00578 GO TO 160
00579
00580
00581
00582
00583
00584
00585 70 CONTINUE
00586 IITER = IITER + 1
00587 IF( .NOT.ILSCHR ) THEN
00588 IFRSTM = IFIRST
00589 END IF
00590
00591
00592
00593
00594
00595
00596
00597 IF( ( IITER / 10 )*10.NE.IITER ) THEN
00598
00599
00600
00601
00602
00603
00604
00605
00606 U12 = ( BSCALE*T( ILAST-1, ILAST ) ) /
00607 $ ( BSCALE*T( ILAST, ILAST ) )
00608 AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
00609 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
00610 AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
00611 $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
00612 AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
00613 $ ( BSCALE*T( ILAST, ILAST ) )
00614 AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
00615 $ ( BSCALE*T( ILAST, ILAST ) )
00616 ABI22 = AD22 - U12*AD21
00617
00618 T1 = HALF*( AD11+ABI22 )
00619 RTDISC = SQRT( T1**2+AD12*AD21-AD11*AD22 )
00620 TEMP = DBLE( T1-ABI22 )*DBLE( RTDISC ) +
00621 $ DIMAG( T1-ABI22 )*DIMAG( RTDISC )
00622 IF( TEMP.LE.ZERO ) THEN
00623 SHIFT = T1 + RTDISC
00624 ELSE
00625 SHIFT = T1 - RTDISC
00626 END IF
00627 ELSE
00628
00629
00630
00631 ESHIFT = ESHIFT + DCONJG( ( ASCALE*H( ILAST-1, ILAST ) ) /
00632 $ ( BSCALE*T( ILAST-1, ILAST-1 ) ) )
00633 SHIFT = ESHIFT
00634 END IF
00635
00636
00637
00638 DO 80 J = ILAST - 1, IFIRST + 1, -1
00639 ISTART = J
00640 CTEMP = ASCALE*H( J, J ) - SHIFT*( BSCALE*T( J, J ) )
00641 TEMP = ABS1( CTEMP )
00642 TEMP2 = ASCALE*ABS1( H( J+1, J ) )
00643 TEMPR = MAX( TEMP, TEMP2 )
00644 IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
00645 TEMP = TEMP / TEMPR
00646 TEMP2 = TEMP2 / TEMPR
00647 END IF
00648 IF( ABS1( H( J, J-1 ) )*TEMP2.LE.TEMP*ATOL )
00649 $ GO TO 90
00650 80 CONTINUE
00651
00652 ISTART = IFIRST
00653 CTEMP = ASCALE*H( IFIRST, IFIRST ) -
00654 $ SHIFT*( BSCALE*T( IFIRST, IFIRST ) )
00655 90 CONTINUE
00656
00657
00658
00659
00660
00661 CTEMP2 = ASCALE*H( ISTART+1, ISTART )
00662 CALL ZLARTG( CTEMP, CTEMP2, C, S, CTEMP3 )
00663
00664
00665
00666 DO 150 J = ISTART, ILAST - 1
00667 IF( J.GT.ISTART ) THEN
00668 CTEMP = H( J, J-1 )
00669 CALL ZLARTG( CTEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
00670 H( J+1, J-1 ) = CZERO
00671 END IF
00672
00673 DO 100 JC = J, ILASTM
00674 CTEMP = C*H( J, JC ) + S*H( J+1, JC )
00675 H( J+1, JC ) = -DCONJG( S )*H( J, JC ) + C*H( J+1, JC )
00676 H( J, JC ) = CTEMP
00677 CTEMP2 = C*T( J, JC ) + S*T( J+1, JC )
00678 T( J+1, JC ) = -DCONJG( S )*T( J, JC ) + C*T( J+1, JC )
00679 T( J, JC ) = CTEMP2
00680 100 CONTINUE
00681 IF( ILQ ) THEN
00682 DO 110 JR = 1, N
00683 CTEMP = C*Q( JR, J ) + DCONJG( S )*Q( JR, J+1 )
00684 Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
00685 Q( JR, J ) = CTEMP
00686 110 CONTINUE
00687 END IF
00688
00689 CTEMP = T( J+1, J+1 )
00690 CALL ZLARTG( CTEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
00691 T( J+1, J ) = CZERO
00692
00693 DO 120 JR = IFRSTM, MIN( J+2, ILAST )
00694 CTEMP = C*H( JR, J+1 ) + S*H( JR, J )
00695 H( JR, J ) = -DCONJG( S )*H( JR, J+1 ) + C*H( JR, J )
00696 H( JR, J+1 ) = CTEMP
00697 120 CONTINUE
00698 DO 130 JR = IFRSTM, J
00699 CTEMP = C*T( JR, J+1 ) + S*T( JR, J )
00700 T( JR, J ) = -DCONJG( S )*T( JR, J+1 ) + C*T( JR, J )
00701 T( JR, J+1 ) = CTEMP
00702 130 CONTINUE
00703 IF( ILZ ) THEN
00704 DO 140 JR = 1, N
00705 CTEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
00706 Z( JR, J ) = -DCONJG( S )*Z( JR, J+1 ) + C*Z( JR, J )
00707 Z( JR, J+1 ) = CTEMP
00708 140 CONTINUE
00709 END IF
00710 150 CONTINUE
00711
00712 160 CONTINUE
00713
00714 170 CONTINUE
00715
00716
00717
00718 180 CONTINUE
00719 INFO = ILAST
00720 GO TO 210
00721
00722
00723
00724 190 CONTINUE
00725
00726
00727
00728 DO 200 J = 1, ILO - 1
00729 ABSB = ABS( T( J, J ) )
00730 IF( ABSB.GT.SAFMIN ) THEN
00731 SIGNBC = DCONJG( T( J, J ) / ABSB )
00732 T( J, J ) = ABSB
00733 IF( ILSCHR ) THEN
00734 CALL ZSCAL( J-1, SIGNBC, T( 1, J ), 1 )
00735 CALL ZSCAL( J, SIGNBC, H( 1, J ), 1 )
00736 ELSE
00737 H( J, J ) = H( J, J )*SIGNBC
00738 END IF
00739 IF( ILZ )
00740 $ CALL ZSCAL( N, SIGNBC, Z( 1, J ), 1 )
00741 ELSE
00742 T( J, J ) = CZERO
00743 END IF
00744 ALPHA( J ) = H( J, J )
00745 BETA( J ) = T( J, J )
00746 200 CONTINUE
00747
00748
00749
00750 INFO = 0
00751
00752
00753
00754 210 CONTINUE
00755 WORK( 1 ) = DCMPLX( N )
00756 RETURN
00757
00758
00759
00760 END