279 SUBROUTINE zhgeqz( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T,
281 $ ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK,
289 CHARACTER COMPQ, COMPZ, JOB
290 INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
293 DOUBLE PRECISION RWORK( * )
294 COMPLEX*16 ALPHA( * ), BETA( * ), H( LDH, * ),
295 $ Q( LDQ, * ), T( LDT, * ), WORK( * ),
302 COMPLEX*16 CZERO, CONE
303 PARAMETER ( CZERO = ( 0.0d+0, 0.0d+0 ),
304 $ cone = ( 1.0d+0, 0.0d+0 ) )
305 DOUBLE PRECISION ZERO, ONE
306 parameter( zero = 0.0d+0, one = 1.0d+0 )
307 DOUBLE PRECISION HALF
308 parameter( half = 0.5d+0 )
311 LOGICAL ILAZR2, ILAZRO, ILQ, ILSCHR, ILZ, LQUERY
312 INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
313 $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
315 DOUBLE PRECISION ABSB, ANORM, ASCALE, ATOL, BNORM, BSCALE, BTOL,
316 $ C, SAFMIN, TEMP, TEMP2, TEMPR, ULP
317 COMPLEX*16 ABI22, AD11, AD12, AD21, AD22, CTEMP, CTEMP2,
318 $ ctemp3, eshift, s, shift, signbc,
324 DOUBLE PRECISION DLAMCH, ZLANHS
325 EXTERNAL zladiv, lsame, dlamch, zlanhs
331 INTRINSIC abs, dble, dcmplx, dconjg, dimag, max, min,
335 DOUBLE PRECISION ABS1
338 abs1( x ) = abs( dble( x ) ) + abs( dimag( x ) )
344 IF( lsame( job,
'E' ) )
THEN
347 ELSE IF( lsame( job,
'S' ) )
THEN
355 IF( lsame( compq,
'N' ) )
THEN
358 ELSE IF( lsame( compq,
'V' ) )
THEN
361 ELSE IF( lsame( compq,
'I' ) )
THEN
369 IF( lsame( compz,
'N' ) )
THEN
372 ELSE IF( lsame( compz,
'V' ) )
THEN
375 ELSE IF( lsame( compz,
'I' ) )
THEN
386 work( 1 ) = max( 1, n )
387 lquery = ( lwork.EQ.-1 )
388 IF( ischur.EQ.0 )
THEN
390 ELSE IF( icompq.EQ.0 )
THEN
392 ELSE IF( icompz.EQ.0 )
THEN
394 ELSE IF( n.LT.0 )
THEN
396 ELSE IF( ilo.LT.1 )
THEN
398 ELSE IF( ihi.GT.n .OR. ihi.LT.ilo-1 )
THEN
400 ELSE IF( ldh.LT.n )
THEN
402 ELSE IF( ldt.LT.n )
THEN
404 ELSE IF( ldq.LT.1 .OR. ( ilq .AND. ldq.LT.n ) )
THEN
406 ELSE IF( ldz.LT.1 .OR. ( ilz .AND. ldz.LT.n ) )
THEN
408 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery )
THEN
412 CALL xerbla(
'ZHGEQZ', -info )
414 ELSE IF( lquery )
THEN
422 work( 1 ) = dcmplx( 1 )
429 $
CALL zlaset(
'Full', n, n, czero, cone, q, ldq )
431 $
CALL zlaset(
'Full', n, n, czero, cone, z, ldz )
436 safmin = dlamch(
'S' )
437 ulp = dlamch(
'E' )*dlamch(
'B' )
438 anorm = zlanhs(
'F', in, h( ilo, ilo ), ldh, rwork )
439 bnorm = zlanhs(
'F', in, t( ilo, ilo ), ldt, rwork )
440 atol = max( safmin, ulp*anorm )
441 btol = max( safmin, ulp*bnorm )
442 ascale = one / max( safmin, anorm )
443 bscale = one / max( safmin, bnorm )
449 absb = abs( t( j, j ) )
450 IF( absb.GT.safmin )
THEN
451 signbc = dconjg( t( j, j ) / absb )
454 CALL zscal( j-1, signbc, t( 1, j ), 1 )
455 CALL zscal( j, signbc, h( 1, j ), 1 )
457 CALL zscal( 1, signbc, h( j, j ), 1 )
460 $
CALL zscal( n, signbc, z( 1, j ), 1 )
464 alpha( j ) = h( j, j )
465 beta( j ) = t( j, j )
498 maxit = 30*( ihi-ilo+1 )
500 DO 170 jiter = 1, maxit
515 IF( ilast.EQ.ilo )
THEN
518 IF( abs1( h( ilast, ilast-1 ) ).LE.max( safmin, ulp*(
519 $ abs1( h( ilast, ilast ) ) + abs1( h( ilast-1, ilast-1 )
521 h( ilast, ilast-1 ) = czero
526 IF( abs( t( ilast, ilast ) ).LE.btol )
THEN
527 t( ilast, ilast ) = czero
533 DO 40 j = ilast - 1, ilo, -1
540 IF( abs1( h( j, j-1 ) ).LE.max( safmin, ulp*(
541 $ abs1( h( j, j ) ) + abs1( h( j-1, j-1 ) )
552 IF( abs( t( j, j ) ).LT.btol )
THEN
558 IF( .NOT.ilazro )
THEN
559 IF( abs1( h( j, j-1 ) )*( ascale*abs1( h( j+1,
560 $ j ) ) ).LE.abs1( h( j, j ) )*( ascale*atol ) )
570 IF( ilazro .OR. ilazr2 )
THEN
571 DO 20 jch = j, ilast - 1
572 ctemp = h( jch, jch )
573 CALL zlartg( ctemp, h( jch+1, jch ), c, s,
575 h( jch+1, jch ) = czero
576 CALL zrot( ilastm-jch, h( jch, jch+1 ), ldh,
577 $ h( jch+1, jch+1 ), ldh, c, s )
578 CALL zrot( ilastm-jch, t( jch, jch+1 ), ldt,
579 $ t( jch+1, jch+1 ), ldt, c, s )
581 $
CALL zrot( n, q( 1, jch ), 1, q( 1, jch+1 ),
585 $ h( jch, jch-1 ) = h( jch, jch-1 )*c
587 IF( abs1( t( jch+1, jch+1 ) ).GE.btol )
THEN
588 IF( jch+1.GE.ilast )
THEN
595 t( jch+1, jch+1 ) = czero
603 DO 30 jch = j, ilast - 1
604 ctemp = t( jch, jch+1 )
605 CALL zlartg( ctemp, t( jch+1, jch+1 ), c, s,
607 t( jch+1, jch+1 ) = czero
608 IF( jch.LT.ilastm-1 )
609 $
CALL zrot( ilastm-jch-1, t( jch, jch+2 ),
611 $ t( jch+1, jch+2 ), ldt, c, s )
612 CALL zrot( ilastm-jch+2, h( jch, jch-1 ), ldh,
613 $ h( jch+1, jch-1 ), ldh, c, s )
615 $
CALL zrot( n, q( 1, jch ), 1, q( 1, jch+1 ),
618 ctemp = h( jch+1, jch )
619 CALL zlartg( ctemp, h( jch+1, jch-1 ), c, s,
621 h( jch+1, jch-1 ) = czero
622 CALL zrot( jch+1-ifrstm, h( ifrstm, jch ), 1,
623 $ h( ifrstm, jch-1 ), 1, c, s )
624 CALL zrot( jch-ifrstm, t( ifrstm, jch ), 1,
625 $ t( ifrstm, jch-1 ), 1, c, s )
627 $
CALL zrot( n, z( 1, jch ), 1, z( 1, jch-1 ),
633 ELSE IF( ilazro )
THEN
654 ctemp = h( ilast, ilast )
655 CALL zlartg( ctemp, h( ilast, ilast-1 ), c, s,
656 $ h( ilast, ilast ) )
657 h( ilast, ilast-1 ) = czero
658 CALL zrot( ilast-ifrstm, h( ifrstm, ilast ), 1,
659 $ h( ifrstm, ilast-1 ), 1, c, s )
660 CALL zrot( ilast-ifrstm, t( ifrstm, ilast ), 1,
661 $ t( ifrstm, ilast-1 ), 1, c, s )
663 $
CALL zrot( n, z( 1, ilast ), 1, z( 1, ilast-1 ), 1, c,
669 absb = abs( t( ilast, ilast ) )
670 IF( absb.GT.safmin )
THEN
671 signbc = dconjg( t( ilast, ilast ) / absb )
672 t( ilast, ilast ) = absb
674 CALL zscal( ilast-ifrstm, signbc, t( ifrstm, ilast ),
676 CALL zscal( ilast+1-ifrstm, signbc, h( ifrstm,
680 CALL zscal( 1, signbc, h( ilast, ilast ), 1 )
683 $
CALL zscal( n, signbc, z( 1, ilast ), 1 )
685 t( ilast, ilast ) = czero
687 alpha( ilast ) = h( ilast, ilast )
688 beta( ilast ) = t( ilast, ilast )
700 IF( .NOT.ilschr )
THEN
702 IF( ifrstm.GT.ilast )
714 IF( .NOT.ilschr )
THEN
724 IF( ( iiter / 10 )*10.NE.iiter )
THEN
733 u12 = ( bscale*t( ilast-1, ilast ) ) /
734 $ ( bscale*t( ilast, ilast ) )
735 ad11 = ( ascale*h( ilast-1, ilast-1 ) ) /
736 $ ( bscale*t( ilast-1, ilast-1 ) )
737 ad21 = ( ascale*h( ilast, ilast-1 ) ) /
738 $ ( bscale*t( ilast-1, ilast-1 ) )
739 ad12 = ( ascale*h( ilast-1, ilast ) ) /
740 $ ( bscale*t( ilast, ilast ) )
741 ad22 = ( ascale*h( ilast, ilast ) ) /
742 $ ( bscale*t( ilast, ilast ) )
743 abi22 = ad22 - u12*ad21
744 abi12 = ad12 - u12*ad11
747 ctemp = sqrt( abi12 )*sqrt( ad21 )
749 IF( ctemp.NE.zero )
THEN
750 x = half*( ad11-shift )
752 temp = max( temp, abs1( x ) )
753 y = temp*sqrt( ( x / temp )**2+( ctemp / temp )**2 )
754 IF( temp2.GT.zero )
THEN
755 IF( dble( x / temp2 )*dble( y )+
756 $ dimag( x / temp2 )*dimag( y ).LT.zero )y = -y
758 shift = shift - ctemp*zladiv( ctemp, ( x+y ) )
764 IF( ( iiter / 20 )*20.EQ.iiter .AND.
765 $ bscale*abs1(t( ilast, ilast )).GT.safmin )
THEN
766 eshift = eshift + ( ascale*h( ilast,
767 $ ilast ) )/( bscale*t( ilast, ilast ) )
769 eshift = eshift + ( ascale*h( ilast,
770 $ ilast-1 ) )/( bscale*t( ilast-1, ilast-1 ) )
777 DO 80 j = ilast - 1, ifirst + 1, -1
779 ctemp = ascale*h( j, j ) - shift*( bscale*t( j, j ) )
781 temp2 = ascale*abs1( h( j+1, j ) )
782 tempr = max( temp, temp2 )
783 IF( tempr.LT.one .AND. tempr.NE.zero )
THEN
785 temp2 = temp2 / tempr
787 IF( abs1( h( j, j-1 ) )*temp2.LE.temp*atol )
792 ctemp = ascale*h( ifirst, ifirst ) -
793 $ shift*( bscale*t( ifirst, ifirst ) )
800 ctemp2 = ascale*h( istart+1, istart )
801 CALL zlartg( ctemp, ctemp2, c, s, ctemp3 )
805 DO 150 j = istart, ilast - 1
806 IF( j.GT.istart )
THEN
808 CALL zlartg( ctemp, h( j+1, j-1 ), c, s, h( j, j-1 ) )
809 h( j+1, j-1 ) = czero
812 DO 100 jc = j, ilastm
813 ctemp = c*h( j, jc ) + s*h( j+1, jc )
814 h( j+1, jc ) = -dconjg( s )*h( j, jc ) + c*h( j+1, jc )
816 ctemp2 = c*t( j, jc ) + s*t( j+1, jc )
817 t( j+1, jc ) = -dconjg( s )*t( j, jc ) + c*t( j+1, jc )
822 ctemp = c*q( jr, j ) + dconjg( s )*q( jr, j+1 )
823 q( jr, j+1 ) = -s*q( jr, j ) + c*q( jr, j+1 )
828 ctemp = t( j+1, j+1 )
829 CALL zlartg( ctemp, t( j+1, j ), c, s, t( j+1, j+1 ) )
832 DO 120 jr = ifrstm, min( j+2, ilast )
833 ctemp = c*h( jr, j+1 ) + s*h( jr, j )
834 h( jr, j ) = -dconjg( s )*h( jr, j+1 ) + c*h( jr, j )
837 DO 130 jr = ifrstm, j
838 ctemp = c*t( jr, j+1 ) + s*t( jr, j )
839 t( jr, j ) = -dconjg( s )*t( jr, j+1 ) + c*t( jr, j )
844 ctemp = c*z( jr, j+1 ) + s*z( jr, j )
845 z( jr, j ) = -dconjg( s )*z( jr, j+1 ) + c*z( jr, j )
867 DO 200 j = 1, ilo - 1
868 absb = abs( t( j, j ) )
869 IF( absb.GT.safmin )
THEN
870 signbc = dconjg( t( j, j ) / absb )
873 CALL zscal( j-1, signbc, t( 1, j ), 1 )
874 CALL zscal( j, signbc, h( 1, j ), 1 )
876 CALL zscal( 1, signbc, h( j, j ), 1 )
879 $
CALL zscal( n, signbc, z( 1, j ), 1 )
883 alpha( j ) = h( j, j )
884 beta( j ) = t( j, j )
894 work( 1 ) = dcmplx( n )