```001:       SUBROUTINE CPOEQU( N, A, LDA, S, SCOND, AMAX, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       INTEGER            INFO, LDA, N
010:       REAL               AMAX, SCOND
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               S( * )
014:       COMPLEX            A( LDA, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CPOEQU computes row and column scalings intended to equilibrate a
021: *  Hermitian positive definite matrix A and reduce its condition number
022: *  (with respect to the two-norm).  S contains the scale factors,
023: *  S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with
024: *  elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal.  This
025: *  choice of S puts the condition number of B within a factor N of the
026: *  smallest possible condition number over all possible diagonal
027: *  scalings.
028: *
029: *  Arguments
030: *  =========
031: *
032: *  N       (input) INTEGER
033: *          The order of the matrix A.  N >= 0.
034: *
035: *  A       (input) COMPLEX array, dimension (LDA,N)
036: *          The N-by-N Hermitian positive definite matrix whose scaling
037: *          factors are to be computed.  Only the diagonal elements of A
038: *          are referenced.
039: *
040: *  LDA     (input) INTEGER
041: *          The leading dimension of the array A.  LDA >= max(1,N).
042: *
043: *  S       (output) REAL array, dimension (N)
044: *          If INFO = 0, S contains the scale factors for A.
045: *
046: *  SCOND   (output) REAL
047: *          If INFO = 0, S contains the ratio of the smallest S(i) to
048: *          the largest S(i).  If SCOND >= 0.1 and AMAX is neither too
049: *          large nor too small, it is not worth scaling by S.
050: *
051: *  AMAX    (output) REAL
052: *          Absolute value of largest matrix element.  If AMAX is very
053: *          close to overflow or very close to underflow, the matrix
054: *          should be scaled.
055: *
056: *  INFO    (output) INTEGER
057: *          = 0:  successful exit
058: *          < 0:  if INFO = -i, the i-th argument had an illegal value
059: *          > 0:  if INFO = i, the i-th diagonal element is nonpositive.
060: *
061: *  =====================================================================
062: *
063: *     .. Parameters ..
064:       REAL               ZERO, ONE
065:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
066: *     ..
067: *     .. Local Scalars ..
068:       INTEGER            I
069:       REAL               SMIN
070: *     ..
071: *     .. External Subroutines ..
072:       EXTERNAL           XERBLA
073: *     ..
074: *     .. Intrinsic Functions ..
075:       INTRINSIC          MAX, MIN, REAL, SQRT
076: *     ..
077: *     .. Executable Statements ..
078: *
079: *     Test the input parameters.
080: *
081:       INFO = 0
082:       IF( N.LT.0 ) THEN
083:          INFO = -1
084:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
085:          INFO = -3
086:       END IF
087:       IF( INFO.NE.0 ) THEN
088:          CALL XERBLA( 'CPOEQU', -INFO )
089:          RETURN
090:       END IF
091: *
092: *     Quick return if possible
093: *
094:       IF( N.EQ.0 ) THEN
095:          SCOND = ONE
096:          AMAX = ZERO
097:          RETURN
098:       END IF
099: *
100: *     Find the minimum and maximum diagonal elements.
101: *
102:       S( 1 ) = REAL( A( 1, 1 ) )
103:       SMIN = S( 1 )
104:       AMAX = S( 1 )
105:       DO 10 I = 2, N
106:          S( I ) = REAL( A( I, I ) )
107:          SMIN = MIN( SMIN, S( I ) )
108:          AMAX = MAX( AMAX, S( I ) )
109:    10 CONTINUE
110: *
111:       IF( SMIN.LE.ZERO ) THEN
112: *
113: *        Find the first non-positive diagonal element and return.
114: *
115:          DO 20 I = 1, N
116:             IF( S( I ).LE.ZERO ) THEN
117:                INFO = I
118:                RETURN
119:             END IF
120:    20    CONTINUE
121:       ELSE
122: *
123: *        Set the scale factors to the reciprocals
124: *        of the diagonal elements.
125: *
126:          DO 30 I = 1, N
127:             S( I ) = ONE / SQRT( S( I ) )
128:    30    CONTINUE
129: *
130: *        Compute SCOND = min(S(I)) / max(S(I))
131: *
132:          SCOND = SQRT( SMIN ) / SQRT( AMAX )
133:       END IF
134:       RETURN
135: *
136: *     End of CPOEQU
137: *
138:       END
139: ```