3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DGEBAL + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgebal.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgebal.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgebal.f">
21 * SUBROUTINE DGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER IHI, ILO, INFO, LDA, N
27 * .. Array Arguments ..
28 * DOUBLE PRECISION A( LDA, * ), SCALE( * )
37 *> DGEBAL balances a general real matrix A. This involves, first,
38 *> permuting A by a similarity transformation to isolate eigenvalues
39 *> in the first 1 to ILO-1 and last IHI+1 to N elements on the
40 *> diagonal; and second, applying a diagonal similarity transformation
41 *> to rows and columns ILO to IHI to make the rows and columns as
42 *> close in norm as possible. Both steps are optional.
44 *> Balancing may reduce the 1-norm of the matrix, and improve the
45 *> accuracy of the computed eigenvalues and/or eigenvectors.
54 *> Specifies the operations to be performed on A:
55 *> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
57 *> = 'P': permute only;
59 *> = 'B': both permute and scale.
65 *> The order of the matrix A. N >= 0.
70 *> A is DOUBLE array, dimension (LDA,N)
71 *> On entry, the input matrix A.
72 *> On exit, A is overwritten by the balanced matrix.
73 *> If JOB = 'N', A is not referenced.
74 *> See Further Details.
80 *> The leading dimension of the array A. LDA >= max(1,N).
90 *> ILO and IHI are set to integers such that on exit
91 *> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
92 *> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
97 *> SCALE is DOUBLE array, dimension (N)
98 *> Details of the permutations and scaling factors applied to
99 *> A. If P(j) is the index of the row and column interchanged
100 *> with row and column j and D(j) is the scaling factor
101 *> applied to row and column j, then
102 *> SCALE(j) = P(j) for j = 1,...,ILO-1
103 *> = D(j) for j = ILO,...,IHI
104 *> = P(j) for j = IHI+1,...,N.
105 *> The order in which the interchanges are made is N to IHI+1,
112 *> = 0: successful exit.
113 *> < 0: if INFO = -i, the i-th argument had an illegal value.
119 *> \author Univ. of Tennessee
120 *> \author Univ. of California Berkeley
121 *> \author Univ. of Colorado Denver
124 *> \date November 2015
126 *> \ingroup doubleGEcomputational
128 *> \par Further Details:
129 * =====================
133 *> The permutations consist of row and column interchanges which put
134 *> the matrix in the form
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
148 *> ( 0 inv(D)*B*D inv(D)*Z ).
151 *> Information about the permutations P and the diagonal matrix D is
152 *> returned in the vector SCALE.
154 *> This subroutine is based on the EISPACK routine BALANC.
156 *> Modified by Tzu-Yi Chen, Computer Science Division, University of
157 *> California at Berkeley, USA
160 * =====================================================================
161 SUBROUTINE DGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
163 * -- LAPACK computational routine (version 3.6.0) --
164 * -- LAPACK is a software package provided by Univ. of Tennessee, --
165 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
168 * .. Scalar Arguments ..
170 INTEGER IHI, ILO, INFO, LDA, N
172 * .. Array Arguments ..
173 DOUBLE PRECISION A( LDA, * ), SCALE( * )
176 * =====================================================================
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 )
186 * .. Local Scalars ..
188 INTEGER I, ICA, IEXC, IRA, J, K, L, M
189 DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
192 * .. External Functions ..
193 LOGICAL DISNAN, LSAME
195 DOUBLE PRECISION DLAMCH, DNRM2
196 EXTERNAL DISNAN, LSAME, IDAMAX, DLAMCH, DNRM2
198 * .. External Subroutines ..
199 EXTERNAL DSCAL, DSWAP, XERBLA
201 * .. Intrinsic Functions ..
202 INTRINSIC ABS, MAX, MIN
204 * Test the input parameters
207 IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.
208 $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN
210 ELSE IF( N.LT.0 ) THEN
212 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
216 CALL XERBLA( 'DGEBAL', -INFO )
226 IF( LSAME( JOB, 'N' ) ) THEN
233 IF( LSAME( JOB, 'S' ) )
236 * Permutation to isolate eigenvalues if possible
240 * Row and column exchange.
247 CALL DSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )
248 CALL DSWAP( N-K+1, A( J, K ), LDA, A( M, K ), LDA )
253 * Search for rows isolating an eigenvalue and push them down.
266 IF( A( J, I ).NE.ZERO )
277 * Search for columns isolating an eigenvalue and push them left.
288 IF( A( I, J ).NE.ZERO )
302 IF( LSAME( JOB, 'P' ) )
305 * Balance the submatrix in rows K to L.
307 * Iterative loop for norm reduction
309 SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )
310 SFMAX1 = ONE / SFMIN1
311 SFMIN2 = SFMIN1*SCLFAC
312 SFMAX2 = ONE / SFMIN2
319 C = DNRM2( L-K+1, A( K, I ), 1 )
320 R = DNRM2( L-K+1, A( I, K ), LDA )
321 ICA = IDAMAX( L, A( 1, I ), 1 )
322 CA = ABS( A( ICA, I ) )
323 IRA = IDAMAX( N-K+1, A( I, K ), LDA )
324 RA = ABS( A( I, IRA+K-1 ) )
326 * Guard against zero C or R due to underflow.
328 IF( C.EQ.ZERO .OR. R.EQ.ZERO )
334 IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
335 $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
336 IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
338 * Exit if NaN to avoid infinite loop
341 CALL XERBLA( 'DGEBAL', -INFO )
355 IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.
356 $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 190
368 IF( ( C+R ).GE.FACTOR*S )
370 IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN
371 IF( F*SCALE( I ).LE.SFMIN1 )
374 IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN
375 IF( SCALE( I ).GE.SFMAX1 / F )
379 SCALE( I ) = SCALE( I )*F
382 CALL DSCAL( N-K+1, G, A( I, K ), LDA )
383 CALL DSCAL( L, F, A( 1, I ), 1 )