175 SUBROUTINE sggbal( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
176 $ RSCALE, WORK, INFO )
184 INTEGER IHI, ILO, INFO, LDA, LDB, N
187 REAL A( LDA, * ), B( LDB, * ), LSCALE( * ),
188 $ rscale( * ), work( * )
195 parameter( zero = 0.0e+0, half = 0.5e+0, one = 1.0e+0 )
197 parameter( three = 3.0e+0, sclfac = 1.0e+1 )
200 INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
201 $ k, kount, l, lcab, lm1, lrab, lsfmax, lsfmin,
203 REAL ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
204 $ coef5, cor, ew, ewc, gamma, pgamma, rab, sfmax,
205 $ sfmin, sum, t, ta, tb, tc
211 EXTERNAL lsame, isamax, sdot, slamch
217 INTRINSIC abs, int, log10, max, min, real, sign
224 IF( .NOT.lsame( job,
'N' ) .AND. .NOT.lsame( job,
'P' ) .AND.
225 $ .NOT.lsame( job,
'S' ) .AND. .NOT.lsame( job,
'B' ) )
THEN
227 ELSE IF( n.LT.0 )
THEN
229 ELSE IF( lda.LT.max( 1, n ) )
THEN
231 ELSE IF( ldb.LT.max( 1, n ) )
THEN
235 CALL xerbla(
'SGGBAL', -info )
255 IF( lsame( job,
'N' ) )
THEN
267 IF( lsame( job,
'S' ) )
290 IF( a( i, j ).NE.zero .OR. b( i, j ).NE.zero )
298 IF( a( i, j ).NE.zero .OR. b( i, j ).NE.zero )
319 IF( a( i, j ).NE.zero .OR. b( i, j ).NE.zero )
326 IF( a( i, j ).NE.zero .OR. b( i, j ).NE.zero )
343 CALL sswap( n-k+1, a( i, k ), lda, a( m, k ), lda )
344 CALL sswap( n-k+1, b( i, k ), ldb, b( m, k ), ldb )
352 CALL sswap( l, a( 1, j ), 1, a( 1, m ), 1 )
353 CALL sswap( l, b( 1, j ), 1, b( 1, m ), 1 )
356 GO TO ( 20, 90 )iflow
362 IF( lsame( job,
'P' ) )
THEN
390 basl = log10( sclfac )
397 ta = log10( abs( ta ) ) / basl
401 tb = log10( abs( tb ) ) / basl
403 work( i+4*n ) = work( i+4*n ) - ta - tb
404 work( j+5*n ) = work( j+5*n ) - ta - tb
408 coef = one / real( 2*nr )
419 gamma = sdot( nr, work( ilo+4*n ), 1, work( ilo+4*n ), 1 ) +
420 $ sdot( nr, work( ilo+5*n ), 1, work( ilo+5*n ), 1 )
425 ew = ew + work( i+4*n )
426 ewc = ewc + work( i+5*n )
429 gamma = coef*gamma - coef2*( ew**2+ewc**2 ) - coef5*( ew-ewc )**2
433 $ beta = gamma / pgamma
434 t = coef5*( ewc-three*ew )
435 tc = coef5*( ew-three*ewc )
437 CALL sscal( nr, beta, work( ilo ), 1 )
438 CALL sscal( nr, beta, work( ilo+n ), 1 )
440 CALL saxpy( nr, coef, work( ilo+4*n ), 1, work( ilo+n ), 1 )
441 CALL saxpy( nr, coef, work( ilo+5*n ), 1, work( ilo ), 1 )
444 work( i ) = work( i ) + tc
445 work( i+n ) = work( i+n ) + t
454 IF( a( i, j ).EQ.zero )
457 sum = sum + work( j )
459 IF( b( i, j ).EQ.zero )
462 sum = sum + work( j )
464 work( i+2*n ) = real( kount )*work( i+n ) + sum
471 IF( a( i, j ).EQ.zero )
474 sum = sum + work( i+n )
476 IF( b( i, j ).EQ.zero )
479 sum = sum + work( i+n )
481 work( j+3*n ) = real( kount )*work( j ) + sum
484 sum = sdot( nr, work( ilo+n ), 1, work( ilo+2*n ), 1 ) +
485 $ sdot( nr, work( ilo ), 1, work( ilo+3*n ), 1 )
492 cor = alpha*work( i+n )
493 IF( abs( cor ).GT.cmax )
495 lscale( i ) = lscale( i ) + cor
496 cor = alpha*work( i )
497 IF( abs( cor ).GT.cmax )
499 rscale( i ) = rscale( i ) + cor
504 CALL saxpy( nr, -alpha, work( ilo+2*n ), 1, work( ilo+4*n ), 1 )
505 CALL saxpy( nr, -alpha, work( ilo+3*n ), 1, work( ilo+5*n ), 1 )
515 sfmin = slamch(
'S' )
517 lsfmin = int( log10( sfmin ) / basl+one )
518 lsfmax = int( log10( sfmax ) / basl )
520 irab = isamax( n-ilo+1, a( i, ilo ), lda )
521 rab = abs( a( i, irab+ilo-1 ) )
522 irab = isamax( n-ilo+1, b( i, ilo ), ldb )
523 rab = max( rab, abs( b( i, irab+ilo-1 ) ) )
524 lrab = int( log10( rab+sfmin ) / basl+one )
525 ir = int( lscale( i ) + sign( half, lscale( i ) ) )
526 ir = min( max( ir, lsfmin ), lsfmax, lsfmax-lrab )
527 lscale( i ) = sclfac**ir
528 icab = isamax( ihi, a( 1, i ), 1 )
529 cab = abs( a( icab, i ) )
530 icab = isamax( ihi, b( 1, i ), 1 )
531 cab = max( cab, abs( b( icab, i ) ) )
532 lcab = int( log10( cab+sfmin ) / basl+one )
533 jc = int( rscale( i ) + sign( half, rscale( i ) ) )
534 jc = min( max( jc, lsfmin ), lsfmax, lsfmax-lcab )
535 rscale( i ) = sclfac**jc
541 CALL sscal( n-ilo+1, lscale( i ), a( i, ilo ), lda )
542 CALL sscal( n-ilo+1, lscale( i ), b( i, ilo ), ldb )
548 CALL sscal( ihi, rscale( j ), a( 1, j ), 1 )
549 CALL sscal( ihi, rscale( j ), b( 1, j ), 1 )
subroutine xerbla(srname, info)
subroutine saxpy(n, sa, sx, incx, sy, incy)
SAXPY
subroutine sggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)
SGGBAL
subroutine sscal(n, sa, sx, incx)
SSCAL
subroutine sswap(n, sx, incx, sy, incy)
SSWAP