1
SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
3
* -- LAPACK routine (version 3.0) --
4
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5
* Courant Institute, Argonne National Lab, and Rice University
8
* .. Scalar Arguments ..
10
INTEGER IHI, ILO, INFO, LDA, N
12
* .. Array Arguments ..
13
DOUBLE PRECISION SCALE( * )
14
COMPLEX*16 A( LDA, * )
20
* ZGEBAL balances a general complex matrix A. This involves, first,
21
* permuting A by a similarity transformation to isolate eigenvalues
22
* in the first 1 to ILO-1 and last IHI+1 to N elements on the
23
* diagonal; and second, applying a diagonal similarity transformation
24
* to rows and columns ILO to IHI to make the rows and columns as
25
* close in norm as possible. Both steps are optional.
27
* Balancing may reduce the 1-norm of the matrix, and improve the
28
* accuracy of the computed eigenvalues and/or eigenvectors.
33
* JOB (input) CHARACTER*1
34
* Specifies the operations to be performed on A:
35
* = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
37
* = 'P': permute only;
39
* = 'B': both permute and scale.
42
* The order of the matrix A. N >= 0.
44
* A (input/output) COMPLEX*16 array, dimension (LDA,N)
45
* On entry, the input matrix A.
46
* On exit, A is overwritten by the balanced matrix.
47
* If JOB = 'N', A is not referenced.
48
* See Further Details.
51
* The leading dimension of the array A. LDA >= max(1,N).
53
* ILO (output) INTEGER
54
* IHI (output) INTEGER
55
* ILO and IHI are set to integers such that on exit
56
* A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
57
* If JOB = 'N' or 'S', ILO = 1 and IHI = N.
59
* SCALE (output) DOUBLE PRECISION array, dimension (N)
60
* Details of the permutations and scaling factors applied to
61
* A. If P(j) is the index of the row and column interchanged
62
* with row and column j and D(j) is the scaling factor
63
* applied to row and column j, then
64
* SCALE(j) = P(j) for j = 1,...,ILO-1
65
* = D(j) for j = ILO,...,IHI
66
* = P(j) for j = IHI+1,...,N.
67
* The order in which the interchanges are made is N to IHI+1,
70
* INFO (output) INTEGER
71
* = 0: successful exit.
72
* < 0: if INFO = -i, the i-th argument had an illegal value.
77
* The permutations consist of row and column interchanges which put
78
* the matrix in the form
84
* where T1 and T2 are upper triangular matrices whose eigenvalues lie
85
* along the diagonal. The column indices ILO and IHI mark the starting
86
* and ending columns of the submatrix B. Balancing consists of applying
87
* a diagonal similarity transformation inv(D) * B * D to make the
88
* 1-norms of each row of B and its corresponding column nearly equal.
89
* The output matrix is
92
* ( 0 inv(D)*B*D inv(D)*Z ).
95
* Information about the permutations P and the diagonal matrix D is
96
* returned in the vector SCALE.
98
* This subroutine is based on the EISPACK routine CBAL.
100
* Modified by Tzu-Yi Chen, Computer Science Division, University of
101
* California at Berkeley, USA
103
* =====================================================================
106
DOUBLE PRECISION ZERO, ONE
107
PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
108
DOUBLE PRECISION SCLFAC
109
PARAMETER ( SCLFAC = 0.8D+1 )
110
DOUBLE PRECISION FACTOR
111
PARAMETER ( FACTOR = 0.95D+0 )
113
* .. Local Scalars ..
115
INTEGER I, ICA, IEXC, IRA, J, K, L, M
116
DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
120
* .. External Functions ..
123
DOUBLE PRECISION DLAMCH
124
EXTERNAL LSAME, IZAMAX, DLAMCH
126
* .. External Subroutines ..
127
EXTERNAL XERBLA, ZDSCAL, ZSWAP
129
* .. Intrinsic Functions ..
130
INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
132
* .. Statement Functions ..
133
DOUBLE PRECISION CABS1
135
* .. Statement Function definitions ..
136
CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
138
* .. Executable Statements ..
140
* Test the input parameters
143
IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
144
$ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
146
ELSE IF( N.LT.0 ) THEN
148
ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
152
CALL XERBLA( 'ZGEBAL', -INFO )
162
IF( LSAME( JOB, 'N' ) ) THEN
169
IF( LSAME( JOB, 'S' ) )
172
* Permutation to isolate eigenvalues if possible
176
* Row and column exchange.
183
CALL ZSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
184
CALL ZSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
189
* Search for rows isolating an eigenvalue and push them down.
202
IF( DBLE( A( J, I ) ).NE.ZERO .OR. DIMAG( A( J, I ) ).NE.
213
* Search for columns isolating an eigenvalue and push them left.
224
IF( DBLE( A( I, J ) ).NE.ZERO .OR. DIMAG( A( I, J ) ).NE.
238
IF( LSAME( JOB, 'P' ) )
241
* Balance the submatrix in rows K to L.
243
* Iterative loop for norm reduction
245
SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
246
SFMAX1 = ONE / SFMIN1
247
SFMIN2 = SFMIN1*SCLFAC
248
SFMAX2 = ONE / SFMIN2
259
C = C + CABS1( A( J, I ) )
260
R = R + CABS1( A( I, J ) )
262
ICA = IZAMAX( L, A( 1, I ), 1 )
263
CA = ABS( A( ICA, I ) )
264
IRA = IZAMAX( N-K+1, A( I, K ), LDA )
265
RA = ABS( A( I, IRA+K-1 ) )
267
* Guard against zero C or R due to underflow.
269
IF( C.EQ.ZERO .OR. R.EQ.ZERO )
275
IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
276
$ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
288
IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
289
$ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
301
IF( ( C+R ).GE.FACTOR*S )
303
IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
304
IF( F*SCALE( I ).LE.SFMIN1 )
307
IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
308
IF( SCALE( I ).GE.SFMAX1 / F )
312
SCALE( I ) = SCALE( I )*F
315
CALL ZDSCAL( N-K+1, G, A( I, K ), LDA )
316
CALL ZDSCAL( L, F, A( 1, I ), 1 )