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