303 SUBROUTINE dhgeqz( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
304 $ alphar, alphai, beta, q, ldq, z, ldz, work,
313 CHARACTER compq, compz, job
314 INTEGER ihi, ilo, info, ldh, ldq, ldt, ldz, lwork, n
317 DOUBLE PRECISION alphai( * ), alphar( * ), beta( * ),
318 $ h( ldh, * ), q( ldq, * ), t( ldt, * ),
319 $ work( * ), z( ldz, * )
326 DOUBLE PRECISION half, zero, one, safety
327 parameter( half = 0.5d+0, zero = 0.0d+0, one = 1.0d+0,
331 LOGICAL ilazr2, ilazro, ilpivt, ilq, ilschr, ilz,
333 INTEGER icompq, icompz, ifirst, ifrstm, iiter, ilast,
334 $ ilastm, in, ischur, istart, j, jc, jch, jiter,
336 DOUBLE PRECISION a11, a12, a1i, a1r, a21, a22, a2i, a2r, ad11,
337 $ ad11l, ad12, ad12l, ad21, ad21l, ad22, ad22l,
338 $ ad32l, an, anorm, ascale, atol, b11, b1a, b1i,
339 $ b1r, b22, b2a, b2i, b2r, bn, bnorm, bscale,
340 $ btol, c, c11i, c11r, c12, c21, c22i, c22r, cl,
341 $ cq, cr, cz, eshift, s, s1, s1inv, s2, safmax,
342 $ safmin, scale, sl, sqi, sqr, sr, szi, szr, t1,
343 $ tau, temp, temp2, tempi, tempr, u1, u12, u12l,
344 $ u2, ulp, vs, w11, w12, w21, w22, wabs, wi, wr,
348 DOUBLE PRECISION v( 3 )
360 INTRINSIC abs, dble, max, min, sqrt
366 IF(
lsame( job,
'E' ) )
THEN
369 ELSE IF(
lsame( job,
'S' ) )
THEN
376 IF(
lsame( compq,
'N' ) )
THEN
379 ELSE IF(
lsame( compq,
'V' ) )
THEN
382 ELSE IF(
lsame( compq,
'I' ) )
THEN
389 IF(
lsame( compz,
'N' ) )
THEN
392 ELSE IF(
lsame( compz,
'V' ) )
THEN
395 ELSE IF(
lsame( compz,
'I' ) )
THEN
405 work( 1 ) = max( 1, n )
406 lquery = ( lwork.EQ.-1 )
407 IF( ischur.EQ.0 )
THEN
409 ELSE IF( icompq.EQ.0 )
THEN
411 ELSE IF( icompz.EQ.0 )
THEN
413 ELSE IF( n.LT.0 )
THEN
415 ELSE IF( ilo.LT.1 )
THEN
417 ELSE IF( ihi.GT.n .OR. ihi.LT.ilo-1 )
THEN
419 ELSE IF( ldh.LT.n )
THEN
421 ELSE IF( ldt.LT.n )
THEN
423 ELSE IF( ldq.LT.1 .OR. ( ilq .AND. ldq.LT.n ) )
THEN
425 ELSE IF( ldz.LT.1 .OR. ( ilz .AND. ldz.LT.n ) )
THEN
427 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery )
THEN
431 CALL
xerbla(
'DHGEQZ', -info )
433 ELSE IF( lquery )
THEN
440 work( 1 ) = dble( 1 )
447 $ CALL
dlaset(
'Full', n, n, zero, one, q, ldq )
449 $ CALL
dlaset(
'Full', n, n, zero, one, z, ldz )
455 safmax = one / safmin
457 anorm =
dlanhs(
'F', in, h( ilo, ilo ), ldh, work )
458 bnorm =
dlanhs(
'F', in, t( ilo, ilo ), ldt, work )
459 atol = max( safmin, ulp*anorm )
460 btol = max( safmin, ulp*bnorm )
461 ascale = one / max( safmin, anorm )
462 bscale = one / max( safmin, bnorm )
467 IF( t( j, j ).LT.zero )
THEN
470 h( jr, j ) = -h( jr, j )
471 t( jr, j ) = -t( jr, j )
474 h( j, j ) = -h( j, j )
475 t( j, j ) = -t( j, j )
479 z( jr, j ) = -z( jr, j )
483 alphar( j ) = h( j, j )
485 beta( j ) = t( j, j )
518 maxit = 30*( ihi-ilo+1 )
520 DO 360 jiter = 1, maxit
528 IF( ilast.EQ.ilo )
THEN
534 IF( abs( h( ilast, ilast-1 ) ).LE.atol )
THEN
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.atol )
THEN
564 IF( abs( t( j, j ) ).LT.btol )
THEN
570 IF( .NOT.ilazro )
THEN
571 temp = abs( h( j, j-1 ) )
572 temp2 = abs( h( j, j ) )
573 tempr = max( temp, temp2 )
574 IF( tempr.LT.one .AND. tempr.NE.zero )
THEN
576 temp2 = temp2 / tempr
578 IF( temp*( ascale*abs( h( j+1, j ) ) ).LE.temp2*
579 $ ( ascale*atol ) )ilazr2 = .true.
588 IF( ilazro .OR. ilazr2 )
THEN
589 DO 40 jch = j, ilast - 1
591 CALL
dlartg( temp, h( jch+1, jch ), c, s,
593 h( jch+1, jch ) = zero
594 CALL
drot( ilastm-jch, h( jch, jch+1 ), ldh,
595 $ h( jch+1, jch+1 ), ldh, c, s )
596 CALL
drot( ilastm-jch, t( jch, jch+1 ), ldt,
597 $ t( jch+1, jch+1 ), ldt, c, s )
599 $ CALL
drot( n, q( 1, jch ), 1, q( 1, jch+1 ), 1,
602 $ h( jch, jch-1 ) = h( jch, jch-1 )*c
604 IF( abs( t( jch+1, jch+1 ) ).GE.btol )
THEN
605 IF( jch+1.GE.ilast )
THEN
612 t( jch+1, jch+1 ) = zero
620 DO 50 jch = j, ilast - 1
621 temp = t( jch, jch+1 )
622 CALL
dlartg( temp, t( jch+1, jch+1 ), c, s,
624 t( jch+1, jch+1 ) = zero
625 IF( jch.LT.ilastm-1 )
626 $ CALL
drot( ilastm-jch-1, t( jch, jch+2 ), ldt,
627 $ t( jch+1, jch+2 ), ldt, c, s )
628 CALL
drot( ilastm-jch+2, h( jch, jch-1 ), ldh,
629 $ h( jch+1, jch-1 ), ldh, c, s )
631 $ CALL
drot( n, q( 1, jch ), 1, q( 1, jch+1 ), 1,
633 temp = h( jch+1, jch )
634 CALL
dlartg( temp, h( jch+1, jch-1 ), c, s,
636 h( jch+1, jch-1 ) = zero
637 CALL
drot( jch+1-ifrstm, h( ifrstm, jch ), 1,
638 $ h( ifrstm, jch-1 ), 1, c, s )
639 CALL
drot( jch-ifrstm, t( ifrstm, jch ), 1,
640 $ t( ifrstm, jch-1 ), 1, c, s )
642 $ CALL
drot( n, z( 1, jch ), 1, z( 1, jch-1 ), 1,
647 ELSE IF( ilazro )
THEN
668 temp = h( ilast, ilast )
669 CALL
dlartg( temp, h( ilast, ilast-1 ), c, s,
670 $ h( ilast, ilast ) )
671 h( ilast, ilast-1 ) = zero
672 CALL
drot( ilast-ifrstm, h( ifrstm, ilast ), 1,
673 $ h( ifrstm, ilast-1 ), 1, c, s )
674 CALL
drot( ilast-ifrstm, t( ifrstm, ilast ), 1,
675 $ t( ifrstm, ilast-1 ), 1, c, s )
677 $ CALL
drot( n, z( 1, ilast ), 1, z( 1, ilast-1 ), 1, c, s )
683 IF( t( ilast, ilast ).LT.zero )
THEN
685 DO 90 j = ifrstm, ilast
686 h( j, ilast ) = -h( j, ilast )
687 t( j, ilast ) = -t( j, ilast )
690 h( ilast, ilast ) = -h( ilast, ilast )
691 t( ilast, ilast ) = -t( ilast, ilast )
695 z( j, ilast ) = -z( j, ilast )
699 alphar( ilast ) = h( ilast, ilast )
700 alphai( ilast ) = zero
701 beta( ilast ) = t( ilast, ilast )
713 IF( .NOT.ilschr )
THEN
715 IF( ifrstm.GT.ilast )
727 IF( .NOT.ilschr )
THEN
737 IF( ( iiter / 10 )*10.EQ.iiter )
THEN
742 IF( ( dble( maxit )*safmin )*abs( h( ilast-1, ilast ) ).LT.
743 $ abs( t( ilast-1, ilast-1 ) ) )
THEN
744 eshift = eshift + h( ilast, ilast-1 ) /
745 $ t( ilast-1, ilast-1 )
747 eshift = eshift + one / ( safmin*dble( maxit ) )
758 CALL
dlag2( h( ilast-1, ilast-1 ), ldh,
759 $ t( ilast-1, ilast-1 ), ldt, safmin*safety, s1,
762 temp = max( s1, safmin*max( one, abs( wr ), abs( wi ) ) )
769 temp = min( ascale, one )*( half*safmax )
770 IF( s1.GT.temp )
THEN
776 temp = min( bscale, one )*( half*safmax )
777 IF( abs( wr ).GT.temp )
778 $ scale = min( scale, temp / abs( wr ) )
784 DO 120 j = ilast - 1, ifirst + 1, -1
786 temp = abs( s1*h( j, j-1 ) )
787 temp2 = abs( s1*h( j, j )-wr*t( j, j ) )
788 tempr = max( temp, temp2 )
789 IF( tempr.LT.one .AND. tempr.NE.zero )
THEN
791 temp2 = temp2 / tempr
793 IF( abs( ( ascale*h( j+1, j ) )*temp ).LE.( ascale*atol )*
804 temp = s1*h( istart, istart ) - wr*t( istart, istart )
805 temp2 = s1*h( istart+1, istart )
806 CALL
dlartg( temp, temp2, c, s, tempr )
810 DO 190 j = istart, ilast - 1
811 IF( j.GT.istart )
THEN
813 CALL
dlartg( temp, h( j+1, j-1 ), c, s, h( j, j-1 ) )
817 DO 140 jc = j, ilastm
818 temp = c*h( j, jc ) + s*h( j+1, jc )
819 h( j+1, jc ) = -s*h( j, jc ) + c*h( j+1, jc )
821 temp2 = c*t( j, jc ) + s*t( j+1, jc )
822 t( j+1, jc ) = -s*t( j, jc ) + c*t( j+1, jc )
827 temp = c*q( jr, j ) + s*q( jr, j+1 )
828 q( jr, j+1 ) = -s*q( jr, j ) + c*q( jr, j+1 )
834 CALL
dlartg( temp, t( j+1, j ), c, s, t( j+1, j+1 ) )
837 DO 160 jr = ifrstm, min( j+2, ilast )
838 temp = c*h( jr, j+1 ) + s*h( jr, j )
839 h( jr, j ) = -s*h( jr, j+1 ) + c*h( jr, j )
842 DO 170 jr = ifrstm, j
843 temp = c*t( jr, j+1 ) + s*t( jr, j )
844 t( jr, j ) = -s*t( jr, j+1 ) + c*t( jr, j )
849 temp = c*z( jr, j+1 ) + s*z( jr, j )
850 z( jr, j ) = -s*z( jr, j+1 ) + c*z( jr, j )
866 IF( ifirst+1.EQ.ilast )
THEN
876 CALL
dlasv2( t( ilast-1, ilast-1 ), t( ilast-1, ilast ),
877 $ t( ilast, ilast ), b22, b11, sr, cr, sl, cl )
879 IF( b11.LT.zero )
THEN
886 CALL
drot( ilastm+1-ifirst, h( ilast-1, ilast-1 ), ldh,
887 $ h( ilast, ilast-1 ), ldh, cl, sl )
888 CALL
drot( ilast+1-ifrstm, h( ifrstm, ilast-1 ), 1,
889 $ h( ifrstm, ilast ), 1, cr, sr )
891 IF( ilast.LT.ilastm )
892 $ CALL
drot( ilastm-ilast, t( ilast-1, ilast+1 ), ldt,
893 $ t( ilast, ilast+1 ), ldt, cl, sl )
894 IF( ifrstm.LT.ilast-1 )
895 $ CALL
drot( ifirst-ifrstm, t( ifrstm, ilast-1 ), 1,
896 $ t( ifrstm, ilast ), 1, cr, sr )
899 $ CALL
drot( n, q( 1, ilast-1 ), 1, q( 1, ilast ), 1, cl,
902 $ CALL
drot( n, z( 1, ilast-1 ), 1, z( 1, ilast ), 1, cr,
905 t( ilast-1, ilast-1 ) = b11
906 t( ilast-1, ilast ) = zero
907 t( ilast, ilast-1 ) = zero
908 t( ilast, ilast ) = b22
912 IF( b22.LT.zero )
THEN
913 DO 210 j = ifrstm, ilast
914 h( j, ilast ) = -h( j, ilast )
915 t( j, ilast ) = -t( j, ilast )
920 z( j, ilast ) = -z( j, ilast )
930 CALL
dlag2( h( ilast-1, ilast-1 ), ldh,
931 $ t( ilast-1, ilast-1 ), ldt, safmin*safety, s1,
932 $ temp, wr, temp2, wi )
943 a11 = h( ilast-1, ilast-1 )
944 a21 = h( ilast, ilast-1 )
945 a12 = h( ilast-1, ilast )
946 a22 = h( ilast, ilast )
954 c11r = s1*a11 - wr*b11
958 c22r = s1*a22 - wr*b22
961 IF( abs( c11r )+abs( c11i )+abs( c12 ).GT.abs( c21 )+
962 $ abs( c22r )+abs( c22i ) )
THEN
963 t1 =
dlapy3( c12, c11r, c11i )
969 IF( cz.LE.safmin )
THEN
978 szr = -c21*tempr / t1
989 an = abs( a11 ) + abs( a12 ) + abs( a21 ) + abs( a22 )
990 bn = abs( b11 ) + abs( b22 )
991 wabs = abs( wr ) + abs( wi )
992 IF( s1*an.GT.wabs*bn )
THEN
997 a1r = cz*a11 + szr*a12
999 a2r = cz*a21 + szr*a22
1002 IF( cq.LE.safmin )
THEN
1009 sqr = tempr*a2r + tempi*a2i
1010 sqi = tempi*a2r - tempr*a2i
1013 t1 =
dlapy3( cq, sqr, sqi )
1020 tempr = sqr*szr - sqi*szi
1021 tempi = sqr*szi + sqi*szr
1022 b1r = cq*cz*b11 + tempr*b22
1025 b2r = cq*cz*b22 + tempr*b11
1031 beta( ilast-1 ) = b1a
1033 alphar( ilast-1 ) = ( wr*b1a )*s1inv
1034 alphai( ilast-1 ) = ( wi*b1a )*s1inv
1035 alphar( ilast ) = ( wr*b2a )*s1inv
1036 alphai( ilast ) = -( wi*b2a )*s1inv
1048 IF( .NOT.ilschr )
THEN
1050 IF( ifrstm.GT.ilast )
1068 ad11 = ( ascale*h( ilast-1, ilast-1 ) ) /
1069 $ ( bscale*t( ilast-1, ilast-1 ) )
1070 ad21 = ( ascale*h( ilast, ilast-1 ) ) /
1071 $ ( bscale*t( ilast-1, ilast-1 ) )
1072 ad12 = ( ascale*h( ilast-1, ilast ) ) /
1073 $ ( bscale*t( ilast, ilast ) )
1074 ad22 = ( ascale*h( ilast, ilast ) ) /
1075 $ ( bscale*t( ilast, ilast ) )
1076 u12 = t( ilast-1, ilast ) / t( ilast, ilast )
1077 ad11l = ( ascale*h( ifirst, ifirst ) ) /
1078 $ ( bscale*t( ifirst, ifirst ) )
1079 ad21l = ( ascale*h( ifirst+1, ifirst ) ) /
1080 $ ( bscale*t( ifirst, ifirst ) )
1081 ad12l = ( ascale*h( ifirst, ifirst+1 ) ) /
1082 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1083 ad22l = ( ascale*h( ifirst+1, ifirst+1 ) ) /
1084 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1085 ad32l = ( ascale*h( ifirst+2, ifirst+1 ) ) /
1086 $ ( bscale*t( ifirst+1, ifirst+1 ) )
1087 u12l = t( ifirst, ifirst+1 ) / t( ifirst+1, ifirst+1 )
1089 v( 1 ) = ( ad11-ad11l )*( ad22-ad11l ) - ad12*ad21 +
1090 $ ad21*u12*ad11l + ( ad12l-ad11l*u12l )*ad21l
1091 v( 2 ) = ( ( ad22l-ad11l )-ad21l*u12l-( ad11-ad11l )-
1092 $ ( ad22-ad11l )+ad21*u12 )*ad21l
1093 v( 3 ) = ad32l*ad21l
1097 CALL
dlarfg( 3, v( 1 ), v( 2 ), 1, tau )
1102 DO 290 j = istart, ilast - 2
1108 IF( j.GT.istart )
THEN
1109 v( 1 ) = h( j, j-1 )
1110 v( 2 ) = h( j+1, j-1 )
1111 v( 3 ) = h( j+2, j-1 )
1113 CALL
dlarfg( 3, h( j, j-1 ), v( 2 ), 1, tau )
1115 h( j+1, j-1 ) = zero
1116 h( j+2, j-1 ) = zero
1119 DO 230 jc = j, ilastm
1120 temp = tau*( h( j, jc )+v( 2 )*h( j+1, jc )+v( 3 )*
1122 h( j, jc ) = h( j, jc ) - temp
1123 h( j+1, jc ) = h( j+1, jc ) - temp*v( 2 )
1124 h( j+2, jc ) = h( j+2, jc ) - temp*v( 3 )
1125 temp2 = tau*( t( j, jc )+v( 2 )*t( j+1, jc )+v( 3 )*
1127 t( j, jc ) = t( j, jc ) - temp2
1128 t( j+1, jc ) = t( j+1, jc ) - temp2*v( 2 )
1129 t( j+2, jc ) = t( j+2, jc ) - temp2*v( 3 )
1133 temp = tau*( q( jr, j )+v( 2 )*q( jr, j+1 )+v( 3 )*
1135 q( jr, j ) = q( jr, j ) - temp
1136 q( jr, j+1 ) = q( jr, j+1 ) - temp*v( 2 )
1137 q( jr, j+2 ) = q( jr, j+2 ) - temp*v( 3 )
1146 temp = max( abs( t( j+1, j+1 ) ), abs( t( j+1, j+2 ) ) )
1147 temp2 = max( abs( t( j+2, j+1 ) ), abs( t( j+2, j+2 ) ) )
1148 IF( max( temp, temp2 ).LT.safmin )
THEN
1153 ELSE IF( temp.GE.temp2 )
THEN
1171 IF( abs( w12 ).GT.abs( w11 ) )
THEN
1185 w22 = w22 - temp*w12
1191 IF( abs( w22 ).LT.safmin )
THEN
1197 IF( abs( w22 ).LT.abs( u2 ) )
1198 $ scale = abs( w22 / u2 )
1199 IF( abs( w11 ).LT.abs( u1 ) )
1200 $ scale = min( scale, abs( w11 / u1 ) )
1204 u2 = ( scale*u2 ) / w22
1205 u1 = ( scale*u1-w12*u2 ) / w11
1216 t1 = sqrt( scale**2+u1**2+u2**2 )
1217 tau = one + scale / t1
1218 vs = -one / ( scale+t1 )
1225 DO 260 jr = ifrstm, min( j+3, ilast )
1226 temp = tau*( h( jr, j )+v( 2 )*h( jr, j+1 )+v( 3 )*
1228 h( jr, j ) = h( jr, j ) - temp
1229 h( jr, j+1 ) = h( jr, j+1 ) - temp*v( 2 )
1230 h( jr, j+2 ) = h( jr, j+2 ) - temp*v( 3 )
1232 DO 270 jr = ifrstm, j + 2
1233 temp = tau*( t( jr, j )+v( 2 )*t( jr, j+1 )+v( 3 )*
1235 t( jr, j ) = t( jr, j ) - temp
1236 t( jr, j+1 ) = t( jr, j+1 ) - temp*v( 2 )
1237 t( jr, j+2 ) = t( jr, j+2 ) - temp*v( 3 )
1241 temp = tau*( z( jr, j )+v( 2 )*z( jr, j+1 )+v( 3 )*
1243 z( jr, j ) = z( jr, j ) - temp
1244 z( jr, j+1 ) = z( jr, j+1 ) - temp*v( 2 )
1245 z( jr, j+2 ) = z( jr, j+2 ) - temp*v( 3 )
1258 CALL
dlartg( temp, h( j+1, j-1 ), c, s, h( j, j-1 ) )
1259 h( j+1, j-1 ) = zero
1261 DO 300 jc = j, ilastm
1262 temp = c*h( j, jc ) + s*h( j+1, jc )
1263 h( j+1, jc ) = -s*h( j, jc ) + c*h( j+1, jc )
1265 temp2 = c*t( j, jc ) + s*t( j+1, jc )
1266 t( j+1, jc ) = -s*t( j, jc ) + c*t( j+1, jc )
1271 temp = c*q( jr, j ) + s*q( jr, j+1 )
1272 q( jr, j+1 ) = -s*q( jr, j ) + c*q( jr, j+1 )
1279 temp = t( j+1, j+1 )
1280 CALL
dlartg( temp, t( j+1, j ), c, s, t( j+1, j+1 ) )
1283 DO 320 jr = ifrstm, ilast
1284 temp = c*h( jr, j+1 ) + s*h( jr, j )
1285 h( jr, j ) = -s*h( jr, j+1 ) + c*h( jr, j )
1288 DO 330 jr = ifrstm, ilast - 1
1289 temp = c*t( jr, j+1 ) + s*t( jr, j )
1290 t( jr, j ) = -s*t( jr, j+1 ) + c*t( jr, j )
1295 temp = c*z( jr, j+1 ) + s*z( jr, j )
1296 z( jr, j ) = -s*z( jr, j+1 ) + c*z( jr, j )
1323 DO 410 j = 1, ilo - 1
1324 IF( t( j, j ).LT.zero )
THEN
1327 h( jr, j ) = -h( jr, j )
1328 t( jr, j ) = -t( jr, j )
1331 h( j, j ) = -h( j, j )
1332 t( j, j ) = -t( j, j )
1336 z( jr, j ) = -z( jr, j )
1340 alphar( j ) = h( j, j )
1342 beta( j ) = t( j, j )
1352 work( 1 ) = dble( n )