--- rpl/lapack/lapack/zgebal.f 2010/08/06 15:28:51 1.3
+++ rpl/lapack/lapack/zgebal.f 2023/08/07 08:39:16 1.21
@@ -1,9 +1,168 @@
+*> \brief \b ZGEBAL
+*
+* =========== DOCUMENTATION ===========
+*
+* Online html documentation available at
+* http://www.netlib.org/lapack/explore-html/
+*
+*> \htmlonly
+*> Download ZGEBAL + dependencies
+*>
+*> [TGZ]
+*>
+*> [ZIP]
+*>
+*> [TXT]
+*> \endhtmlonly
+*
+* Definition:
+* ===========
+*
+* SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
+*
+* .. Scalar Arguments ..
+* CHARACTER JOB
+* INTEGER IHI, ILO, INFO, LDA, N
+* ..
+* .. Array Arguments ..
+* DOUBLE PRECISION SCALE( * )
+* COMPLEX*16 A( LDA, * )
+* ..
+*
+*
+*> \par Purpose:
+* =============
+*>
+*> \verbatim
+*>
+*> ZGEBAL balances a general complex matrix A. This involves, first,
+*> permuting A by a similarity transformation to isolate eigenvalues
+*> in the first 1 to ILO-1 and last IHI+1 to N elements on the
+*> diagonal; and second, applying a diagonal similarity transformation
+*> to rows and columns ILO to IHI to make the rows and columns as
+*> close in norm as possible. Both steps are optional.
+*>
+*> Balancing may reduce the 1-norm of the matrix, and improve the
+*> accuracy of the computed eigenvalues and/or eigenvectors.
+*> \endverbatim
+*
+* Arguments:
+* ==========
+*
+*> \param[in] JOB
+*> \verbatim
+*> JOB is CHARACTER*1
+*> Specifies the operations to be performed on A:
+*> = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
+*> for i = 1,...,N;
+*> = 'P': permute only;
+*> = 'S': scale only;
+*> = 'B': both permute and scale.
+*> \endverbatim
+*>
+*> \param[in] N
+*> \verbatim
+*> N is INTEGER
+*> The order of the matrix A. N >= 0.
+*> \endverbatim
+*>
+*> \param[in,out] A
+*> \verbatim
+*> A is COMPLEX*16 array, dimension (LDA,N)
+*> On entry, the input matrix A.
+*> On exit, A is overwritten by the balanced matrix.
+*> If JOB = 'N', A is not referenced.
+*> See Further Details.
+*> \endverbatim
+*>
+*> \param[in] LDA
+*> \verbatim
+*> LDA is INTEGER
+*> The leading dimension of the array A. LDA >= max(1,N).
+*> \endverbatim
+*>
+*> \param[out] ILO
+*> \verbatim
+*> ILO is INTEGER
+*> \endverbatim
+*>
+*> \param[out] IHI
+*> \verbatim
+*> IHI is INTEGER
+*> ILO and IHI are set to INTEGER such that on exit
+*> A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
+*> If JOB = 'N' or 'S', ILO = 1 and IHI = N.
+*> \endverbatim
+*>
+*> \param[out] SCALE
+*> \verbatim
+*> SCALE is DOUBLE PRECISION array, dimension (N)
+*> Details of the permutations and scaling factors applied to
+*> A. If P(j) is the index of the row and column interchanged
+*> with row and column j and D(j) is the scaling factor
+*> applied to row and column j, then
+*> SCALE(j) = P(j) for j = 1,...,ILO-1
+*> = D(j) for j = ILO,...,IHI
+*> = P(j) for j = IHI+1,...,N.
+*> The order in which the interchanges are made is N to IHI+1,
+*> then 1 to ILO-1.
+*> \endverbatim
+*>
+*> \param[out] INFO
+*> \verbatim
+*> INFO is INTEGER
+*> = 0: successful exit.
+*> < 0: if INFO = -i, the i-th argument had an illegal value.
+*> \endverbatim
+*
+* Authors:
+* ========
+*
+*> \author Univ. of Tennessee
+*> \author Univ. of California Berkeley
+*> \author Univ. of Colorado Denver
+*> \author NAG Ltd.
+*
+*> \ingroup complex16GEcomputational
+*
+*> \par Further Details:
+* =====================
+*>
+*> \verbatim
+*>
+*> The permutations consist of row and column interchanges which put
+*> the matrix in the form
+*>
+*> ( T1 X Y )
+*> P A P = ( 0 B Z )
+*> ( 0 0 T2 )
+*>
+*> where T1 and T2 are upper triangular matrices whose eigenvalues lie
+*> along the diagonal. The column indices ILO and IHI mark the starting
+*> and ending columns of the submatrix B. Balancing consists of applying
+*> a diagonal similarity transformation inv(D) * B * D to make the
+*> 1-norms of each row of B and its corresponding column nearly equal.
+*> The output matrix is
+*>
+*> ( T1 X*D Y )
+*> ( 0 inv(D)*B*D inv(D)*Z ).
+*> ( 0 0 T2 )
+*>
+*> Information about the permutations P and the diagonal matrix D is
+*> returned in the vector SCALE.
+*>
+*> This subroutine is based on the EISPACK routine CBAL.
+*>
+*> Modified by Tzu-Yi Chen, Computer Science Division, University of
+*> California at Berkeley, USA
+*> \endverbatim
+*>
+* =====================================================================
SUBROUTINE ZGEBAL( JOB, N, A, LDA, ILO, IHI, SCALE, INFO )
*
-* -- LAPACK routine (version 3.2) --
+* -- LAPACK computational routine --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
-* November 2006
*
* .. Scalar Arguments ..
CHARACTER JOB
@@ -14,92 +173,6 @@
COMPLEX*16 A( LDA, * )
* ..
*
-* Purpose
-* =======
-*
-* ZGEBAL balances a general complex matrix A. This involves, first,
-* permuting A by a similarity transformation to isolate eigenvalues
-* in the first 1 to ILO-1 and last IHI+1 to N elements on the
-* diagonal; and second, applying a diagonal similarity transformation
-* to rows and columns ILO to IHI to make the rows and columns as
-* close in norm as possible. Both steps are optional.
-*
-* Balancing may reduce the 1-norm of the matrix, and improve the
-* accuracy of the computed eigenvalues and/or eigenvectors.
-*
-* Arguments
-* =========
-*
-* JOB (input) CHARACTER*1
-* Specifies the operations to be performed on A:
-* = 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
-* for i = 1,...,N;
-* = 'P': permute only;
-* = 'S': scale only;
-* = 'B': both permute and scale.
-*
-* N (input) INTEGER
-* The order of the matrix A. N >= 0.
-*
-* A (input/output) COMPLEX*16 array, dimension (LDA,N)
-* On entry, the input matrix A.
-* On exit, A is overwritten by the balanced matrix.
-* If JOB = 'N', A is not referenced.
-* See Further Details.
-*
-* LDA (input) INTEGER
-* The leading dimension of the array A. LDA >= max(1,N).
-*
-* ILO (output) INTEGER
-* IHI (output) INTEGER
-* ILO and IHI are set to integers such that on exit
-* A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
-* If JOB = 'N' or 'S', ILO = 1 and IHI = N.
-*
-* SCALE (output) DOUBLE PRECISION array, dimension (N)
-* Details of the permutations and scaling factors applied to
-* A. If P(j) is the index of the row and column interchanged
-* with row and column j and D(j) is the scaling factor
-* applied to row and column j, then
-* SCALE(j) = P(j) for j = 1,...,ILO-1
-* = D(j) for j = ILO,...,IHI
-* = P(j) for j = IHI+1,...,N.
-* The order in which the interchanges are made is N to IHI+1,
-* then 1 to ILO-1.
-*
-* INFO (output) INTEGER
-* = 0: successful exit.
-* < 0: if INFO = -i, the i-th argument had an illegal value.
-*
-* Further Details
-* ===============
-*
-* The permutations consist of row and column interchanges which put
-* the matrix in the form
-*
-* ( T1 X Y )
-* P A P = ( 0 B Z )
-* ( 0 0 T2 )
-*
-* where T1 and T2 are upper triangular matrices whose eigenvalues lie
-* along the diagonal. The column indices ILO and IHI mark the starting
-* and ending columns of the submatrix B. Balancing consists of applying
-* a diagonal similarity transformation inv(D) * B * D to make the
-* 1-norms of each row of B and its corresponding column nearly equal.
-* The output matrix is
-*
-* ( T1 X*D Y )
-* ( 0 inv(D)*B*D inv(D)*Z ).
-* ( 0 0 T2 )
-*
-* Information about the permutations P and the diagonal matrix D is
-* returned in the vector SCALE.
-*
-* This subroutine is based on the EISPACK routine CBAL.
-*
-* Modified by Tzu-Yi Chen, Computer Science Division, University of
-* California at Berkeley, USA
-*
* =====================================================================
*
* .. Parameters ..
@@ -115,27 +188,18 @@
INTEGER I, ICA, IEXC, IRA, J, K, L, M
DOUBLE PRECISION C, CA, F, G, R, RA, S, SFMAX1, SFMAX2, SFMIN1,
$ SFMIN2
- COMPLEX*16 CDUM
* ..
* .. External Functions ..
- LOGICAL LSAME
+ LOGICAL DISNAN, LSAME
INTEGER IZAMAX
- DOUBLE PRECISION DLAMCH
- EXTERNAL LSAME, IZAMAX, DLAMCH
+ DOUBLE PRECISION DLAMCH, DZNRM2
+ EXTERNAL DISNAN, LSAME, IZAMAX, DLAMCH, DZNRM2
* ..
* .. External Subroutines ..
EXTERNAL XERBLA, ZDSCAL, ZSWAP
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
-* ..
-* .. Statement Functions ..
- DOUBLE PRECISION CABS1
-* ..
-* .. Statement Function definitions ..
- CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
-* ..
-* .. Executable Statements ..
*
* Test the input parameters
*
@@ -250,15 +314,9 @@
NOCONV = .FALSE.
*
DO 200 I = K, L
- C = ZERO
- R = ZERO
*
- DO 150 J = K, L
- IF( J.EQ.I )
- $ GO TO 150
- C = C + CABS1( A( J, I ) )
- R = R + CABS1( A( I, J ) )
- 150 CONTINUE
+ C = DZNRM2( L-K+1, A( K, I ), 1 )
+ R = DZNRM2( L-K+1, A( I, K ), LDA )
ICA = IZAMAX( L, A( 1, I ), 1 )
CA = ABS( A( ICA, I ) )
IRA = IZAMAX( N-K+1, A( I, K ), LDA )
@@ -274,6 +332,14 @@
160 CONTINUE
IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.
$ MIN( R, G, RA ).LE.SFMIN2 )GO TO 170
+ IF( DISNAN( C+F+CA+R+G+RA ) ) THEN
+*
+* Exit if NaN to avoid infinite loop
+*
+ INFO = -3
+ CALL XERBLA( 'ZGEBAL', -INFO )
+ RETURN
+ END IF
F = F*SCLFAC
C = C*SCLFAC
CA = CA*SCLFAC