3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGEBAL + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgebal.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgebal.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgebal.f">
21 * SUBROUTINE CGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER IHI, ILO, INFO, LDA, N
27 * .. Array Arguments ..
38 *> CGEBAL 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.
45 *> Balancing may reduce the 1-norm of the matrix, and improve the
46 *> accuracy of the computed eigenvalues and/or eigenvectors.
55 *> Specifies the operations to be performed on A:
56 *> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
58 *> = 'P': permute only;
60 *> = 'B': both permute and scale.
66 *> The order of the matrix A. N >= 0.
71 *> A is COMPLEX 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.
81 *> The leading dimension of the array A. LDA >= max(1,N).
91 *> ILO and IHI are set to integers such that on exit
92 *> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
93 *> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
98 *> SCALE is REAL array, dimension (N)
99 *> Details of the permutations and scaling factors applied to
100 *> A. If P(j) is the index of the row and column interchanged
101 *> with row and column j and D(j) is the scaling factor
102 *> applied to row and column j, then
103 *> SCALE(j) = P(j) for j = 1,...,ILO-1
104 *> = D(j) for j = ILO,...,IHI
105 *> = P(j) for j = IHI+1,...,N.
106 *> The order in which the interchanges are made is N to IHI+1,
113 *> = 0: successful exit.
114 *> < 0: if INFO = -i, the i-th argument had an illegal value.
120 *> \author Univ. of Tennessee
121 *> \author Univ. of California Berkeley
122 *> \author Univ. of Colorado Denver
125 *> \date November 2015
127 *> \ingroup complexGEcomputational
129 *> \par Further Details:
130 * =====================
134 *> The permutations consist of row and column interchanges which put
135 *> the matrix in the form
141 *> where T1 and T2 are upper triangular matrices whose eigenvalues lie
142 *> along the diagonal. The column indices ILO and IHI mark the starting
143 *> and ending columns of the submatrix B. Balancing consists of applying
144 *> a diagonal similarity transformation inv(D) * B * D to make the
145 *> 1-norms of each row of B and its corresponding column nearly equal.
146 *> The output matrix is
149 *> ( 0 inv(D)*B*D inv(D)*Z ).
152 *> Information about the permutations P and the diagonal matrix D is
153 *> returned in the vector SCALE.
155 *> This subroutine is based on the EISPACK routine CBAL.
157 *> Modified by Tzu-Yi Chen, Computer Science Division, University of
158 *> California at Berkeley, USA
161 * =====================================================================
162 SUBROUTINE CGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
164 * -- LAPACK computational routine (version 3.6.0) --
165 * -- LAPACK is a software package provided by Univ. of Tennessee, --
166 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
169 * .. Scalar Arguments ..
171 INTEGER IHI, ILO, INFO, LDA, N
173 * .. Array Arguments ..
178 * =====================================================================
182 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
184 PARAMETER ( SCLFAC = 2.0E+0 )
186 PARAMETER ( FACTOR = 0.95E+0 )
188 * .. Local Scalars ..
190 INTEGER I, ICA, IEXC, IRA, J, K, L, M
191 REAL C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
195 * .. External Functions ..
196 LOGICAL SISNAN, LSAME
199 EXTERNAL SISNAN, LSAME, ICAMAX, SLAMCH, SCNRM2
201 * .. External Subroutines ..
202 EXTERNAL CSSCAL, CSWAP, XERBLA
204 * .. Intrinsic Functions ..
205 INTRINSIC ABS, AIMAG, MAX, MIN, REAL
207 * Test the input parameters
210 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
211 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
213 ELSE IF( N.LT.0 ) THEN
215 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
219 CALL XERBLA( 'CGEBAL', -INFO )
229 IF( LSAME( JOB, 'N' ) ) THEN
236 IF( LSAME( JOB, 'S' ) )
239 * Permutation to isolate eigenvalues if possible
243 * Row and column exchange.
250 CALL CSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
251 CALL CSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
256 * Search for rows isolating an eigenvalue and push them down.
269 IF( REAL( A( J, I ) ).NE.ZERO .OR. AIMAG( A( J, I ) ).NE.
280 * Search for columns isolating an eigenvalue and push them left.
291 IF( REAL( A( I, J ) ).NE.ZERO .OR. AIMAG( A( I, J ) ).NE.
305 IF( LSAME( JOB, 'P' ) )
308 * Balance the submatrix in rows K to L.
310 * Iterative loop for norm reduction
312 SFMIN1 = SLAMCH( 'S' ) / SLAMCH( 'P' )
313 SFMAX1 = ONE / SFMIN1
314 SFMIN2 = SFMIN1*SCLFAC
315 SFMAX2 = ONE / SFMIN2
321 C = SCNRM2( L-K+1, A( K, I ), 1 )
322 R = SCNRM2( L-K+1, A( I , K ), LDA )
323 ICA = ICAMAX( L, A( 1, I ), 1 )
324 CA = ABS( A( ICA, I ) )
325 IRA = ICAMAX( N-K+1, A( I, K ), LDA )
326 RA = ABS( A( I, IRA+K-1 ) )
328 * Guard against zero C or R due to underflow.
330 IF( C.EQ.ZERO .OR. R.EQ.ZERO )
336 IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
337 $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
338 IF( SISNAN( C+F+CA+R+G+RA ) ) THEN
340 * Exit if NaN to avoid infinite loop
343 CALL XERBLA( 'CGEBAL', -INFO )
357 IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
358 $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
370 IF( ( C+R ).GE.FACTOR*S )
372 IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
373 IF( F*SCALE( I ).LE.SFMIN1 )
376 IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
377 IF( SCALE( I ).GE.SFMAX1 / F )
381 SCALE( I ) = SCALE( I )*F
384 CALL CSSCAL( N-K+1, G, A( I, K ), LDA )
385 CALL CSSCAL( L, F, A( 1, I ), 1 )