175 SUBROUTINE cggbal( JOB, N, A, LDA, B, LDB, ILO, IHI, LSCALE,
176 $ RSCALE, WORK, INFO )
184 INTEGER IHI, ILO, INFO, LDA, LDB, N
187 REAL LSCALE( * ), RSCALE( * ), WORK( * )
188 COMPLEX A( LDA, * ), B( LDB, * )
195 parameter( zero = 0.0e+0, half = 0.5e+0, one = 1.0e+0 )
197 parameter( three = 3.0e+0, sclfac = 1.0e+1 )
199 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
202 INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,
203 $ k, kount, l, lcab, lm1, lrab, lsfmax, lsfmin,
205 REAL ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,
206 $ coef5, cor, ew, ewc, gamma, pgamma, rab, sfmax,
207 $ sfmin, sum, t, ta, tb, tc
214 EXTERNAL lsame, icamax, sdot, slamch
220 INTRINSIC abs, aimag, int, log10, max, min, real, sign
226 cabs1( cdum ) = abs( real( cdum ) ) + abs( aimag( cdum ) )
233 IF( .NOT.lsame( job,
'N' ) .AND. .NOT.lsame( job,
'P' ) .AND.
234 $ .NOT.lsame( job,
'S' ) .AND. .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(
'CGGBAL', -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 cswap( n-k+1, a( i, k ), lda, a( m, k ), lda )
353 CALL cswap( n-k+1, b( i, k ), ldb, b( m, k ), ldb )
361 CALL cswap( l, a( 1, j ), 1, a( 1, m ), 1 )
362 CALL cswap( 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 / real( 2*nr )
432 gamma = sdot( nr, work( ilo+4*n ), 1, work( ilo+4*n ), 1 ) +
433 $ sdot( 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 sscal( nr, beta, work( ilo ), 1 )
451 CALL sscal( nr, beta, work( ilo+n ), 1 )
453 CALL saxpy( nr, coef, work( ilo+4*n ), 1, work( ilo+n ), 1 )
454 CALL saxpy( 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 ) = real( 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 ) = real( kount )*work( j ) + sum
497 sum = sdot( nr, work( ilo+n ), 1, work( ilo+2*n ), 1 ) +
498 $ sdot( 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 saxpy( nr, -alpha, work( ilo+2*n ), 1, work( ilo+4*n ), 1 )
518 CALL saxpy( nr, -alpha, work( ilo+3*n ), 1, work( ilo+5*n ), 1 )
528 sfmin = slamch(
'S' )
530 lsfmin = int( log10( sfmin ) / basl+one )
531 lsfmax = int( log10( sfmax ) / basl )
533 irab = icamax( n-ilo+1, a( i, ilo ), lda )
534 rab = abs( a( i, irab+ilo-1 ) )
535 irab = icamax( n-ilo+1, b( i, ilo ), ldb )
536 rab = max( rab, abs( b( i, irab+ilo-1 ) ) )
537 lrab = int( log10( rab+sfmin ) / basl+one )
538 ir = int( lscale( i ) + sign( half, lscale( i ) ) )
539 ir = min( max( ir, lsfmin ), lsfmax, lsfmax-lrab )
540 lscale( i ) = sclfac**ir
541 icab = icamax( ihi, a( 1, i ), 1 )
542 cab = abs( a( icab, i ) )
543 icab = icamax( ihi, b( 1, i ), 1 )
544 cab = max( cab, abs( b( icab, i ) ) )
545 lcab = int( log10( cab+sfmin ) / basl+one )
546 jc = int( rscale( i ) + sign( half, rscale( i ) ) )
547 jc = min( max( jc, lsfmin ), lsfmax, lsfmax-lcab )
548 rscale( i ) = sclfac**jc
554 CALL csscal( n-ilo+1, lscale( i ), a( i, ilo ), lda )
555 CALL csscal( n-ilo+1, lscale( i ), b( i, ilo ), ldb )
561 CALL csscal( ihi, rscale( j ), a( 1, j ), 1 )
562 CALL csscal( ihi, rscale( j ), b( 1, j ), 1 )
subroutine xerbla(srname, info)
subroutine saxpy(n, sa, sx, incx, sy, incy)
SAXPY
subroutine cggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, info)
CGGBAL
subroutine csscal(n, sa, cx, incx)
CSSCAL
subroutine sscal(n, sa, sx, incx)
SSCAL
subroutine cswap(n, cx, incx, cy, incy)
CSWAP