Annotation of rpl/lapack/lapack/zgebal.f, revision 1.21

1.9       bertrand    1: *> \brief \b ZGEBAL
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.17      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.9       bertrand    7: *
                      8: *> \htmlonly
1.17      bertrand    9: *> Download ZGEBAL + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgebal.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgebal.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgebal.f">
1.9       bertrand   15: *> [TXT]</a>
1.17      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
1.17      bertrand   22: *
1.9       bertrand   23: *       .. Scalar Arguments ..
                     24: *       CHARACTER          JOB
                     25: *       INTEGER            IHI, ILO, INFO, LDA, N
                     26: *       ..
                     27: *       .. Array Arguments ..
                     28: *       DOUBLE PRECISION   SCALE( * )
                     29: *       COMPLEX*16         A( LDA, * )
                     30: *       ..
1.17      bertrand   31: *
1.9       bertrand   32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *> ZGEBAL balances a general complex matrix A.  This involves, first,
                     39: *> permuting A by a similarity transformation to isolate eigenvalues
                     40: *> in the first 1 to ILO-1 and last IHI+1 to N elements on the
                     41: *> diagonal; and second, applying a diagonal similarity transformation
                     42: *> to rows and columns ILO to IHI to make the rows and columns as
                     43: *> close in norm as possible.  Both steps are optional.
                     44: *>
                     45: *> Balancing may reduce the 1-norm of the matrix, and improve the
                     46: *> accuracy of the computed eigenvalues and/or eigenvectors.
                     47: *> \endverbatim
                     48: *
                     49: *  Arguments:
                     50: *  ==========
                     51: *
                     52: *> \param[in] JOB
                     53: *> \verbatim
                     54: *>          JOB is CHARACTER*1
                     55: *>          Specifies the operations to be performed on A:
                     56: *>          = 'N':  none:  simply set ILO = 1, IHI = N, SCALE(I) = 1.0
                     57: *>                  for i = 1,...,N;
                     58: *>          = 'P':  permute only;
                     59: *>          = 'S':  scale only;
                     60: *>          = 'B':  both permute and scale.
                     61: *> \endverbatim
                     62: *>
                     63: *> \param[in] N
                     64: *> \verbatim
                     65: *>          N is INTEGER
                     66: *>          The order of the matrix A.  N >= 0.
                     67: *> \endverbatim
                     68: *>
                     69: *> \param[in,out] A
                     70: *> \verbatim
                     71: *>          A is COMPLEX*16 array, dimension (LDA,N)
                     72: *>          On entry, the input matrix A.
                     73: *>          On exit,  A is overwritten by the balanced matrix.
                     74: *>          If JOB = 'N', A is not referenced.
                     75: *>          See Further Details.
                     76: *> \endverbatim
                     77: *>
                     78: *> \param[in] LDA
                     79: *> \verbatim
                     80: *>          LDA is INTEGER
                     81: *>          The leading dimension of the array A.  LDA >= max(1,N).
                     82: *> \endverbatim
                     83: *>
                     84: *> \param[out] ILO
                     85: *> \verbatim
1.19      bertrand   86: *>          ILO is INTEGER
1.9       bertrand   87: *> \endverbatim
                     88: *>
                     89: *> \param[out] IHI
                     90: *> \verbatim
1.19      bertrand   91: *>          IHI is INTEGER
1.9       bertrand   92: *>          ILO and IHI are set to INTEGER such that on exit
                     93: *>          A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
                     94: *>          If JOB = 'N' or 'S', ILO = 1 and IHI = N.
                     95: *> \endverbatim
                     96: *>
                     97: *> \param[out] SCALE
                     98: *> \verbatim
                     99: *>          SCALE is DOUBLE PRECISION array, dimension (N)
                    100: *>          Details of the permutations and scaling factors applied to
                    101: *>          A.  If P(j) is the index of the row and column interchanged
                    102: *>          with row and column j and D(j) is the scaling factor
                    103: *>          applied to row and column j, then
                    104: *>          SCALE(j) = P(j)    for j = 1,...,ILO-1
                    105: *>                   = D(j)    for j = ILO,...,IHI
                    106: *>                   = P(j)    for j = IHI+1,...,N.
                    107: *>          The order in which the interchanges are made is N to IHI+1,
                    108: *>          then 1 to ILO-1.
                    109: *> \endverbatim
                    110: *>
                    111: *> \param[out] INFO
                    112: *> \verbatim
                    113: *>          INFO is INTEGER
                    114: *>          = 0:  successful exit.
                    115: *>          < 0:  if INFO = -i, the i-th argument had an illegal value.
                    116: *> \endverbatim
                    117: *
                    118: *  Authors:
                    119: *  ========
                    120: *
1.17      bertrand  121: *> \author Univ. of Tennessee
                    122: *> \author Univ. of California Berkeley
                    123: *> \author Univ. of Colorado Denver
                    124: *> \author NAG Ltd.
1.9       bertrand  125: *
                    126: *> \ingroup complex16GEcomputational
                    127: *
                    128: *> \par Further Details:
                    129: *  =====================
                    130: *>
                    131: *> \verbatim
                    132: *>
                    133: *>  The permutations consist of row and column interchanges which put
                    134: *>  the matrix in the form
                    135: *>
                    136: *>             ( T1   X   Y  )
                    137: *>     P A P = (  0   B   Z  )
                    138: *>             (  0   0   T2 )
                    139: *>
                    140: *>  where T1 and T2 are upper triangular matrices whose eigenvalues lie
                    141: *>  along the diagonal.  The column indices ILO and IHI mark the starting
                    142: *>  and ending columns of the submatrix B. Balancing consists of applying
                    143: *>  a diagonal similarity transformation inv(D) * B * D to make the
                    144: *>  1-norms of each row of B and its corresponding column nearly equal.
                    145: *>  The output matrix is
                    146: *>
                    147: *>     ( T1     X*D          Y    )
                    148: *>     (  0  inv(D)*B*D  inv(D)*Z ).
                    149: *>     (  0      0           T2   )
                    150: *>
                    151: *>  Information about the permutations P and the diagonal matrix D is
                    152: *>  returned in the vector SCALE.
                    153: *>
                    154: *>  This subroutine is based on the EISPACK routine CBAL.
                    155: *>
                    156: *>  Modified by Tzu-Yi Chen, Computer Science Division, University of
                    157: *>    California at Berkeley, USA
                    158: *> \endverbatim
                    159: *>
                    160: *  =====================================================================
1.1       bertrand  161:       SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
                    162: *
1.21    ! bertrand  163: *  -- LAPACK computational routine --
1.1       bertrand  164: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    165: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    166: *
                    167: *     .. Scalar Arguments ..
                    168:       CHARACTER          JOB
                    169:       INTEGER            IHI, ILO, INFO, LDA, N
                    170: *     ..
                    171: *     .. Array Arguments ..
                    172:       DOUBLE PRECISION   SCALE( * )
                    173:       COMPLEX*16         A( LDA, * )
                    174: *     ..
                    175: *
                    176: *  =====================================================================
                    177: *
                    178: *     .. Parameters ..
                    179:       DOUBLE PRECISION   ZERO, ONE
                    180:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
                    181:       DOUBLE PRECISION   SCLFAC
                    182:       PARAMETER          ( SCLFAC = 2.0D+0 )
                    183:       DOUBLE PRECISION   FACTOR
                    184:       PARAMETER          ( FACTOR = 0.95D+0 )
                    185: *     ..
                    186: *     .. Local Scalars ..
                    187:       LOGICAL            NOCONV
                    188:       INTEGER            I, ICA, IEXC, IRA, J, K, L, M
                    189:       DOUBLE PRECISION   C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
                    190:      $                   SFMIN2
                    191: *     ..
                    192: *     .. External Functions ..
1.5       bertrand  193:       LOGICAL            DISNAN, LSAME
1.1       bertrand  194:       INTEGER            IZAMAX
1.13      bertrand  195:       DOUBLE PRECISION   DLAMCH, DZNRM2
                    196:       EXTERNAL           DISNAN, LSAME, IZAMAX, DLAMCH, DZNRM2
1.1       bertrand  197: *     ..
                    198: *     .. External Subroutines ..
                    199:       EXTERNAL           XERBLA, ZDSCAL, ZSWAP
                    200: *     ..
                    201: *     .. Intrinsic Functions ..
                    202:       INTRINSIC          ABS, DBLE, DIMAG, MAX, MIN
                    203: *
                    204: *     Test the input parameters
                    205: *
                    206:       INFO = 0
                    207:       IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
                    208:      $    .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
                    209:          INFO = -1
                    210:       ELSE IF( N.LT.0 ) THEN
                    211:          INFO = -2
                    212:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
                    213:          INFO = -4
                    214:       END IF
                    215:       IF( INFO.NE.0 ) THEN
                    216:          CALL XERBLA( 'ZGEBAL', -INFO )
                    217:          RETURN
                    218:       END IF
                    219: *
                    220:       K = 1
                    221:       L = N
                    222: *
                    223:       IF( N.EQ.0 )
                    224:      $   GO TO 210
                    225: *
                    226:       IF( LSAME( JOB, 'N' ) ) THEN
                    227:          DO 10 I = 1, N
                    228:             SCALE( I ) = ONE
                    229:    10    CONTINUE
                    230:          GO TO 210
                    231:       END IF
                    232: *
                    233:       IF( LSAME( JOB, 'S' ) )
                    234:      $   GO TO 120
                    235: *
                    236: *     Permutation to isolate eigenvalues if possible
                    237: *
                    238:       GO TO 50
                    239: *
                    240: *     Row and column exchange.
                    241: *
                    242:    20 CONTINUE
                    243:       SCALE( M ) = J
                    244:       IF( J.EQ.M )
                    245:      $   GO TO 30
                    246: *
                    247:       CALL ZSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
                    248:       CALL ZSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
                    249: *
                    250:    30 CONTINUE
                    251:       GO TO ( 40, 80 )IEXC
                    252: *
                    253: *     Search for rows isolating an eigenvalue and push them down.
                    254: *
                    255:    40 CONTINUE
                    256:       IF( L.EQ.1 )
                    257:      $   GO TO 210
                    258:       L = L - 1
                    259: *
                    260:    50 CONTINUE
                    261:       DO 70 J = L, 1, -1
                    262: *
                    263:          DO 60 I = 1, L
                    264:             IF( I.EQ.J )
                    265:      $         GO TO 60
                    266:             IF( DBLE( A( J, I ) ).NE.ZERO .OR. DIMAG( A( J, I ) ).NE.
                    267:      $          ZERO )GO TO 70
                    268:    60    CONTINUE
                    269: *
                    270:          M = L
                    271:          IEXC = 1
                    272:          GO TO 20
                    273:    70 CONTINUE
                    274: *
                    275:       GO TO 90
                    276: *
                    277: *     Search for columns isolating an eigenvalue and push them left.
                    278: *
                    279:    80 CONTINUE
                    280:       K = K + 1
                    281: *
                    282:    90 CONTINUE
                    283:       DO 110 J = K, L
                    284: *
                    285:          DO 100 I = K, L
                    286:             IF( I.EQ.J )
                    287:      $         GO TO 100
                    288:             IF( DBLE( A( I, J ) ).NE.ZERO .OR. DIMAG( A( I, J ) ).NE.
                    289:      $          ZERO )GO TO 110
                    290:   100    CONTINUE
                    291: *
                    292:          M = K
                    293:          IEXC = 2
                    294:          GO TO 20
                    295:   110 CONTINUE
                    296: *
                    297:   120 CONTINUE
                    298:       DO 130 I = K, L
                    299:          SCALE( I ) = ONE
                    300:   130 CONTINUE
                    301: *
                    302:       IF( LSAME( JOB, 'P' ) )
                    303:      $   GO TO 210
                    304: *
                    305: *     Balance the submatrix in rows K to L.
                    306: *
                    307: *     Iterative loop for norm reduction
                    308: *
                    309:       SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
                    310:       SFMAX1 = ONE / SFMIN1
                    311:       SFMIN2 = SFMIN1*SCLFAC
                    312:       SFMAX2 = ONE / SFMIN2
                    313:   140 CONTINUE
                    314:       NOCONV = .FALSE.
                    315: *
                    316:       DO 200 I = K, L
                    317: *
1.13      bertrand  318:          C = DZNRM2( L-K+1, A( K, I ), 1 )
                    319:          R = DZNRM2( L-K+1, A( I, K ), LDA )
1.1       bertrand  320:          ICA = IZAMAX( L, A( 1, I ), 1 )
                    321:          CA = ABS( A( ICA, I ) )
                    322:          IRA = IZAMAX( N-K+1, A( I, K ), LDA )
                    323:          RA = ABS( A( I, IRA+K-1 ) )
                    324: *
                    325: *        Guard against zero C or R due to underflow.
                    326: *
                    327:          IF( C.EQ.ZERO .OR. R.EQ.ZERO )
                    328:      $      GO TO 200
                    329:          G = R / SCLFAC
                    330:          F = ONE
                    331:          S = C + R
                    332:   160    CONTINUE
                    333:          IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
                    334:      $       MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
1.5       bertrand  335:             IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
                    336: *
                    337: *           Exit if NaN to avoid infinite loop
                    338: *
                    339:             INFO = -3
                    340:             CALL XERBLA( 'ZGEBAL', -INFO )
                    341:             RETURN
                    342:          END IF
1.1       bertrand  343:          F = F*SCLFAC
                    344:          C = C*SCLFAC
                    345:          CA = CA*SCLFAC
                    346:          R = R / SCLFAC
                    347:          G = G / SCLFAC
                    348:          RA = RA / SCLFAC
                    349:          GO TO 160
                    350: *
                    351:   170    CONTINUE
                    352:          G = C / SCLFAC
                    353:   180    CONTINUE
                    354:          IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
                    355:      $       MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
                    356:          F = F / SCLFAC
                    357:          C = C / SCLFAC
                    358:          G = G / SCLFAC
                    359:          CA = CA / SCLFAC
                    360:          R = R*SCLFAC
                    361:          RA = RA*SCLFAC
                    362:          GO TO 180
                    363: *
                    364: *        Now balance.
                    365: *
                    366:   190    CONTINUE
                    367:          IF( ( C+R ).GE.FACTOR*S )
                    368:      $      GO TO 200
                    369:          IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
                    370:             IF( F*SCALE( I ).LE.SFMIN1 )
                    371:      $         GO TO 200
                    372:          END IF
                    373:          IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
                    374:             IF( SCALE( I ).GE.SFMAX1 / F )
                    375:      $         GO TO 200
                    376:          END IF
                    377:          G = ONE / F
                    378:          SCALE( I ) = SCALE( I )*F
                    379:          NOCONV = .TRUE.
                    380: *
                    381:          CALL ZDSCAL( N-K+1, G, A( I, K ), LDA )
                    382:          CALL ZDSCAL( L, F, A( 1, I ), 1 )
                    383: *
                    384:   200 CONTINUE
                    385: *
                    386:       IF( NOCONV )
                    387:      $   GO TO 140
                    388: *
                    389:   210 CONTINUE
                    390:       ILO = K
                    391:       IHI = L
                    392: *
                    393:       RETURN
                    394: *
                    395: *     End of ZGEBAL
                    396: *
                    397:       END

CVSweb interface <joel.bertrand@systella.fr>