299 SUBROUTINE dhgeqz( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T,
301 $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, WORK,
309 CHARACTER COMPQ, COMPZ, JOB
310 INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
313 DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),
314 $ H( LDH, * ), Q( LDQ, * ), T( LDT, * ),
315 $ WORK( * ), Z( LDZ, * )
322 DOUBLE PRECISION HALF, ZERO, ONE, SAFETY
323 PARAMETER ( HALF = 0.5d+0, zero = 0.0d+0, one = 1.0d+0,
327 LOGICAL ILAZR2, ILAZRO, ILPIVT, ILQ, ILSCHR, ILZ,
329 INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
330 $ ilastm, in, ischur, istart, j, jc, jch, jiter,
332 DOUBLE PRECISION A11, A12, A1I, A1R, A21, A22, A2I, A2R, AD11,
333 $ AD11L, AD12, AD12L, AD21, AD21L, AD22, AD22L,
334 $ AD32L, AN, ANORM, ASCALE, ATOL, B11, B1A, B1I,
335 $ b1r, b22, b2a, b2i, b2r, bn, bnorm, bscale,
336 $ btol, c, c11i, c11r, c12, c21, c22i, c22r, cl,
337 $ cq, cr, cz, eshift, s, s1, s1inv, s2, safmax,
338 $ safmin, scale, sl, sqi, sqr, sr, szi, szr, t1,
339 $ t2, t3, tau, temp, temp2, tempi, tempr, u1,
340 $ u12, u12l, u2, ulp, vs, w11, w12, w21, w22,
344 DOUBLE PRECISION V( 3 )
348 DOUBLE PRECISION DLAMCH, DLANHS, DLAPY2, DLAPY3
349 EXTERNAL LSAME, DLAMCH, DLANHS, DLAPY2,
358 INTRINSIC abs, dble, max, min, sqrt
364 IF( lsame( job,
'E' ) )
THEN
367 ELSE IF( lsame( job,
'S' ) )
THEN
374 IF( lsame( compq,
'N' ) )
THEN
377 ELSE IF( lsame( compq,
'V' ) )
THEN
380 ELSE IF( lsame( compq,
'I' ) )
THEN
387 IF( lsame( compz,
'N' ) )
THEN
390 ELSE IF( lsame( compz,
'V' ) )
THEN
393 ELSE IF( lsame( compz,
'I' ) )
THEN
403 work( 1 ) = max( 1, n )
404 lquery = ( lwork.EQ.-1 )
405 IF( ischur.EQ.0 )
THEN
407 ELSE IF( icompq.EQ.0 )
THEN
409 ELSE IF( icompz.EQ.0 )
THEN
411 ELSE IF( n.LT.0 )
THEN
413 ELSE IF( ilo.LT.1 )
THEN
415 ELSE IF( ihi.GT.n .OR. ihi.LT.ilo-1 )
THEN
417 ELSE IF( ldh.LT.n )
THEN
419 ELSE IF( ldt.LT.n )
THEN
421 ELSE IF( ldq.LT.1 .OR. ( ilq .AND. ldq.LT.n ) )
THEN
423 ELSE IF( ldz.LT.1 .OR. ( ilz .AND. ldz.LT.n ) )
THEN
425 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery )
THEN
429 CALL xerbla(
'DHGEQZ', -info )
431 ELSE IF( lquery )
THEN
438 work( 1 ) = dble( 1 )
445 $
CALL dlaset(
'Full', n, n, zero, one, q, ldq )
447 $
CALL dlaset(
'Full', n, n, zero, one, z, ldz )
452 safmin = dlamch(
'S' )
453 safmax = one / safmin
454 ulp = dlamch(
'E' )*dlamch(
'B' )
455 anorm = dlanhs(
'F', in, h( ilo, ilo ), ldh, work )
456 bnorm = dlanhs(
'F', in, t( ilo, ilo ), ldt, work )
457 atol = max( safmin, ulp*anorm )
458 btol = max( safmin, ulp*bnorm )
459 ascale = one / max( safmin, anorm )
460 bscale = one / max( safmin, bnorm )
465 IF( t( j, j ).LT.zero )
THEN
468 h( jr, j ) = -h( jr, j )
469 t( jr, j ) = -t( jr, j )
472 h( j, j ) = -h( j, j )
473 t( j, j ) = -t( j, j )
477 z( jr, j ) = -z( jr, j )
481 alphar( j ) = h( j, j )
483 beta( j ) = t( j, j )
516 maxit = 30*( ihi-ilo+1 )
518 DO 360 jiter = 1, maxit
526 IF( ilast.EQ.ilo )
THEN
532 IF( abs( h( ilast, ilast-1 ) ).LE.max( safmin, ulp*(
533 $ abs( h( ilast, ilast ) ) + abs( h( ilast-1, ilast-1 ) )
535 h( ilast, ilast-1 ) = zero
540 IF( abs( t( ilast, ilast ) ).LE.btol )
THEN
541 t( ilast, ilast ) = zero
547 DO 60 j = ilast - 1, ilo, -1
554 IF( abs( h( j, j-1 ) ).LE.max( safmin, ulp*(
555 $ abs( h( j, j ) ) + abs( h( j-1, j-1 ) )
566 IF( abs( t( j, j ) ).LT.btol )
THEN
572 IF( .NOT.ilazro )
THEN
573 temp = abs( h( j, j-1 ) )
574 temp2 = abs( h( j, j ) )
575 tempr = max( temp, temp2 )
576 IF( tempr.LT.one .AND. tempr.NE.zero )
THEN
578 temp2 = temp2 / tempr
580 IF( temp*( ascale*abs( h( j+1, j ) ) ).LE.temp2*
581 $ ( ascale*atol ) )ilazr2 = .true.
590 IF( ilazro .OR. ilazr2 )
THEN
591 DO 40 jch = j, ilast - 1
593 CALL dlartg( temp, h( jch+1, jch ), c, s,
595 h( jch+1, jch ) = zero
596 CALL drot( ilastm-jch, h( jch, jch+1 ), ldh,
597 $ h( jch+1, jch+1 ), ldh, c, s )
598 CALL drot( ilastm-jch, t( jch, jch+1 ), ldt,
599 $ t( jch+1, jch+1 ), ldt, c, s )
601 $
CALL drot( n, q( 1, jch ), 1, q( 1, jch+1 ),
605 $ h( jch, jch-1 ) = h( jch, jch-1 )*c
607 IF( abs( t( jch+1, jch+1 ) ).GE.btol )
THEN
608 IF( jch+1.GE.ilast )
THEN
615 t( jch+1, jch+1 ) = zero
623 DO 50 jch = j, ilast - 1
624 temp = t( jch, jch+1 )
625 CALL dlartg( temp, t( jch+1, jch+1 ), c, s,
627 t( jch+1, jch+1 ) = zero
628 IF( jch.LT.ilastm-1 )
629 $
CALL drot( ilastm-jch-1, t( jch, jch+2 ),
631 $ t( jch+1, jch+2 ), ldt, c, s )
632 CALL drot( ilastm-jch+2, h( jch, jch-1 ), ldh,
633 $ h( jch+1, jch-1 ), ldh, c, s )
635 $
CALL drot( n, q( 1, jch ), 1, q( 1, jch+1 ),
638 temp = h( jch+1, jch )
639 CALL dlartg( temp, h( jch+1, jch-1 ), c, s,
641 h( jch+1, jch-1 ) = zero
642 CALL drot( jch+1-ifrstm, h( ifrstm, jch ), 1,
643 $ h( ifrstm, jch-1 ), 1, c, s )
644 CALL drot( jch-ifrstm, t( ifrstm, jch ), 1,
645 $ t( ifrstm, jch-1 ), 1, c, s )
647 $
CALL drot( n, z( 1, jch ), 1, z( 1, jch-1 ),
653 ELSE IF( ilazro )
THEN
674 temp = h( ilast, ilast )
675 CALL dlartg( temp, h( ilast, ilast-1 ), c, s,
676 $ h( ilast, ilast ) )
677 h( ilast, ilast-1 ) = zero
678 CALL drot( ilast-ifrstm, h( ifrstm, ilast ), 1,
679 $ h( ifrstm, ilast-1 ), 1, c, s )
680 CALL drot( ilast-ifrstm, t( ifrstm, ilast ), 1,
681 $ t( ifrstm, ilast-1 ), 1, c, s )
683 $
CALL drot( n, z( 1, ilast ), 1, z( 1, ilast-1 ), 1, c,
690 IF( t( ilast, ilast ).LT.zero )
THEN
692 DO 90 j = ifrstm, ilast
693 h( j, ilast ) = -h( j, ilast )
694 t( j, ilast ) = -t( j, ilast )
697 h( ilast, ilast ) = -h( ilast, ilast )
698 t( ilast, ilast ) = -t( ilast, ilast )
702 z( j, ilast ) = -z( j, ilast )
706 alphar( ilast ) = h( ilast, ilast )
707 alphai( ilast ) = zero
708 beta( ilast ) = t( ilast, ilast )
720 IF( .NOT.ilschr )
THEN
722 IF( ifrstm.GT.ilast )
734 IF( .NOT.ilschr )
THEN
744 IF( ( iiter / 10 )*10.EQ.iiter )
THEN
749 IF( ( dble( maxit )*safmin )*abs( h( ilast, ilast-1 ) ).LT.
750 $ abs( t( ilast-1, ilast-1 ) ) )
THEN
751 eshift = h( ilast, ilast-1 ) /
752 $ t( ilast-1, ilast-1 )
754 eshift = eshift + one / ( safmin*dble( maxit ) )
765 CALL dlag2( h( ilast-1, ilast-1 ), ldh,
766 $ t( ilast-1, ilast-1 ), ldt, safmin*safety, s1,
769 IF ( abs( (wr/s1)*t( ilast, ilast ) - h( ilast, ilast ) )
770 $ .GT. abs( (wr2/s2)*t( ilast, ilast )
771 $ - h( ilast, ilast ) ) )
THEN
779 temp = max( s1, safmin*max( one, abs( wr ), abs( wi ) ) )
786 temp = min( ascale, one )*( half*safmax )
787 IF( s1.GT.temp )
THEN
793 temp = min( bscale, one )*( half*safmax )
794 IF( abs( wr ).GT.temp )
795 $ scale = min( scale, temp / abs( wr ) )
801 DO 120 j = ilast - 1, ifirst + 1, -1
803 temp = abs( s1*h( j, j-1 ) )
804 temp2 = abs( s1*h( j, j )-wr*t( j, j ) )
805 tempr = max( temp, temp2 )
806 IF( tempr.LT.one .AND. tempr.NE.zero )
THEN
808 temp2 = temp2 / tempr
810 IF( abs( ( ascale*h( j+1, j ) )*temp ).LE.( ascale*atol )*
821 temp = s1*h( istart, istart ) - wr*t( istart, istart )
822 temp2 = s1*h( istart+1, istart )
823 CALL dlartg( temp, temp2, c, s, tempr )
827 DO 190 j = istart, ilast - 1
828 IF( j.GT.istart )
THEN
830 CALL dlartg( temp, h( j+1, j-1 ), c, s, h( j, j-1 ) )
834 DO 140 jc = j, ilastm
835 temp = c*h( j, jc ) + s*h( j+1, jc )
836 h( j+1, jc ) = -s*h( j, jc ) + c*h( j+1, jc )
838 temp2 = c*t( j, jc ) + s*t( j+1, jc )
839 t( j+1, jc ) = -s*t( j, jc ) + c*t( j+1, jc )
844 temp = c*q( jr, j ) + s*q( jr, j+1 )
845 q( jr, j+1 ) = -s*q( jr, j ) + c*q( jr, j+1 )
851 CALL dlartg( temp, t( j+1, j ), c, s, t( j+1, j+1 ) )
854 DO 160 jr = ifrstm, min( j+2, ilast )
855 temp = c*h( jr, j+1 ) + s*h( jr, j )
856 h( jr, j ) = -s*h( jr, j+1 ) + c*h( jr, j )
859 DO 170 jr = ifrstm, j
860 temp = c*t( jr, j+1 ) + s*t( jr, j )
861 t( jr, j ) = -s*t( jr, j+1 ) + c*t( jr, j )
866 temp = c*z( jr, j+1 ) + s*z( jr, j )
867 z( jr, j ) = -s*z( jr, j+1 ) + c*z( jr, j )
883 IF( ifirst+1.EQ.ilast )
THEN
893 CALL dlasv2( t( ilast-1, ilast-1 ), t( ilast-1, ilast ),
894 $ t( ilast, ilast ), b22, b11, sr, cr, sl, cl )
896 IF( b11.LT.zero )
THEN
903 CALL drot( ilastm+1-ifirst, h( ilast-1, ilast-1 ), ldh,
904 $ h( ilast, ilast-1 ), ldh, cl, sl )
905 CALL drot( ilast+1-ifrstm, h( ifrstm, ilast-1 ), 1,
906 $ h( ifrstm, ilast ), 1, cr, sr )
908 IF( ilast.LT.ilastm )
909 $
CALL drot( ilastm-ilast, t( ilast-1, ilast+1 ), ldt,
910 $ t( ilast, ilast+1 ), ldt, cl, sl )
911 IF( ifrstm.LT.ilast-1 )
912 $
CALL drot( ifirst-ifrstm, t( ifrstm, ilast-1 ), 1,
913 $ t( ifrstm, ilast ), 1, cr, sr )
916 $
CALL drot( n, q( 1, ilast-1 ), 1, q( 1, ilast ), 1,
920 $
CALL drot( n, z( 1, ilast-1 ), 1, z( 1, ilast ), 1,
924 t( ilast-1, ilast-1 ) = b11
925 t( ilast-1, ilast ) = zero
926 t( ilast, ilast-1 ) = zero
927 t( ilast, ilast ) = b22
931 IF( b22.LT.zero )
THEN
932 DO 210 j = ifrstm, ilast
933 h( j, ilast ) = -h( j, ilast )
934 t( j, ilast ) = -t( j, ilast )
939 z( j, ilast ) = -z( j, ilast )
949 CALL dlag2( h( ilast-1, ilast-1 ), ldh,
950 $ t( ilast-1, ilast-1 ), ldt, safmin*safety, s1,
951 $ temp, wr, temp2, wi )
962 a11 = h( ilast-1, ilast-1 )
963 a21 = h( ilast, ilast-1 )
964 a12 = h( ilast-1, ilast )
965 a22 = h( ilast, ilast )
973 c11r = s1*a11 - wr*b11
977 c22r = s1*a22 - wr*b22
980 IF( abs( c11r )+abs( c11i )+abs( c12 ).GT.abs( c21 )+
981 $ abs( c22r )+abs( c22i ) )
THEN
982 t1 = dlapy3( c12, c11r, c11i )
987 cz = dlapy2( c22r, c22i )
988 IF( cz.LE.safmin )
THEN
995 t1 = dlapy2( cz, c21 )
997 szr = -c21*tempr / t1
1008 an = abs( a11 ) + abs( a12 ) + abs( a21 ) + abs( a22 )
1009 bn = abs( b11 ) + abs( b22 )
1010 wabs = abs( wr ) + abs( wi )
1011 IF( s1*an.GT.wabs*bn )
THEN
1016 a1r = cz*a11 + szr*a12
1018 a2r = cz*a21 + szr*a22
1020 cq = dlapy2( a1r, a1i )
1021 IF( cq.LE.safmin )
THEN
1028 sqr = tempr*a2r + tempi*a2i
1029 sqi = tempi*a2r - tempr*a2i
1032 t1 = dlapy3( cq, sqr, sqi )
1039 tempr = sqr*szr - sqi*szi
1040 tempi = sqr*szi + sqi*szr
1041 b1r = cq*cz*b11 + tempr*b22
1043 b1a = dlapy2( b1r, b1i )
1044 b2r = cq*cz*b22 + tempr*b11
1046 b2a = dlapy2( b2r, b2i )
1050 beta( ilast-1 ) = b1a
1052 alphar( ilast-1 ) = ( wr*b1a )*s1inv
1053 alphai( ilast-1 ) = ( wi*b1a )*s1inv
1054 alphar( ilast ) = ( wr*b2a )*s1inv
1055 alphai( ilast ) = -( wi*b2a )*s1inv
1067 IF( .NOT.ilschr )
THEN
1069 IF( ifrstm.GT.ilast )
1087 ad11 = ( ascale*h( ilast-1, ilast-1 ) ) /
1088 $ ( bscale*t( ilast-1, ilast-1 ) )
1089 ad21 = ( ascale*h( ilast, ilast-1 ) ) /
1090 $ ( bscale*t( ilast-1, ilast-1 ) )
1091 ad12 = ( ascale*h( ilast-1, ilast ) ) /
1092 $ ( bscale*t( ilast, ilast ) )
1093 ad22 = ( ascale*h( ilast, ilast ) ) /
1094 $ ( bscale*t( ilast, ilast ) )
1095 u12 = t( ilast-1, ilast ) / t( ilast, ilast )
1096 ad11l = ( ascale*h( ifirst, ifirst ) ) /
1097 $ ( bscale*t( ifirst, ifirst ) )
1098 ad21l = ( ascale*h( ifirst+1, ifirst ) ) /
1099 $ ( bscale*t( ifirst, ifirst ) )
1100 ad12l = ( ascale*h( ifirst, ifirst+1 ) ) /
1101 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1102 ad22l = ( ascale*h( ifirst+1, ifirst+1 ) ) /
1103 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1104 ad32l = ( ascale*h( ifirst+2, ifirst+1 ) ) /
1105 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1106 u12l = t( ifirst, ifirst+1 ) / t( ifirst+1, ifirst+1 )
1108 v( 1 ) = ( ad11-ad11l )*( ad22-ad11l ) - ad12*ad21 +
1109 $ ad21*u12*ad11l + ( ad12l-ad11l*u12l )*ad21l
1110 v( 2 ) = ( ( ad22l-ad11l )-ad21l*u12l-( ad11-ad11l )-
1111 $ ( ad22-ad11l )+ad21*u12 )*ad21l
1112 v( 3 ) = ad32l*ad21l
1116 CALL dlarfg( 3, v( 1 ), v( 2 ), 1, tau )
1121 DO 290 j = istart, ilast - 2
1127 IF( j.GT.istart )
THEN
1128 v( 1 ) = h( j, j-1 )
1129 v( 2 ) = h( j+1, j-1 )
1130 v( 3 ) = h( j+2, j-1 )
1132 CALL dlarfg( 3, h( j, j-1 ), v( 2 ), 1, tau )
1134 h( j+1, j-1 ) = zero
1135 h( j+2, j-1 ) = zero
1140 DO 230 jc = j, ilastm
1141 temp = h( j, jc )+v( 2 )*h( j+1, jc )+v( 3 )*
1143 h( j, jc ) = h( j, jc ) - temp*tau
1144 h( j+1, jc ) = h( j+1, jc ) - temp*t2
1145 h( j+2, jc ) = h( j+2, jc ) - temp*t3
1146 temp2 = t( j, jc )+v( 2 )*t( j+1, jc )+v( 3 )*
1148 t( j, jc ) = t( j, jc ) - temp2*tau
1149 t( j+1, jc ) = t( j+1, jc ) - temp2*t2
1150 t( j+2, jc ) = t( j+2, jc ) - temp2*t3
1154 temp = q( jr, j )+v( 2 )*q( jr, j+1 )+v( 3 )*
1156 q( jr, j ) = q( jr, j ) - temp*tau
1157 q( jr, j+1 ) = q( jr, j+1 ) - temp*t2
1158 q( jr, j+2 ) = q( jr, j+2 ) - temp*t3
1167 temp = max( abs( t( j+1, j+1 ) ), abs( t( j+1, j+2 ) ) )
1168 temp2 = max( abs( t( j+2, j+1 ) ), abs( t( j+2, j+2 ) ) )
1169 IF( max( temp, temp2 ).LT.safmin )
THEN
1174 ELSE IF( temp.GE.temp2 )
THEN
1192 IF( abs( w12 ).GT.abs( w11 ) )
THEN
1206 w22 = w22 - temp*w12
1212 IF( abs( w22 ).LT.safmin )
THEN
1218 IF( abs( w22 ).LT.abs( u2 ) )
1219 $ scale = abs( w22 / u2 )
1220 IF( abs( w11 ).LT.abs( u1 ) )
1221 $ scale = min( scale, abs( w11 / u1 ) )
1225 u2 = ( scale*u2 ) / w22
1226 u1 = ( scale*u1-w12*u2 ) / w11
1237 t1 = sqrt( scale**2+u1**2+u2**2 )
1238 tau = one + scale / t1
1239 vs = -one / ( scale+t1 )
1248 DO 260 jr = ifrstm, min( j+3, ilast )
1249 temp = h( jr, j )+v( 2 )*h( jr, j+1 )+v( 3 )*
1251 h( jr, j ) = h( jr, j ) - temp*tau
1252 h( jr, j+1 ) = h( jr, j+1 ) - temp*t2
1253 h( jr, j+2 ) = h( jr, j+2 ) - temp*t3
1255 DO 270 jr = ifrstm, j + 2
1256 temp = t( jr, j )+v( 2 )*t( jr, j+1 )+v( 3 )*
1258 t( jr, j ) = t( jr, j ) - temp*tau
1259 t( jr, j+1 ) = t( jr, j+1 ) - temp*t2
1260 t( jr, j+2 ) = t( jr, j+2 ) - temp*t3
1264 temp = z( jr, j )+v( 2 )*z( jr, j+1 )+v( 3 )*
1266 z( jr, j ) = z( jr, j ) - temp*tau
1267 z( jr, j+1 ) = z( jr, j+1 ) - temp*t2
1268 z( jr, j+2 ) = z( jr, j+2 ) - temp*t3
1281 CALL dlartg( temp, h( j+1, j-1 ), c, s, h( j, j-1 ) )
1282 h( j+1, j-1 ) = zero
1284 DO 300 jc = j, ilastm
1285 temp = c*h( j, jc ) + s*h( j+1, jc )
1286 h( j+1, jc ) = -s*h( j, jc ) + c*h( j+1, jc )
1288 temp2 = c*t( j, jc ) + s*t( j+1, jc )
1289 t( j+1, jc ) = -s*t( j, jc ) + c*t( j+1, jc )
1294 temp = c*q( jr, j ) + s*q( jr, j+1 )
1295 q( jr, j+1 ) = -s*q( jr, j ) + c*q( jr, j+1 )
1302 temp = t( j+1, j+1 )
1303 CALL dlartg( temp, t( j+1, j ), c, s, t( j+1, j+1 ) )
1306 DO 320 jr = ifrstm, ilast
1307 temp = c*h( jr, j+1 ) + s*h( jr, j )
1308 h( jr, j ) = -s*h( jr, j+1 ) + c*h( jr, j )
1311 DO 330 jr = ifrstm, ilast - 1
1312 temp = c*t( jr, j+1 ) + s*t( jr, j )
1313 t( jr, j ) = -s*t( jr, j+1 ) + c*t( jr, j )
1318 temp = c*z( jr, j+1 ) + s*z( jr, j )
1319 z( jr, j ) = -s*z( jr, j+1 ) + c*z( jr, j )
1346 DO 410 j = 1, ilo - 1
1347 IF( t( j, j ).LT.zero )
THEN
1350 h( jr, j ) = -h( jr, j )
1351 t( jr, j ) = -t( jr, j )
1354 h( j, j ) = -h( j, j )
1355 t( j, j ) = -t( j, j )
1359 z( jr, j ) = -z( jr, j )
1363 alphar( j ) = h( j, j )
1365 beta( j ) = t( j, j )
1375 work( 1 ) = dble( n )