175 SUBROUTINE dggbal( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
176 $ RSCALE, WORK, INFO )
184 INTEGER IHI, ILO, INFO, LDA, LDB, N
187 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), LSCALE( * ),
188 $ rscale( * ), work( * )
194 DOUBLE PRECISION ZERO, HALF, ONE
195 parameter( zero = 0.0d+0, half = 0.5d+0, one = 1.0d+0 )
196 DOUBLE PRECISION THREE, SCLFAC
197 parameter( three = 3.0d+0, sclfac = 1.0d+1 )
200 INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
201 $ k, kount, l, lcab, lm1, lrab, lsfmax, lsfmin,
203 DOUBLE PRECISION ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
204 $ coef5, cor, ew, ewc, gamma, pgamma, rab, sfmax,
205 $ sfmin, sum, t, ta, tb, tc
210 DOUBLE PRECISION DDOT, DLAMCH
211 EXTERNAL lsame, idamax, ddot, dlamch
217 INTRINSIC abs, dble, int, log10, max, min, 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(
'DGGBAL', -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 dswap( n-k+1, a( i, k ), lda, a( m, k ), lda )
344 CALL dswap( n-k+1, b( i, k ), ldb, b( m, k ), ldb )
352 CALL dswap( l, a( 1, j ), 1, a( 1, m ), 1 )
353 CALL dswap( 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 / dble( 2*nr )
419 gamma = ddot( nr, work( ilo+4*n ), 1, work( ilo+4*n ), 1 ) +
420 $ ddot( 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 dscal( nr, beta, work( ilo ), 1 )
438 CALL dscal( nr, beta, work( ilo+n ), 1 )
440 CALL daxpy( nr, coef, work( ilo+4*n ), 1, work( ilo+n ), 1 )
441 CALL daxpy( 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 ) = dble( 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 ) = dble( kount )*work( j ) + sum
484 sum = ddot( nr, work( ilo+n ), 1, work( ilo+2*n ), 1 ) +
485 $ ddot( 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 daxpy( nr, -alpha, work( ilo+2*n ), 1, work( ilo+4*n ), 1 )
505 CALL daxpy( nr, -alpha, work( ilo+3*n ), 1, work( ilo+5*n ), 1 )
515 sfmin = dlamch(
'S' )
517 lsfmin = int( log10( sfmin ) / basl+one )
518 lsfmax = int( log10( sfmax ) / basl )
520 irab = idamax( n-ilo+1, a( i, ilo ), lda )
521 rab = abs( a( i, irab+ilo-1 ) )
522 irab = idamax( 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 = idamax( ihi, a( 1, i ), 1 )
529 cab = abs( a( icab, i ) )
530 icab = idamax( 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 dscal( n-ilo+1, lscale( i ), a( i, ilo ), lda )
542 CALL dscal( n-ilo+1, lscale( i ), b( i, ilo ), ldb )
548 CALL dscal( ihi, rscale( j ), a( 1, j ), 1 )
549 CALL dscal( ihi, rscale( j ), b( 1, j ), 1 )
subroutine xerbla(srname, info)
subroutine daxpy(n, da, dx, incx, dy, incy)
DAXPY
subroutine dggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)
DGGBAL
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine dswap(n, dx, incx, dy, incy)
DSWAP