240 SUBROUTINE ctrevc3( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL,
242 $ LDVR, MM, M, WORK, LWORK, RWORK, LRWORK, INFO)
250 CHARACTER HOWMNY, SIDE
251 INTEGER INFO, LDT, LDVL, LDVR, LWORK, LRWORK, M, MM, N
256 COMPLEX T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
264 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0 )
266 parameter( czero = ( 0.0e+0, 0.0e+0 ),
267 $ cone = ( 1.0e+0, 0.0e+0 ) )
269 PARAMETER ( NBMIN = 8, nbmax = 128 )
272 LOGICAL ALLV, BOTHV, LEFTV, LQUERY, OVER, RIGHTV, SOMEV
273 INTEGER I, II, IS, J, K, KI, IV, MAXWRK, NB
274 REAL OVFL, REMAX, SCALE, SMIN, SMLNUM, ULP, UNFL
279 INTEGER ILAENV, ICAMAX
280 REAL SLAMCH, SCASUM, SROUNDUP_LWORK
281 EXTERNAL lsame, ilaenv, icamax, slamch, scasum,
290 INTRINSIC abs, real, cmplx, conjg, aimag, max
296 cabs1( cdum ) = abs( real( cdum ) ) + abs( aimag( cdum ) )
302 bothv = lsame( side,
'B' )
303 rightv = lsame( side,
'R' ) .OR. bothv
304 leftv = lsame( side,
'L' ) .OR. bothv
306 allv = lsame( howmny,
'A' )
307 over = lsame( howmny,
'B' )
308 somev = lsame( howmny,
'S' )
324 nb = ilaenv( 1,
'CTREVC', side // howmny, n, -1, -1, -1 )
325 maxwrk = max( 1, n + 2*n*nb )
326 work(1) = sroundup_lwork(maxwrk)
327 rwork(1) = real( max( 1, n ) )
328 lquery = ( lwork.EQ.-1 .OR. lrwork.EQ.-1 )
329 IF( .NOT.rightv .AND. .NOT.leftv )
THEN
331 ELSE IF( .NOT.allv .AND. .NOT.over .AND. .NOT.somev )
THEN
333 ELSE IF( n.LT.0 )
THEN
335 ELSE IF( ldt.LT.max( 1, n ) )
THEN
337 ELSE IF( ldvl.LT.1 .OR. ( leftv .AND. ldvl.LT.n ) )
THEN
339 ELSE IF( ldvr.LT.1 .OR. ( rightv .AND. ldvr.LT.n ) )
THEN
341 ELSE IF( mm.LT.m )
THEN
343 ELSE IF( lwork.LT.max( 1, 2*n ) .AND. .NOT.lquery )
THEN
345 ELSE IF ( lrwork.LT.max( 1, n ) .AND. .NOT.lquery )
THEN
349 CALL xerbla(
'CTREVC3', -info )
351 ELSE IF( lquery )
THEN
363 IF( over .AND. lwork .GE. n + 2*n*nbmin )
THEN
364 nb = (lwork - n) / (2*n)
365 nb = min( nb, nbmax )
366 CALL claset(
'F', n, 1+2*nb, czero, czero, work, n )
373 unfl = slamch(
'Safe minimum' )
375 ulp = slamch(
'Precision' )
376 smlnum = unfl*( real( n ) / ulp )
381 work( i ) = t( i, i )
389 rwork( j ) = scasum( j-1, t( 1, j ), 1 )
405 IF( .NOT.
SELECT( ki ) )
408 smin = max( ulp*( cabs1( t( ki, ki ) ) ), smlnum )
413 work( ki + iv*n ) = cone
418 work( k + iv*n ) = -t( k, ki )
425 t( k, k ) = t( k, k ) - t( ki, ki )
426 IF( cabs1( t( k, k ) ).LT.smin )
431 CALL clatrs(
'Upper',
'No transpose',
'Non-unit',
'Y',
432 $ ki-1, t, ldt, work( 1 + iv*n ), scale,
434 work( ki + iv*n ) = scale
442 CALL ccopy( ki, work( 1 + iv*n ), 1, vr( 1, is ), 1 )
444 ii = icamax( ki, vr( 1, is ), 1 )
445 remax = one / cabs1( vr( ii, is ) )
446 CALL csscal( ki, remax, vr( 1, is ), 1 )
452 ELSE IF( nb.EQ.1 )
THEN
456 $
CALL cgemv(
'N', n, ki-1, cone, vr, ldvr,
457 $ work( 1 + iv*n ), 1, cmplx( scale ),
460 ii = icamax( n, vr( 1, ki ), 1 )
461 remax = one / cabs1( vr( ii, ki ) )
462 CALL csscal( n, remax, vr( 1, ki ), 1 )
469 work( k + iv*n ) = czero
475 IF( (iv.EQ.1) .OR. (ki.EQ.1) )
THEN
476 CALL cgemm(
'N',
'N', n, nb-iv+1, ki+nb-iv, cone,
478 $ work( 1 + (iv)*n ), n,
480 $ work( 1 + (nb+iv)*n ), n )
483 ii = icamax( n, work( 1 + (nb+k)*n ), 1 )
484 remax = one / cabs1( work( ii + (nb+k)*n ) )
485 CALL csscal( n, remax, work( 1 + (nb+k)*n ), 1 )
487 CALL clacpy(
'F', n, nb-iv+1,
488 $ work( 1 + (nb+iv)*n ), n,
489 $ vr( 1, ki ), ldvr )
499 t( k, k ) = work( k )
520 IF( .NOT.
SELECT( ki ) )
523 smin = max( ulp*( cabs1( t( ki, ki ) ) ), smlnum )
528 work( ki + iv*n ) = cone
533 work( k + iv*n ) = -conjg( t( ki, k ) )
540 t( k, k ) = t( k, k ) - t( ki, ki )
541 IF( cabs1( t( k, k ) ).LT.smin )
546 CALL clatrs(
'Upper',
'Conjugate transpose',
548 $
'Y', n-ki, t( ki+1, ki+1 ), ldt,
549 $ work( ki+1 + iv*n ), scale, rwork, info )
550 work( ki + iv*n ) = scale
558 CALL ccopy( n-ki+1, work( ki + iv*n ), 1, vl(ki,is),
561 ii = icamax( n-ki+1, vl( ki, is ), 1 ) + ki - 1
562 remax = one / cabs1( vl( ii, is ) )
563 CALL csscal( n-ki+1, remax, vl( ki, is ), 1 )
569 ELSE IF( nb.EQ.1 )
THEN
573 $
CALL cgemv(
'N', n, n-ki, cone, vl( 1, ki+1 ),
575 $ work( ki+1 + iv*n ), 1, cmplx( scale ),
578 ii = icamax( n, vl( 1, ki ), 1 )
579 remax = one / cabs1( vl( ii, ki ) )
580 CALL csscal( n, remax, vl( 1, ki ), 1 )
588 work( k + iv*n ) = czero
594 IF( (iv.EQ.nb) .OR. (ki.EQ.n) )
THEN
595 CALL cgemm(
'N',
'N', n, iv, n-ki+iv, cone,
596 $ vl( 1, ki-iv+1 ), ldvl,
597 $ work( ki-iv+1 + (1)*n ), n,
599 $ work( 1 + (nb+1)*n ), n )
602 ii = icamax( n, work( 1 + (nb+k)*n ), 1 )
603 remax = one / cabs1( work( ii + (nb+k)*n ) )
604 CALL csscal( n, remax, work( 1 + (nb+k)*n ), 1 )
607 $ work( 1 + (nb+1)*n ), n,
608 $ vl( 1, ki-iv+1 ), ldvl )
618 t( k, k ) = work( k )