233 SUBROUTINE dtrevc3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL,
234 $ VR, LDVR, MM, M, WORK, LWORK, INFO )
242 CHARACTER HOWMNY, SIDE
243 INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N
247 DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
254 DOUBLE PRECISION ZERO, ONE
255 parameter( zero = 0.0d+0, one = 1.0d+0 )
257 parameter( nbmin = 8, nbmax = 128 )
260 LOGICAL ALLV, BOTHV, LEFTV, LQUERY, OVER, PAIR,
262 INTEGER I, IERR, II, IP, IS, J, J1, J2, JNXT, K, KI,
263 $ iv, maxwrk, nb, ki2
264 DOUBLE PRECISION BETA, BIGNUM, EMAX, OVFL, REC, REMAX, SCALE,
265 $ smin, smlnum, ulp, unfl, vcrit, vmax, wi, wr,
270 INTEGER IDAMAX, ILAENV
271 DOUBLE PRECISION DDOT, DLAMCH
272 EXTERNAL lsame, idamax, ilaenv, ddot, dlamch
280 INTRINSIC abs, max, sqrt
283 DOUBLE PRECISION X( 2, 2 )
284 INTEGER ISCOMPLEX( NBMAX )
290 bothv = lsame( side,
'B' )
291 rightv = lsame( side,
'R' ) .OR. bothv
292 leftv = lsame( side,
'L' ) .OR. bothv
294 allv = lsame( howmny,
'A' )
295 over = lsame( howmny,
'B' )
296 somev = lsame( howmny,
'S' )
299 nb = ilaenv( 1,
'DTREVC', side // howmny, n, -1, -1, -1 )
300 maxwrk = max( 1, n + 2*n*nb )
302 lquery = ( lwork.EQ.-1 )
303 IF( .NOT.rightv .AND. .NOT.leftv )
THEN
305 ELSE IF( .NOT.allv .AND. .NOT.over .AND. .NOT.somev )
THEN
307 ELSE IF( n.LT.0 )
THEN
309 ELSE IF( ldt.LT.max( 1, n ) )
THEN
311 ELSE IF( ldvl.LT.1 .OR. ( leftv .AND. ldvl.LT.n ) )
THEN
313 ELSE IF( ldvr.LT.1 .OR. ( rightv .AND. ldvr.LT.n ) )
THEN
315 ELSE IF( lwork.LT.max( 1, 3*n ) .AND. .NOT.lquery )
THEN
329 SELECT( j ) = .false.
332 IF( t( j+1, j ).EQ.zero )
THEN
337 IF(
SELECT( j ) .OR.
SELECT( j+1 ) )
THEN
357 CALL xerbla(
'DTREVC3', -info )
359 ELSE IF( lquery )
THEN
371 IF( over .AND. lwork .GE. n + 2*n*nbmin )
THEN
372 nb = (lwork - n) / (2*n)
373 nb = min( nb, nbmax )
374 CALL dlaset(
'F', n, 1+2*nb, zero, zero, work, n )
381 unfl = dlamch(
'Safe minimum' )
383 ulp = dlamch(
'Precision' )
384 smlnum = unfl*( n / ulp )
385 bignum = ( one-ulp ) / smlnum
394 work( j ) = work( j ) + abs( t( i, j ) )
427 ELSE IF( ki.EQ.1 )
THEN
430 ELSE IF( t( ki, ki-1 ).EQ.zero )
THEN
440 IF( .NOT.
SELECT( ki ) )
443 IF( .NOT.
SELECT( ki-1 ) )
453 $ wi = sqrt( abs( t( ki, ki-1 ) ) )*
454 $ sqrt( abs( t( ki-1, ki ) ) )
455 smin = max( ulp*( abs( wr )+abs( wi ) ), smlnum )
462 work( ki + iv*n ) = one
467 work( k + iv*n ) = -t( k, ki )
474 DO 60 j = ki - 1, 1, -1
481 IF( t( j, j-1 ).NE.zero )
THEN
491 CALL dlaln2( .false., 1, 1, smin, one, t( j,
493 $ ldt, one, one, work( j+iv*n ), n, wr,
494 $ zero, x, 2, scale, xnorm, ierr )
499 IF( xnorm.GT.one )
THEN
500 IF( work( j ).GT.bignum / xnorm )
THEN
501 x( 1, 1 ) = x( 1, 1 ) / xnorm
502 scale = scale / xnorm
509 $
CALL dscal( ki, scale, work( 1+iv*n ), 1 )
510 work( j+iv*n ) = x( 1, 1 )
514 CALL daxpy( j-1, -x( 1, 1 ), t( 1, j ), 1,
515 $ work( 1+iv*n ), 1 )
521 CALL dlaln2( .false., 2, 1, smin, one,
522 $ t( j-1, j-1 ), ldt, one, one,
523 $ work( j-1+iv*n ), n, wr, zero, x, 2,
524 $ scale, xnorm, ierr )
529 IF( xnorm.GT.one )
THEN
530 beta = max( work( j-1 ), work( j ) )
531 IF( beta.GT.bignum / xnorm )
THEN
532 x( 1, 1 ) = x( 1, 1 ) / xnorm
533 x( 2, 1 ) = x( 2, 1 ) / xnorm
534 scale = scale / xnorm
541 $
CALL dscal( ki, scale, work( 1+iv*n ), 1 )
542 work( j-1+iv*n ) = x( 1, 1 )
543 work( j +iv*n ) = x( 2, 1 )
547 CALL daxpy( j-2, -x( 1, 1 ), t( 1, j-1 ), 1,
548 $ work( 1+iv*n ), 1 )
549 CALL daxpy( j-2, -x( 2, 1 ), t( 1, j ), 1,
550 $ work( 1+iv*n ), 1 )
559 CALL dcopy( ki, work( 1 + iv*n ), 1, vr( 1, is ),
562 ii = idamax( ki, vr( 1, is ), 1 )
563 remax = one / abs( vr( ii, is ) )
564 CALL dscal( ki, remax, vr( 1, is ), 1 )
570 ELSE IF( nb.EQ.1 )
THEN
574 $
CALL dgemv(
'N', n, ki-1, one, vr, ldvr,
575 $ work( 1 + iv*n ), 1, work( ki + iv*n ),
578 ii = idamax( n, vr( 1, ki ), 1 )
579 remax = one / abs( vr( ii, ki ) )
580 CALL dscal( n, remax, vr( 1, ki ), 1 )
587 work( k + iv*n ) = zero
601 IF( abs( t( ki-1, ki ) ).GE.abs( t( ki, ki-1 ) ) )
THEN
602 work( ki-1 + (iv-1)*n ) = one
603 work( ki + (iv )*n ) = wi / t( ki-1, ki )
605 work( ki-1 + (iv-1)*n ) = -wi / t( ki, ki-1 )
606 work( ki + (iv )*n ) = one
608 work( ki + (iv-1)*n ) = zero
609 work( ki-1 + (iv )*n ) = zero
614 work( k+(iv-1)*n ) = -work( ki-1+(iv-1)*n )*t(k,ki-1)
615 work( k+(iv )*n ) = -work( ki +(iv )*n )*t(k,ki )
622 DO 90 j = ki - 2, 1, -1
629 IF( t( j, j-1 ).NE.zero )
THEN
639 CALL dlaln2( .false., 1, 2, smin, one, t( j,
641 $ ldt, one, one, work( j+(iv-1)*n ), n,
642 $ wr, wi, x, 2, scale, xnorm, ierr )
647 IF( xnorm.GT.one )
THEN
648 IF( work( j ).GT.bignum / xnorm )
THEN
649 x( 1, 1 ) = x( 1, 1 ) / xnorm
650 x( 1, 2 ) = x( 1, 2 ) / xnorm
651 scale = scale / xnorm
657 IF( scale.NE.one )
THEN
658 CALL dscal( ki, scale, work( 1+(iv-1)*n ),
660 CALL dscal( ki, scale, work( 1+(iv )*n ),
663 work( j+(iv-1)*n ) = x( 1, 1 )
664 work( j+(iv )*n ) = x( 1, 2 )
668 CALL daxpy( j-1, -x( 1, 1 ), t( 1, j ), 1,
669 $ work( 1+(iv-1)*n ), 1 )
670 CALL daxpy( j-1, -x( 1, 2 ), t( 1, j ), 1,
671 $ work( 1+(iv )*n ), 1 )
677 CALL dlaln2( .false., 2, 2, smin, one,
678 $ t( j-1, j-1 ), ldt, one, one,
679 $ work( j-1+(iv-1)*n ), n, wr, wi, x, 2,
680 $ scale, xnorm, ierr )
685 IF( xnorm.GT.one )
THEN
686 beta = max( work( j-1 ), work( j ) )
687 IF( beta.GT.bignum / xnorm )
THEN
689 x( 1, 1 ) = x( 1, 1 )*rec
690 x( 1, 2 ) = x( 1, 2 )*rec
691 x( 2, 1 ) = x( 2, 1 )*rec
692 x( 2, 2 ) = x( 2, 2 )*rec
699 IF( scale.NE.one )
THEN
700 CALL dscal( ki, scale, work( 1+(iv-1)*n ),
702 CALL dscal( ki, scale, work( 1+(iv )*n ),
705 work( j-1+(iv-1)*n ) = x( 1, 1 )
706 work( j +(iv-1)*n ) = x( 2, 1 )
707 work( j-1+(iv )*n ) = x( 1, 2 )
708 work( j +(iv )*n ) = x( 2, 2 )
712 CALL daxpy( j-2, -x( 1, 1 ), t( 1, j-1 ), 1,
713 $ work( 1+(iv-1)*n ), 1 )
714 CALL daxpy( j-2, -x( 2, 1 ), t( 1, j ), 1,
715 $ work( 1+(iv-1)*n ), 1 )
716 CALL daxpy( j-2, -x( 1, 2 ), t( 1, j-1 ), 1,
717 $ work( 1+(iv )*n ), 1 )
718 CALL daxpy( j-2, -x( 2, 2 ), t( 1, j ), 1,
719 $ work( 1+(iv )*n ), 1 )
728 CALL dcopy( ki, work( 1+(iv-1)*n ), 1, vr(1,is-1),
730 CALL dcopy( ki, work( 1+(iv )*n ), 1, vr(1,is ),
735 emax = max( emax, abs( vr( k, is-1 ) )+
736 $ abs( vr( k, is ) ) )
739 CALL dscal( ki, remax, vr( 1, is-1 ), 1 )
740 CALL dscal( ki, remax, vr( 1, is ), 1 )
747 ELSE IF( nb.EQ.1 )
THEN
751 CALL dgemv(
'N', n, ki-2, one, vr, ldvr,
752 $ work( 1 + (iv-1)*n ), 1,
753 $ work( ki-1 + (iv-1)*n ), vr(1,ki-1), 1)
754 CALL dgemv(
'N', n, ki-2, one, vr, ldvr,
755 $ work( 1 + (iv)*n ), 1,
756 $ work( ki + (iv)*n ), vr( 1, ki ), 1 )
758 CALL dscal( n, work(ki-1+(iv-1)*n), vr(1,ki-1),
760 CALL dscal( n, work(ki +(iv )*n), vr(1,ki ),
766 emax = max( emax, abs( vr( k, ki-1 ) )+
767 $ abs( vr( k, ki ) ) )
770 CALL dscal( n, remax, vr( 1, ki-1 ), 1 )
771 CALL dscal( n, remax, vr( 1, ki ), 1 )
778 work( k + (iv-1)*n ) = zero
779 work( k + (iv )*n ) = zero
781 iscomplex( iv-1 ) = -ip
801 IF( (iv.LE.2) .OR. (ki2.EQ.1) )
THEN
802 CALL dgemm(
'N',
'N', n, nb-iv+1, ki2+nb-iv, one,
804 $ work( 1 + (iv)*n ), n,
806 $ work( 1 + (nb+iv)*n ), n )
809 IF( iscomplex(k).EQ.0 )
THEN
811 ii = idamax( n, work( 1 + (nb+k)*n ), 1 )
812 remax = one / abs( work( ii + (nb+k)*n ) )
813 ELSE IF( iscomplex(k).EQ.1 )
THEN
818 $ abs( work( ii + (nb+k )*n ) )+
819 $ abs( work( ii + (nb+k+1)*n ) ) )
826 CALL dscal( n, remax, work( 1 + (nb+k)*n ), 1 )
828 CALL dlacpy(
'F', n, nb-iv+1,
829 $ work( 1 + (nb+iv)*n ), n,
830 $ vr( 1, ki2 ), ldvr )
862 ELSE IF( ki.EQ.n )
THEN
865 ELSE IF( t( ki+1, ki ).EQ.zero )
THEN
874 IF( .NOT.
SELECT( ki ) )
883 $ wi = sqrt( abs( t( ki, ki+1 ) ) )*
884 $ sqrt( abs( t( ki+1, ki ) ) )
885 smin = max( ulp*( abs( wr )+abs( wi ) ), smlnum )
892 work( ki + iv*n ) = one
897 work( k + iv*n ) = -t( ki, k )
914 IF( t( j+1, j ).NE.zero )
THEN
927 IF( work( j ).GT.vcrit )
THEN
929 CALL dscal( n-ki+1, rec, work( ki+iv*n ), 1 )
934 work( j+iv*n ) = work( j+iv*n ) -
935 $ ddot( j-ki-1, t( ki+1, j ), 1,
936 $ work( ki+1+iv*n ), 1 )
940 CALL dlaln2( .false., 1, 1, smin, one, t( j,
942 $ ldt, one, one, work( j+iv*n ), n, wr,
943 $ zero, x, 2, scale, xnorm, ierr )
948 $
CALL dscal( n-ki+1, scale, work( ki+iv*n ),
950 work( j+iv*n ) = x( 1, 1 )
951 vmax = max( abs( work( j+iv*n ) ), vmax )
952 vcrit = bignum / vmax
961 beta = max( work( j ), work( j+1 ) )
962 IF( beta.GT.vcrit )
THEN
964 CALL dscal( n-ki+1, rec, work( ki+iv*n ), 1 )
969 work( j+iv*n ) = work( j+iv*n ) -
970 $ ddot( j-ki-1, t( ki+1, j ), 1,
971 $ work( ki+1+iv*n ), 1 )
973 work( j+1+iv*n ) = work( j+1+iv*n ) -
974 $ ddot( j-ki-1, t( ki+1, j+1 ),
976 $ work( ki+1+iv*n ), 1 )
982 CALL dlaln2( .true., 2, 1, smin, one, t( j, j ),
983 $ ldt, one, one, work( j+iv*n ), n, wr,
984 $ zero, x, 2, scale, xnorm, ierr )
989 $
CALL dscal( n-ki+1, scale, work( ki+iv*n ),
991 work( j +iv*n ) = x( 1, 1 )
992 work( j+1+iv*n ) = x( 2, 1 )
994 vmax = max( abs( work( j +iv*n ) ),
995 $ abs( work( j+1+iv*n ) ), vmax )
996 vcrit = bignum / vmax
1003 IF( .NOT.over )
THEN
1006 CALL dcopy( n-ki+1, work( ki + iv*n ), 1,
1009 ii = idamax( n-ki+1, vl( ki, is ), 1 ) + ki - 1
1010 remax = one / abs( vl( ii, is ) )
1011 CALL dscal( n-ki+1, remax, vl( ki, is ), 1 )
1013 DO 180 k = 1, ki - 1
1017 ELSE IF( nb.EQ.1 )
THEN
1021 $
CALL dgemv(
'N', n, n-ki, one,
1022 $ vl( 1, ki+1 ), ldvl,
1023 $ work( ki+1 + iv*n ), 1,
1024 $ work( ki + iv*n ), vl( 1, ki ), 1 )
1026 ii = idamax( n, vl( 1, ki ), 1 )
1027 remax = one / abs( vl( ii, ki ) )
1028 CALL dscal( n, remax, vl( 1, ki ), 1 )
1036 work( k + iv*n ) = zero
1038 iscomplex( iv ) = ip
1050 IF( abs( t( ki, ki+1 ) ).GE.abs( t( ki+1, ki ) ) )
THEN
1051 work( ki + (iv )*n ) = wi / t( ki, ki+1 )
1052 work( ki+1 + (iv+1)*n ) = one
1054 work( ki + (iv )*n ) = one
1055 work( ki+1 + (iv+1)*n ) = -wi / t( ki+1, ki )
1057 work( ki+1 + (iv )*n ) = zero
1058 work( ki + (iv+1)*n ) = zero
1062 DO 190 k = ki + 2, n
1063 work( k+(iv )*n ) = -work( ki +(iv )*n )*t(ki, k)
1064 work( k+(iv+1)*n ) = -work( ki+1+(iv+1)*n )*t(ki+1,k)
1074 DO 200 j = ki + 2, n
1081 IF( t( j+1, j ).NE.zero )
THEN
1094 IF( work( j ).GT.vcrit )
THEN
1096 CALL dscal( n-ki+1, rec, work(ki+(iv )*n),
1098 CALL dscal( n-ki+1, rec, work(ki+(iv+1)*n),
1104 work( j+(iv )*n ) = work( j+(iv)*n ) -
1105 $ ddot( j-ki-2, t( ki+2, j ),
1107 $ work( ki+2+(iv)*n ), 1 )
1108 work( j+(iv+1)*n ) = work( j+(iv+1)*n ) -
1109 $ ddot( j-ki-2, t( ki+2, j ),
1111 $ work( ki+2+(iv+1)*n ), 1 )
1115 CALL dlaln2( .false., 1, 2, smin, one, t( j,
1117 $ ldt, one, one, work( j+iv*n ), n, wr,
1118 $ -wi, x, 2, scale, xnorm, ierr )
1122 IF( scale.NE.one )
THEN
1123 CALL dscal( n-ki+1, scale, work(ki+(iv )*n),
1125 CALL dscal( n-ki+1, scale, work(ki+(iv+1)*n),
1128 work( j+(iv )*n ) = x( 1, 1 )
1129 work( j+(iv+1)*n ) = x( 1, 2 )
1130 vmax = max( abs( work( j+(iv )*n ) ),
1131 $ abs( work( j+(iv+1)*n ) ), vmax )
1132 vcrit = bignum / vmax
1141 beta = max( work( j ), work( j+1 ) )
1142 IF( beta.GT.vcrit )
THEN
1144 CALL dscal( n-ki+1, rec, work(ki+(iv )*n),
1146 CALL dscal( n-ki+1, rec, work(ki+(iv+1)*n),
1152 work( j +(iv )*n ) = work( j+(iv)*n ) -
1153 $ ddot( j-ki-2, t( ki+2, j ), 1,
1154 $ work( ki+2+(iv)*n ), 1 )
1156 work( j +(iv+1)*n ) = work( j+(iv+1)*n ) -
1157 $ ddot( j-ki-2, t( ki+2, j ), 1,
1158 $ work( ki+2+(iv+1)*n ), 1 )
1160 work( j+1+(iv )*n ) = work( j+1+(iv)*n ) -
1161 $ ddot( j-ki-2, t( ki+2, j+1 ),
1163 $ work( ki+2+(iv)*n ), 1 )
1165 work( j+1+(iv+1)*n ) = work( j+1+(iv+1)*n ) -
1166 $ ddot( j-ki-2, t( ki+2, j+1 ),
1168 $ work( ki+2+(iv+1)*n ), 1 )
1174 CALL dlaln2( .true., 2, 2, smin, one, t( j, j ),
1175 $ ldt, one, one, work( j+iv*n ), n, wr,
1176 $ -wi, x, 2, scale, xnorm, ierr )
1180 IF( scale.NE.one )
THEN
1181 CALL dscal( n-ki+1, scale, work(ki+(iv )*n),
1183 CALL dscal( n-ki+1, scale, work(ki+(iv+1)*n),
1186 work( j +(iv )*n ) = x( 1, 1 )
1187 work( j +(iv+1)*n ) = x( 1, 2 )
1188 work( j+1+(iv )*n ) = x( 2, 1 )
1189 work( j+1+(iv+1)*n ) = x( 2, 2 )
1190 vmax = max( abs( x( 1, 1 ) ), abs( x( 1, 2 ) ),
1191 $ abs( x( 2, 1 ) ), abs( x( 2, 2 ) ),
1193 vcrit = bignum / vmax
1200 IF( .NOT.over )
THEN
1203 CALL dcopy( n-ki+1, work( ki + (iv )*n ), 1,
1205 CALL dcopy( n-ki+1, work( ki + (iv+1)*n ), 1,
1206 $ vl( ki, is+1 ), 1 )
1210 emax = max( emax, abs( vl( k, is ) )+
1211 $ abs( vl( k, is+1 ) ) )
1214 CALL dscal( n-ki+1, remax, vl( ki, is ), 1 )
1215 CALL dscal( n-ki+1, remax, vl( ki, is+1 ), 1 )
1217 DO 230 k = 1, ki - 1
1219 vl( k, is+1 ) = zero
1222 ELSE IF( nb.EQ.1 )
THEN
1225 IF( ki.LT.n-1 )
THEN
1226 CALL dgemv(
'N', n, n-ki-1, one,
1227 $ vl( 1, ki+2 ), ldvl,
1228 $ work( ki+2 + (iv)*n ), 1,
1229 $ work( ki + (iv)*n ),
1231 CALL dgemv(
'N', n, n-ki-1, one,
1232 $ vl( 1, ki+2 ), ldvl,
1233 $ work( ki+2 + (iv+1)*n ), 1,
1234 $ work( ki+1 + (iv+1)*n ),
1235 $ vl( 1, ki+1 ), 1 )
1237 CALL dscal( n, work(ki+ (iv )*n), vl(1, ki ),
1239 CALL dscal( n, work(ki+1+(iv+1)*n), vl(1, ki+1),
1245 emax = max( emax, abs( vl( k, ki ) )+
1246 $ abs( vl( k, ki+1 ) ) )
1249 CALL dscal( n, remax, vl( 1, ki ), 1 )
1250 CALL dscal( n, remax, vl( 1, ki+1 ), 1 )
1258 work( k + (iv )*n ) = zero
1259 work( k + (iv+1)*n ) = zero
1261 iscomplex( iv ) = ip
1262 iscomplex( iv+1 ) = -ip
1281 IF( (iv.GE.nb-1) .OR. (ki2.EQ.n) )
THEN
1282 CALL dgemm(
'N',
'N', n, iv, n-ki2+iv, one,
1283 $ vl( 1, ki2-iv+1 ), ldvl,
1284 $ work( ki2-iv+1 + (1)*n ), n,
1286 $ work( 1 + (nb+1)*n ), n )
1289 IF( iscomplex(k).EQ.0)
THEN
1291 ii = idamax( n, work( 1 + (nb+k)*n ), 1 )
1292 remax = one / abs( work( ii + (nb+k)*n ) )
1293 ELSE IF( iscomplex(k).EQ.1)
THEN
1298 $ abs( work( ii + (nb+k )*n ) )+
1299 $ abs( work( ii + (nb+k+1)*n ) ) )
1306 CALL dscal( n, remax, work( 1 + (nb+k)*n ), 1 )
1309 $ work( 1 + (nb+1)*n ), n,
1310 $ vl( 1, ki2-iv+1 ), ldvl )