173 SUBROUTINE zggbal( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
174 $ RSCALE, WORK, INFO )
182 INTEGER IHI, ILO, INFO, LDA, LDB, N
185 DOUBLE PRECISION LSCALE( * ), RSCALE( * ), WORK( * )
186 COMPLEX*16 A( LDA, * ), B( LDB, * )
192 DOUBLE PRECISION ZERO, HALF, ONE
193 parameter( zero = 0.0d+0, half = 0.5d+0, one = 1.0d+0 )
194 DOUBLE PRECISION THREE, SCLFAC
195 parameter( three = 3.0d+0, sclfac = 1.0d+1 )
197 parameter( czero = ( 0.0d+0, 0.0d+0 ) )
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
211 DOUBLE PRECISION DDOT, DLAMCH
212 EXTERNAL lsame, izamax, ddot, dlamch
218 INTRINSIC abs, dble, dimag, int, log10, max, min, sign
221 DOUBLE PRECISION CABS1
224 cabs1( cdum ) = abs( dble( cdum ) ) + abs( dimag( cdum ) )
231 IF( .NOT.lsame( job,
'N' ) .AND.
232 $ .NOT.lsame( job,
'P' ) .AND.
233 $ .NOT.lsame( job,
'S' ) .AND.
234 $ .NOT.lsame( job,
'B' ) )
THEN
236 ELSE IF( n.LT.0 )
THEN
238 ELSE IF( lda.LT.max( 1, n ) )
THEN
240 ELSE IF( ldb.LT.max( 1, n ) )
THEN
244 CALL xerbla(
'ZGGBAL', -info )
264 IF( lsame( job,
'N' ) )
THEN
276 IF( lsame( job,
'S' ) )
299 IF( a( i, j ).NE.czero .OR. b( i, j ).NE.czero )
307 IF( a( i, j ).NE.czero .OR. b( i, j ).NE.czero )
328 IF( a( i, j ).NE.czero .OR. b( i, j ).NE.czero )
335 IF( a( i, j ).NE.czero .OR. b( i, j ).NE.czero )
352 CALL zswap( n-k+1, a( i, k ), lda, a( m, k ), lda )
353 CALL zswap( n-k+1, b( i, k ), ldb, b( m, k ), ldb )
361 CALL zswap( l, a( 1, j ), 1, a( 1, m ), 1 )
362 CALL zswap( l, b( 1, j ), 1, b( 1, m ), 1 )
365 GO TO ( 20, 90 )iflow
371 IF( lsame( job,
'P' ) )
THEN
399 basl = log10( sclfac )
402 IF( a( i, j ).EQ.czero )
THEN
406 ta = log10( cabs1( a( i, j ) ) ) / basl
409 IF( b( i, j ).EQ.czero )
THEN
413 tb = log10( cabs1( b( i, j ) ) ) / basl
416 work( i+4*n ) = work( i+4*n ) - ta - tb
417 work( j+5*n ) = work( j+5*n ) - ta - tb
421 coef = one / dble( 2*nr )
432 gamma = ddot( nr, work( ilo+4*n ), 1, work( ilo+4*n ), 1 ) +
433 $ ddot( nr, work( ilo+5*n ), 1, work( ilo+5*n ), 1 )
438 ew = ew + work( i+4*n )
439 ewc = ewc + work( i+5*n )
442 gamma = coef*gamma - coef2*( ew**2+ewc**2 ) - coef5*( ew-ewc )**2
446 $ beta = gamma / pgamma
447 t = coef5*( ewc-three*ew )
448 tc = coef5*( ew-three*ewc )
450 CALL dscal( nr, beta, work( ilo ), 1 )
451 CALL dscal( nr, beta, work( ilo+n ), 1 )
453 CALL daxpy( nr, coef, work( ilo+4*n ), 1, work( ilo+n ), 1 )
454 CALL daxpy( nr, coef, work( ilo+5*n ), 1, work( ilo ), 1 )
457 work( i ) = work( i ) + tc
458 work( i+n ) = work( i+n ) + t
467 IF( a( i, j ).EQ.czero )
470 sum = sum + work( j )
472 IF( b( i, j ).EQ.czero )
475 sum = sum + work( j )
477 work( i+2*n ) = dble( kount )*work( i+n ) + sum
484 IF( a( i, j ).EQ.czero )
487 sum = sum + work( i+n )
489 IF( b( i, j ).EQ.czero )
492 sum = sum + work( i+n )
494 work( j+3*n ) = dble( kount )*work( j ) + sum
497 sum = ddot( nr, work( ilo+n ), 1, work( ilo+2*n ), 1 ) +
498 $ ddot( nr, work( ilo ), 1, work( ilo+3*n ), 1 )
505 cor = alpha*work( i+n )
506 IF( abs( cor ).GT.cmax )
508 lscale( i ) = lscale( i ) + cor
509 cor = alpha*work( i )
510 IF( abs( cor ).GT.cmax )
512 rscale( i ) = rscale( i ) + cor
517 CALL daxpy( nr, -alpha, work( ilo+2*n ), 1, work( ilo+4*n ),
519 CALL daxpy( nr, -alpha, work( ilo+3*n ), 1, work( ilo+5*n ),
530 sfmin = dlamch(
'S' )
532 lsfmin = int( log10( sfmin ) / basl+one )
533 lsfmax = int( log10( sfmax ) / basl )
535 irab = izamax( n-ilo+1, a( i, ilo ), lda )
536 rab = abs( a( i, irab+ilo-1 ) )
537 irab = izamax( n-ilo+1, b( i, ilo ), ldb )
538 rab = max( rab, abs( b( i, irab+ilo-1 ) ) )
539 lrab = int( log10( rab+sfmin ) / basl+one )
540 ir = int(lscale( i ) + sign( half, lscale( i ) ))
541 ir = min( max( ir, lsfmin ), lsfmax, lsfmax-lrab )
542 lscale( i ) = sclfac**ir
543 icab = izamax( ihi, a( 1, i ), 1 )
544 cab = abs( a( icab, i ) )
545 icab = izamax( ihi, b( 1, i ), 1 )
546 cab = max( cab, abs( b( icab, i ) ) )
547 lcab = int( log10( cab+sfmin ) / basl+one )
548 jc = int(rscale( i ) + sign( half, rscale( i ) ))
549 jc = min( max( jc, lsfmin ), lsfmax, lsfmax-lcab )
550 rscale( i ) = sclfac**jc
556 CALL zdscal( n-ilo+1, lscale( i ), a( i, ilo ), lda )
557 CALL zdscal( n-ilo+1, lscale( i ), b( i, ilo ), ldb )
563 CALL zdscal( ihi, rscale( j ), a( 1, j ), 1 )
564 CALL zdscal( ihi, rscale( j ), b( 1, j ), 1 )