001:       SUBROUTINE CPBEQU( UPLO, N, KD, AB, LDAB, S, SCOND, AMAX, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       CHARACTER          UPLO
009:       INTEGER            INFO, KD, LDAB, N
010:       REAL               AMAX, SCOND
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               S( * )
014:       COMPLEX            AB( LDAB, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CPBEQU computes row and column scalings intended to equilibrate a
021: *  Hermitian positive definite band matrix A and reduce its condition
022: *  number (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: *  UPLO    (input) CHARACTER*1
033: *          = 'U':  Upper triangular of A is stored;
034: *          = 'L':  Lower triangular of A is stored.
035: *
036: *  N       (input) INTEGER
037: *          The order of the matrix A.  N >= 0.
038: *
039: *  KD      (input) INTEGER
040: *          The number of superdiagonals of the matrix A if UPLO = 'U',
041: *          or the number of subdiagonals if UPLO = 'L'.  KD >= 0.
042: *
043: *  AB      (input) COMPLEX array, dimension (LDAB,N)
044: *          The upper or lower triangle of the Hermitian band matrix A,
045: *          stored in the first KD+1 rows of the array.  The j-th column
046: *          of A is stored in the j-th column of the array AB as follows:
047: *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
048: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
049: *
050: *  LDAB     (input) INTEGER
051: *          The leading dimension of the array A.  LDAB >= KD+1.
052: *
053: *  S       (output) REAL array, dimension (N)
054: *          If INFO = 0, S contains the scale factors for A.
055: *
056: *  SCOND   (output) REAL
057: *          If INFO = 0, S contains the ratio of the smallest S(i) to
058: *          the largest S(i).  If SCOND >= 0.1 and AMAX is neither too
059: *          large nor too small, it is not worth scaling by S.
060: *
061: *  AMAX    (output) REAL
062: *          Absolute value of largest matrix element.  If AMAX is very
063: *          close to overflow or very close to underflow, the matrix
064: *          should be scaled.
065: *
066: *  INFO    (output) INTEGER
067: *          = 0:  successful exit
068: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
069: *          > 0:  if INFO = i, the i-th diagonal element is nonpositive.
070: *
071: *  =====================================================================
072: *
073: *     .. Parameters ..
074:       REAL               ZERO, ONE
075:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
076: *     ..
077: *     .. Local Scalars ..
078:       LOGICAL            UPPER
079:       INTEGER            I, J
080:       REAL               SMIN
081: *     ..
082: *     .. External Functions ..
083:       LOGICAL            LSAME
084:       EXTERNAL           LSAME
085: *     ..
086: *     .. External Subroutines ..
087:       EXTERNAL           XERBLA
088: *     ..
089: *     .. Intrinsic Functions ..
090:       INTRINSIC          MAX, MIN, REAL, SQRT
091: *     ..
092: *     .. Executable Statements ..
093: *
094: *     Test the input parameters.
095: *
096:       INFO = 0
097:       UPPER = LSAME( UPLO, 'U' )
098:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
099:          INFO = -1
100:       ELSE IF( N.LT.0 ) THEN
101:          INFO = -2
102:       ELSE IF( KD.LT.0 ) THEN
103:          INFO = -3
104:       ELSE IF( LDAB.LT.KD+1 ) THEN
105:          INFO = -5
106:       END IF
107:       IF( INFO.NE.0 ) THEN
108:          CALL XERBLA( 'CPBEQU', -INFO )
109:          RETURN
110:       END IF
111: *
112: *     Quick return if possible
113: *
114:       IF( N.EQ.0 ) THEN
115:          SCOND = ONE
116:          AMAX = ZERO
117:          RETURN
118:       END IF
119: *
120:       IF( UPPER ) THEN
121:          J = KD + 1
122:       ELSE
123:          J = 1
124:       END IF
125: *
126: *     Initialize SMIN and AMAX.
127: *
128:       S( 1 ) = REAL( AB( J, 1 ) )
129:       SMIN = S( 1 )
130:       AMAX = S( 1 )
131: *
132: *     Find the minimum and maximum diagonal elements.
133: *
134:       DO 10 I = 2, N
135:          S( I ) = REAL( AB( J, I ) )
136:          SMIN = MIN( SMIN, S( I ) )
137:          AMAX = MAX( AMAX, S( I ) )
138:    10 CONTINUE
139: *
140:       IF( SMIN.LE.ZERO ) THEN
141: *
142: *        Find the first non-positive diagonal element and return.
143: *
144:          DO 20 I = 1, N
145:             IF( S( I ).LE.ZERO ) THEN
146:                INFO = I
147:                RETURN
148:             END IF
149:    20    CONTINUE
150:       ELSE
151: *
152: *        Set the scale factors to the reciprocals
153: *        of the diagonal elements.
154: *
155:          DO 30 I = 1, N
156:             S( I ) = ONE / SQRT( S( I ) )
157:    30    CONTINUE
158: *
159: *        Compute SCOND = min(S(I)) / max(S(I))
160: *
161:          SCOND = SQRT( SMIN ) / SQRT( AMAX )
162:       END IF
163:       RETURN
164: *
165: *     End of CPBEQU
166: *
167:       END
168: