236 SUBROUTINE claqr0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
237 $ IHIZ, Z, LDZ, WORK, LWORK, INFO )
244 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
248 COMPLEX H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
258 parameter( ntiny = 15 )
264 parameter( kexnw = 5 )
270 parameter( kexsh = 6 )
275 parameter( wilk1 = 0.75e0 )
277 parameter( zero = ( 0.0e0, 0.0e0 ),
278 $ one = ( 1.0e0, 0.0e0 ) )
280 parameter( two = 2.0e0 )
283 COMPLEX AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2
285 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
286 $ kt, ktop, ku, kv, kwh, kwtop, kwv, ld, ls,
287 $ lwkopt, ndec, ndfl, nh, nho, nibble, nmin, ns,
288 $ nsmax, nsr, nve, nw, nwmax, nwr, nwupbd
304 INTRINSIC abs, aimag, cmplx, int, max, min, mod, real,
311 cabs1( cdum ) = abs( real( cdum ) ) + abs( aimag( cdum ) )
323 IF( n.LE.ntiny )
THEN
329 $
CALL clahqr( wantt, wantz, n, ilo, ihi, h, ldh, w, iloz,
330 $ ihiz, z, ldz, info )
359 nwr = ilaenv( 13,
'CLAQR0', jbcmpz, n, ilo, ihi, lwork )
361 nwr = min( ihi-ilo+1, ( n-1 ) / 3, nwr )
368 nsr = ilaenv( 15,
'CLAQR0', jbcmpz, n, ilo, ihi, lwork )
369 nsr = min( nsr, ( n-3 ) / 6, ihi-ilo )
370 nsr = max( 2, nsr-mod( nsr, 2 ) )
376 CALL claqr3( wantt, wantz, n, ilo, ihi, nwr+1, h, ldh, iloz,
377 $ ihiz, z, ldz, ls, ld, w, h, ldh, n, h, ldh, n, h,
382 lwkopt = max( 3*nsr / 2, int( work( 1 ) ) )
386 IF( lwork.EQ.-1 )
THEN
387 work( 1 ) = cmplx( lwkopt, 0 )
393 nmin = ilaenv( 12,
'CLAQR0', jbcmpz, n, ilo, ihi, lwork )
394 nmin = max( ntiny, nmin )
398 nibble = ilaenv( 14,
'CLAQR0', jbcmpz, n, ilo, ihi, lwork )
399 nibble = max( 0, nibble )
404 kacc22 = ilaenv( 16,
'CLAQR0', jbcmpz, n, ilo, ihi, lwork )
405 kacc22 = max( 0, kacc22 )
406 kacc22 = min( 2, kacc22 )
411 nwmax = min( ( n-1 ) / 3, lwork / 2 )
417 nsmax = min( ( n-3 ) / 6, 2*lwork / 3 )
418 nsmax = nsmax - mod( nsmax, 2 )
426 itmax = max( 30, 2*kexsh )*max( 10, ( ihi-ilo+1 ) )
443 DO 10 k = kbot, ilo + 1, -1
444 IF( h( k, k-1 ).EQ.zero )
468 nwupbd = min( nh, nwmax )
469 IF( ndfl.LT.kexnw )
THEN
470 nw = min( nwupbd, nwr )
472 nw = min( nwupbd, 2*nw )
474 IF( nw.LT.nwmax )
THEN
475 IF( nw.GE.nh-1 )
THEN
478 kwtop = kbot - nw + 1
479 IF( cabs1( h( kwtop, kwtop-1 ) ).GT.
480 $ cabs1( h( kwtop-1, kwtop-2 ) ) )nw = nw + 1
483 IF( ndfl.LT.kexnw )
THEN
485 ELSE IF( ndec.GE.0 .OR. nw.GE.nwupbd )
THEN
505 nho = ( n-nw-1 ) - kt + 1
507 nve = ( n-nw ) - kwv + 1
511 CALL claqr3( wantt, wantz, n, ktop, kbot, nw, h, ldh,
513 $ ihiz, z, ldz, ls, ld, w, h( kv, 1 ), ldh, nho,
514 $ h( kv, kt ), ldh, nve, h( kwv, 1 ), ldh, work,
531 IF( ( ld.EQ.0 ) .OR. ( ( 100*ld.LE.nw*nibble ) .AND. ( kbot-
532 $ ktop+1.GT.min( nmin, nwmax ) ) ) )
THEN
538 ns = min( nsmax, nsr, max( 2, kbot-ktop ) )
539 ns = ns - mod( ns, 2 )
548 IF( mod( ndfl, kexsh ).EQ.0 )
THEN
550 DO 30 i = kbot, ks + 1, -2
551 w( i ) = h( i, i ) + wilk1*cabs1( h( i, i-1 ) )
562 IF( kbot-ks+1.LE.ns / 2 )
THEN
565 CALL clacpy(
'A', ns, ns, h( ks, ks ), ldh,
567 IF( ns.GT.nmin )
THEN
568 CALL claqr4( .false., .false., ns, 1, ns,
569 $ h( kt, 1 ), ldh, w( ks ), 1, 1,
570 $ zdum, 1, work, lwork, inf )
572 CALL clahqr( .false., .false., ns, 1, ns,
573 $ h( kt, 1 ), ldh, w( ks ), 1, 1,
585 IF( ks.GE.kbot )
THEN
586 s = cabs1( h( kbot-1, kbot-1 ) ) +
587 $ cabs1( h( kbot, kbot-1 ) ) +
588 $ cabs1( h( kbot-1, kbot ) ) +
589 $ cabs1( h( kbot, kbot ) )
590 aa = h( kbot-1, kbot-1 ) / s
591 cc = h( kbot, kbot-1 ) / s
592 bb = h( kbot-1, kbot ) / s
593 dd = h( kbot, kbot ) / s
594 tr2 = ( aa+dd ) / two
595 det = ( aa-tr2 )*( dd-tr2 ) - bb*cc
596 rtdisc = sqrt( -det )
597 w( kbot-1 ) = ( tr2+rtdisc )*s
598 w( kbot ) = ( tr2-rtdisc )*s
604 IF( kbot-ks+1.GT.ns )
THEN
609 DO 50 k = kbot, ks + 1, -1
614 IF( cabs1( w( i ) ).LT.cabs1( w( i+1 ) ) )
630 IF( kbot-ks+1.EQ.2 )
THEN
631 IF( cabs1( w( kbot )-h( kbot, kbot ) ).LT.
632 $ cabs1( w( kbot-1 )-h( kbot, kbot ) ) )
THEN
633 w( kbot-1 ) = w( kbot )
635 w( kbot ) = w( kbot-1 )
644 ns = min( ns, kbot-ks+1 )
645 ns = ns - mod( ns, 2 )
662 nho = ( n-kdu+1-4 ) - ( kdu+1 ) + 1
664 nve = n - kdu - kwv + 1
668 CALL claqr5( wantt, wantz, kacc22, n, ktop, kbot, ns,
669 $ w( ks ), h, ldh, iloz, ihiz, z, ldz, work,
670 $ 3, h( ku, 1 ), ldh, nve, h( kwv, 1 ), ldh,
671 $ nho, h( ku, kwh ), ldh )
694 work( 1 ) = cmplx( lwkopt, 0 )