217 SUBROUTINE stgex2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z,
218 $ LDZ, J1, N1, N2, WORK, LWORK, INFO )
226 INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2
229 REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
230 $ work( * ), z( ldz, * )
239 parameter( zero = 0.0e+0, one = 1.0e+0 )
241 parameter( twenty = 2.0e+01 )
243 parameter( ldst = 4 )
245 parameter( wands = .true. )
249 INTEGER I, IDUM, LINFO, M
250 REAL BQRA21, BRQA21, DDUM, DNORMA, DNORMB,
252 $ dsum, eps, f, g, sa, sb, scale, smlnum,
256 INTEGER IWORK( LDST + 2 )
257 REAL AI( 2 ), AR( 2 ), BE( 2 ), IR( LDST, LDST ),
258 $ ircop( ldst, ldst ), li( ldst, ldst ),
259 $ licop( ldst, ldst ), s( ldst, ldst ),
260 $ scpy( ldst, ldst ), t( ldst, ldst ),
261 $ taul( ldst ), taur( ldst ), tcpy( ldst, ldst )
274 INTRINSIC abs, max, sqrt
282 IF( n.LE.1 .OR. n1.LE.0 .OR. n2.LE.0 )
284 IF( n1.GT.n .OR. ( j1+n1 ).GT.n )
287 IF( lwork.LT.max( n*m, m*m*2 ) )
THEN
289 work( 1 ) = real( max( n*m, m*m*2 ) )
298 CALL slaset(
'Full', ldst, ldst, zero, zero, li, ldst )
299 CALL slaset(
'Full', ldst, ldst, zero, zero, ir, ldst )
300 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda, s, ldst )
301 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb, t, ldst )
306 smlnum = slamch(
'S' ) / eps
309 CALL slacpy(
'Full', m, m, s, ldst, work, m )
310 CALL slassq( m*m, work, 1, dscale, dsum )
311 dnorma = dscale*sqrt( dsum )
314 CALL slacpy(
'Full', m, m, t, ldst, work, m )
315 CALL slassq( m*m, work, 1, dscale, dsum )
316 dnormb = dscale*sqrt( dsum )
326 thresha = max( twenty*eps*dnorma, smlnum )
327 threshb = max( twenty*eps*dnormb, smlnum )
336 f = s( 2, 2 )*t( 1, 1 ) - t( 2, 2 )*s( 1, 1 )
337 g = s( 2, 2 )*t( 1, 2 ) - t( 2, 2 )*s( 1, 2 )
338 sa = abs( s( 2, 2 ) ) * abs( t( 1, 1 ) )
339 sb = abs( s( 1, 1 ) ) * abs( t( 2, 2 ) )
340 CALL slartg( f, g, ir( 1, 2 ), ir( 1, 1 ), ddum )
341 ir( 2, 1 ) = -ir( 1, 2 )
342 ir( 2, 2 ) = ir( 1, 1 )
343 CALL srot( 2, s( 1, 1 ), 1, s( 1, 2 ), 1, ir( 1, 1 ),
345 CALL srot( 2, t( 1, 1 ), 1, t( 1, 2 ), 1, ir( 1, 1 ),
348 CALL slartg( s( 1, 1 ), s( 2, 1 ), li( 1, 1 ), li( 2,
352 CALL slartg( t( 1, 1 ), t( 2, 1 ), li( 1, 1 ), li( 2,
356 CALL srot( 2, s( 1, 1 ), ldst, s( 2, 1 ), ldst, li( 1, 1 ),
358 CALL srot( 2, t( 1, 1 ), ldst, t( 2, 1 ), ldst, li( 1, 1 ),
360 li( 2, 2 ) = li( 1, 1 )
361 li( 1, 2 ) = -li( 2, 1 )
366 weak = abs( s( 2, 1 ) ) .LE. thresha .AND.
367 $ abs( t( 2, 1 ) ) .LE. threshb
378 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda,
381 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, s, ldst,
384 CALL sgemm(
'N',
'T', m, m, m, -one, work, m, ir, ldst,
389 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
390 sa = dscale*sqrt( dsum )
392 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb,
395 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, t, ldst,
398 CALL sgemm(
'N',
'T', m, m, m, -one, work, m, ir, ldst,
403 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
404 sb = dscale*sqrt( dsum )
405 strong = sa.LE.thresha .AND. sb.LE.threshb
413 CALL srot( j1+1, a( 1, j1 ), 1, a( 1, j1+1 ), 1, ir( 1, 1 ),
415 CALL srot( j1+1, b( 1, j1 ), 1, b( 1, j1+1 ), 1, ir( 1, 1 ),
417 CALL srot( n-j1+1, a( j1, j1 ), lda, a( j1+1, j1 ), lda,
418 $ li( 1, 1 ), li( 2, 1 ) )
419 CALL srot( n-j1+1, b( j1, j1 ), ldb, b( j1+1, j1 ), ldb,
420 $ li( 1, 1 ), li( 2, 1 ) )
430 $
CALL srot( n, z( 1, j1 ), 1, z( 1, j1+1 ), 1, ir( 1, 1 ),
433 $
CALL srot( n, q( 1, j1 ), 1, q( 1, j1+1 ), 1, li( 1, 1 ),
450 CALL slacpy(
'Full', n1, n2, t( 1, n1+1 ), ldst, li, ldst )
451 CALL slacpy(
'Full', n1, n2, s( 1, n1+1 ), ldst,
452 $ ir( n2+1, n1+1 ), ldst )
453 CALL stgsy2(
'N', 0, n1, n2, s, ldst, s( n1+1, n1+1 ), ldst,
454 $ ir( n2+1, n1+1 ), ldst, t, ldst, t( n1+1, n1+1 ),
455 $ ldst, li, ldst, scale, dsum, dscale, iwork, idum,
469 CALL sscal( n1, -one, li( 1, i ), 1 )
470 li( n1+i, i ) = scale
472 CALL sgeqr2( m, n2, li, ldst, taul, work, linfo )
475 CALL sorg2r( m, m, n2, li, ldst, taul, work, linfo )
486 ir( n2+i, i ) = scale
488 CALL sgerq2( n1, m, ir( n2+1, 1 ), ldst, taur, work, linfo )
491 CALL sorgr2( m, m, n1, ir, ldst, taur, work, linfo )
497 CALL sgemm(
'T',
'N', m, m, m, one, li, ldst, s, ldst, zero,
499 CALL sgemm(
'N',
'T', m, m, m, one, work, m, ir, ldst, zero,
502 CALL sgemm(
'T',
'N', m, m, m, one, li, ldst, t, ldst, zero,
504 CALL sgemm(
'N',
'T', m, m, m, one, work, m, ir, ldst, zero,
507 CALL slacpy(
'F', m, m, s, ldst, scpy, ldst )
508 CALL slacpy(
'F', m, m, t, ldst, tcpy, ldst )
509 CALL slacpy(
'F', m, m, ir, ldst, ircop, ldst )
510 CALL slacpy(
'F', m, m, li, ldst, licop, ldst )
515 CALL sgerq2( m, m, t, ldst, taur, work, linfo )
518 CALL sormr2(
'R',
'T', m, m, m, t, ldst, taur, s, ldst,
523 CALL sormr2(
'L',
'N', m, m, m, t, ldst, taur, ir, ldst,
534 CALL slassq( n1, s( n2+1, i ), 1, dscale, dsum )
536 brqa21 = dscale*sqrt( dsum )
541 CALL sgeqr2( m, m, tcpy, ldst, taul, work, linfo )
544 CALL sorm2r(
'L',
'T', m, m, m, tcpy, ldst, taul, scpy,
547 CALL sorm2r(
'R',
'N', m, m, m, tcpy, ldst, taul, licop,
558 CALL slassq( n1, scpy( n2+1, i ), 1, dscale, dsum )
560 bqra21 = dscale*sqrt( dsum )
566 IF( bqra21.LE.brqa21 .AND. bqra21.LE.thresha )
THEN
567 CALL slacpy(
'F', m, m, scpy, ldst, s, ldst )
568 CALL slacpy(
'F', m, m, tcpy, ldst, t, ldst )
569 CALL slacpy(
'F', m, m, ircop, ldst, ir, ldst )
570 CALL slacpy(
'F', m, m, licop, ldst, li, ldst )
571 ELSE IF( brqa21.GE.thresha )
THEN
577 CALL slaset(
'Lower', m-1, m-1, zero, zero, t(2,1), ldst )
586 CALL slacpy(
'Full', m, m, a( j1, j1 ), lda,
589 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, s, ldst,
592 CALL sgemm(
'N',
'N', m, m, m, -one, work, m, ir, ldst,
597 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
598 sa = dscale*sqrt( dsum )
600 CALL slacpy(
'Full', m, m, b( j1, j1 ), ldb,
603 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, t, ldst,
606 CALL sgemm(
'N',
'N', m, m, m, -one, work, m, ir, ldst,
611 CALL slassq( m*m, work( m*m+1 ), 1, dscale, dsum )
612 sb = dscale*sqrt( dsum )
613 strong = sa.LE.thresha .AND. sb.LE.threshb
622 CALL slaset(
'Full', n1, n2, zero, zero, s(n2+1,1), ldst )
626 CALL slacpy(
'F', m, m, s, ldst, a( j1, j1 ), lda )
627 CALL slacpy(
'F', m, m, t, ldst, b( j1, j1 ), ldb )
628 CALL slaset(
'Full', ldst, ldst, zero, zero, t, ldst )
632 CALL slaset(
'Full', m, m, zero, zero, work, m )
635 idum = lwork - m*m - 2
637 CALL slagv2( a( j1, j1 ), lda, b( j1, j1 ), ldb, ar, ai,
639 $ work( 1 ), work( 2 ), t( 1, 1 ), t( 2, 1 ) )
640 work( m+1 ) = -work( 2 )
641 work( m+2 ) = work( 1 )
642 t( n2, n2 ) = t( 1, 1 )
643 t( 1, 2 ) = -t( 2, 1 )
649 CALL slagv2( a( j1+n2, j1+n2 ), lda, b( j1+n2, j1+n2 ),
651 $ taur, taul, work( m*m+1 ), work( n2*m+n2+1 ),
652 $ work( n2*m+n2+2 ), t( n2+1, n2+1 ),
654 work( m*m ) = work( n2*m+n2+1 )
655 work( m*m-1 ) = -work( n2*m+n2+2 )
656 t( m, m ) = t( n2+1, n2+1 )
657 t( m-1, m ) = -t( m, m-1 )
659 CALL sgemm(
'T',
'N', n2, n1, n2, one, work, m, a( j1,
661 $ lda, zero, work( m*m+1 ), n2 )
662 CALL slacpy(
'Full', n2, n1, work( m*m+1 ), n2, a( j1,
665 CALL sgemm(
'T',
'N', n2, n1, n2, one, work, m, b( j1,
667 $ ldb, zero, work( m*m+1 ), n2 )
668 CALL slacpy(
'Full', n2, n1, work( m*m+1 ), n2, b( j1,
671 CALL sgemm(
'N',
'N', m, m, m, one, li, ldst, work, m, zero,
673 CALL slacpy(
'Full', m, m, work( m*m+1 ), m, li, ldst )
674 CALL sgemm(
'N',
'N', n2, n1, n1, one, a( j1, j1+n2 ), lda,
675 $ t( n2+1, n2+1 ), ldst, zero, work, n2 )
676 CALL slacpy(
'Full', n2, n1, work, n2, a( j1, j1+n2 ), lda )
677 CALL sgemm(
'N',
'N', n2, n1, n1, one, b( j1, j1+n2 ), ldb,
678 $ t( n2+1, n2+1 ), ldst, zero, work, n2 )
679 CALL slacpy(
'Full', n2, n1, work, n2, b( j1, j1+n2 ), ldb )
680 CALL sgemm(
'T',
'N', m, m, m, one, ir, ldst, t, ldst, zero,
682 CALL slacpy(
'Full', m, m, work, m, ir, ldst )
687 CALL sgemm(
'N',
'N', n, m, m, one, q( 1, j1 ), ldq, li,
688 $ ldst, zero, work, n )
689 CALL slacpy(
'Full', n, m, work, n, q( 1, j1 ), ldq )
694 CALL sgemm(
'N',
'N', n, m, m, one, z( 1, j1 ), ldz, ir,
695 $ ldst, zero, work, n )
696 CALL slacpy(
'Full', n, m, work, n, z( 1, j1 ), ldz )
705 CALL sgemm(
'T',
'N', m, n-i+1, m, one, li, ldst,
706 $ a( j1, i ), lda, zero, work, m )
707 CALL slacpy(
'Full', m, n-i+1, work, m, a( j1, i ), lda )
708 CALL sgemm(
'T',
'N', m, n-i+1, m, one, li, ldst,
709 $ b( j1, i ), ldb, zero, work, m )
710 CALL slacpy(
'Full', m, n-i+1, work, m, b( j1, i ), ldb )
714 CALL sgemm(
'N',
'N', i, m, m, one, a( 1, j1 ), lda, ir,
715 $ ldst, zero, work, i )
716 CALL slacpy(
'Full', i, m, work, i, a( 1, j1 ), lda )
717 CALL sgemm(
'N',
'N', i, m, m, one, b( 1, j1 ), ldb, ir,
718 $ ldst, zero, work, i )
719 CALL slacpy(
'Full', i, m, work, i, b( 1, j1 ), ldb )