203 SUBROUTINE dlahqr( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
204 $ ILOZ, IHIZ, Z, LDZ, INFO )
212 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
216 DOUBLE PRECISION H( LDH, * ), WI( * ), WR( * ), Z( LDZ, * )
222 DOUBLE PRECISION ZERO, ONE, TWO
223 parameter( zero = 0.0d0, one = 1.0d0, two = 2.0d0 )
224 DOUBLE PRECISION DAT1, DAT2
225 parameter( dat1 = 3.0d0 / 4.0d0, dat2 = -0.4375d0 )
227 parameter( kexsh = 10 )
230 DOUBLE PRECISION AA, AB, BA, BB, CS, DET, H11, H12, H21, H21S,
231 $ h22, rt1i, rt1r, rt2i, rt2r, rtdisc, s, safmax,
232 $ safmin, smlnum, sn, sum, t1, t2, t3, tr, tst,
234 INTEGER I, I1, I2, ITS, ITMAX, J, K, L, M, NH, NR, NZ,
238 DOUBLE PRECISION V( 3 )
241 DOUBLE PRECISION DLAMCH
248 INTRINSIC abs, dble, max, min, sqrt
258 IF( ilo.EQ.ihi )
THEN
259 wr( ilo ) = h( ilo, ilo )
265 DO 10 j = ilo, ihi - 3
270 $ h( ihi, ihi-2 ) = zero
277 safmin = dlamch(
'SAFE MINIMUM' )
278 safmax = one / safmin
279 ulp = dlamch(
'PRECISION' )
280 smlnum = safmin*( dble( nh ) / ulp )
293 itmax = 30 * max( 10, nh )
315 DO 140 its = 0, itmax
319 DO 30 k = i, l + 1, -1
320 IF( abs( h( k, k-1 ) ).LE.smlnum )
322 tst = abs( h( k-1, k-1 ) ) + abs( h( k, k ) )
323 IF( tst.EQ.zero )
THEN
325 $ tst = tst + abs( h( k-1, k-2 ) )
327 $ tst = tst + abs( h( k+1, k ) )
333 IF( abs( h( k, k-1 ) ).LE.ulp*tst )
THEN
334 ab = max( abs( h( k, k-1 ) ), abs( h( k-1, k ) ) )
335 ba = min( abs( h( k, k-1 ) ), abs( h( k-1, k ) ) )
336 aa = max( abs( h( k, k ) ),
337 $ abs( h( k-1, k-1 )-h( k, k ) ) )
338 bb = min( abs( h( k, k ) ),
339 $ abs( h( k-1, k-1 )-h( k, k ) ) )
341 IF( ba*( ab / s ).LE.max( smlnum,
342 $ ulp*( bb*( aa / s ) ) ) )
GO TO 40
364 IF( .NOT.wantt )
THEN
369 IF( mod(kdefl,2*kexsh).EQ.0 )
THEN
373 s = abs( h( i, i-1 ) ) + abs( h( i-1, i-2 ) )
374 h11 = dat1*s + h( i, i )
378 ELSE IF( mod(kdefl,kexsh).EQ.0 )
THEN
382 s = abs( h( l+1, l ) ) + abs( h( l+2, l+1 ) )
383 h11 = dat1*s + h( l, l )
397 s = abs( h11 ) + abs( h12 ) + abs( h21 ) + abs( h22 )
408 tr = ( h11+h22 ) / two
409 det = ( h11-tr )*( h22-tr ) - h12*h21
410 rtdisc = sqrt( abs( det ) )
411 IF( det.GE.zero )
THEN
425 IF( abs( rt1r-h22 ).LE.abs( rt2r-h22 ) )
THEN
439 DO 50 m = i - 2, l, -1
446 s = abs( h( m, m )-rt2r ) + abs( rt2i ) + abs( h21s )
447 h21s = h( m+1, m ) / s
448 v( 1 ) = h21s*h( m, m+1 ) + ( h( m, m )-rt1r )*
449 $ ( ( h( m, m )-rt2r ) / s ) - rt1i*( rt2i / s )
450 v( 2 ) = h21s*( h( m, m )+h( m+1, m+1 )-rt1r-rt2r )
451 v( 3 ) = h21s*h( m+2, m+1 )
452 s = abs( v( 1 ) ) + abs( v( 2 ) ) + abs( v( 3 ) )
458 IF( abs( h( m, m-1 ) )*( abs( v( 2 ) )+abs( v( 3 ) ) ).LE.
459 $ ulp*abs( v( 1 ) )*( abs( h( m-1, m-1 ) )+abs( h( m,
460 $ m ) )+abs( h( m+1, m+1 ) ) ) )
GO TO 60
479 $
CALL dcopy( nr, h( k, k-1 ), 1, v, 1 )
480 CALL dlarfg( nr, v( 1 ), v( 2 ), 1, t1 )
485 $ h( k+2, k-1 ) = zero
486 ELSE IF( m.GT.l )
THEN
491 h( k, k-1 ) = h( k, k-1 )*( one-t1 )
503 sum = h( k, j ) + v2*h( k+1, j ) + v3*h( k+2, j )
504 h( k, j ) = h( k, j ) - sum*t1
505 h( k+1, j ) = h( k+1, j ) - sum*t2
506 h( k+2, j ) = h( k+2, j ) - sum*t3
512 DO 80 j = i1, min( k+3, i )
513 sum = h( j, k ) + v2*h( j, k+1 ) + v3*h( j, k+2 )
514 h( j, k ) = h( j, k ) - sum*t1
515 h( j, k+1 ) = h( j, k+1 ) - sum*t2
516 h( j, k+2 ) = h( j, k+2 ) - sum*t3
524 sum = z( j, k ) + v2*z( j, k+1 ) + v3*z( j, k+2 )
525 z( j, k ) = z( j, k ) - sum*t1
526 z( j, k+1 ) = z( j, k+1 ) - sum*t2
527 z( j, k+2 ) = z( j, k+2 ) - sum*t3
530 ELSE IF( nr.EQ.2 )
THEN
536 sum = h( k, j ) + v2*h( k+1, j )
537 h( k, j ) = h( k, j ) - sum*t1
538 h( k+1, j ) = h( k+1, j ) - sum*t2
545 sum = h( j, k ) + v2*h( j, k+1 )
546 h( j, k ) = h( j, k ) - sum*t1
547 h( j, k+1 ) = h( j, k+1 ) - sum*t2
554 DO 120 j = iloz, ihiz
555 sum = z( j, k ) + v2*z( j, k+1 )
556 z( j, k ) = z( j, k ) - sum*t1
557 z( j, k+1 ) = z( j, k+1 ) - sum*t2
578 ELSE IF( l.EQ.i-1 )
THEN
585 CALL dlanv2( h( i-1, i-1 ), h( i-1, i ), h( i, i-1 ),
586 $ h( i, i ), wr( i-1 ), wi( i-1 ), wr( i ), wi( i ),
594 $
CALL drot( i2-i, h( i-1, i+1 ), ldh, h( i, i+1 ), ldh,
596 CALL drot( i-i1-1, h( i1, i-1 ), 1, h( i1, i ), 1, cs,
603 CALL drot( nz, z( iloz, i-1 ), 1, z( iloz, i ), 1, cs,