373 SUBROUTINE stgsja( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B,
374 $ LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV,
375 $ Q, LDQ, WORK, NCYCLE, INFO )
382 CHARACTER JOBQ, JOBU, JOBV
383 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
388 REAL A( LDA, * ), ALPHA( * ), B( LDB, * ),
389 $ BETA( * ), Q( LDQ, * ), U( LDU, * ),
390 $ v( ldv, * ), work( * )
397 PARAMETER ( MAXIT = 40 )
398 REAL ZERO, ONE, HUGENUM
399 parameter( zero = 0.0e+0, one = 1.0e+0 )
403 LOGICAL INITQ, INITU, INITV, UPPER, WANTQ, WANTU, WANTV
405 REAL A1, A2, A3, B1, B2, B3, CSQ, CSU, CSV, ERROR,
406 $ gamma, rwk, snq, snu, snv, ssmin
418 INTRINSIC abs, max, min, huge
419 parameter( hugenum = huge(zero) )
425 initu = lsame( jobu,
'I' )
426 wantu = initu .OR. lsame( jobu,
'U' )
428 initv = lsame( jobv,
'I' )
429 wantv = initv .OR. lsame( jobv,
'V' )
431 initq = lsame( jobq,
'I' )
432 wantq = initq .OR. lsame( jobq,
'Q' )
435 IF( .NOT.( initu .OR. wantu .OR. lsame( jobu,
'N' ) ) )
THEN
437 ELSE IF( .NOT.( initv .OR.
439 $ lsame( jobv,
'N' ) ) )
THEN
441 ELSE IF( .NOT.( initq .OR.
443 $ lsame( jobq,
'N' ) ) )
THEN
445 ELSE IF( m.LT.0 )
THEN
447 ELSE IF( p.LT.0 )
THEN
449 ELSE IF( n.LT.0 )
THEN
451 ELSE IF( lda.LT.max( 1, m ) )
THEN
453 ELSE IF( ldb.LT.max( 1, p ) )
THEN
455 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) )
THEN
457 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) )
THEN
459 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) )
THEN
463 CALL xerbla(
'STGSJA', -info )
470 $
CALL slaset(
'Full', m, m, zero, one, u, ldu )
472 $
CALL slaset(
'Full', p, p, zero, one, v, ldv )
474 $
CALL slaset(
'Full', n, n, zero, one, q, ldq )
479 DO 40 kcycle = 1, maxit
490 $ a1 = a( k+i, n-l+i )
492 $ a3 = a( k+j, n-l+j )
499 $ a2 = a( k+i, n-l+j )
503 $ a2 = a( k+j, n-l+i )
507 CALL slags2( upper, a1, a2, a3, b1, b2, b3, csu, snu,
508 $ csv, snv, csq, snq )
513 $
CALL srot( l, a( k+j, n-l+1 ), lda, a( k+i,
519 CALL srot( l, b( j, n-l+1 ), ldb, b( i, n-l+1 ), ldb,
525 CALL srot( min( k+l, m ), a( 1, n-l+j ), 1,
526 $ a( 1, n-l+i ), 1, csq, snq )
528 CALL srot( l, b( 1, n-l+j ), 1, b( 1, n-l+i ), 1, csq,
533 $ a( k+i, n-l+j ) = zero
537 $ a( k+j, n-l+i ) = zero
543 IF( wantu .AND. k+j.LE.m )
544 $
CALL srot( m, u( 1, k+j ), 1, u( 1, k+i ), 1, csu,
548 $
CALL srot( p, v( 1, j ), 1, v( 1, i ), 1, csv,
552 $
CALL srot( n, q( 1, n-l+j ), 1, q( 1, n-l+i ), 1,
559 IF( .NOT.upper )
THEN
568 DO 30 i = 1, min( l, m-k )
569 CALL scopy( l-i+1, a( k+i, n-l+i ), lda, work, 1 )
570 CALL scopy( l-i+1, b( i, n-l+i ), ldb, work( l+1 ),
572 CALL slapll( l-i+1, work, 1, work( l+1 ), 1, ssmin )
573 error = max( error, ssmin )
576 IF( abs( error ).LE.min( tola, tolb ) )
600 DO 70 i = 1, min( l, m-k )
606 IF( (gamma.LE.hugenum).AND.(gamma.GE.-hugenum) )
THEN
610 IF( gamma.LT.zero )
THEN
611 CALL sscal( l-i+1, -one, b( i, n-l+i ), ldb )
613 $
CALL sscal( p, -one, v( 1, i ), 1 )
616 CALL slartg( abs( gamma ), one, beta( k+i ),
620 IF( alpha( k+i ).GE.beta( k+i ) )
THEN
621 CALL sscal( l-i+1, one / alpha( k+i ), a( k+i,
625 CALL sscal( l-i+1, one / beta( k+i ), b( i, n-l+i ),
627 CALL scopy( l-i+1, b( i, n-l+i ), ldb, a( k+i,
636 CALL scopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
645 DO 80 i = m + 1, k + l
651 DO 90 i = k + l + 1, n