001:       SUBROUTINE SLAQGB( M, N, KL, KU, AB, LDAB, R, C, ROWCND, COLCND,
002:      $                   AMAX, EQUED )
003: *
004: *  -- LAPACK auxiliary routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          EQUED
010:       INTEGER            KL, KU, LDAB, M, N
011:       REAL               AMAX, COLCND, ROWCND
012: *     ..
013: *     .. Array Arguments ..
014:       REAL               AB( LDAB, * ), C( * ), R( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  SLAQGB equilibrates a general M by N band matrix A with KL
021: *  subdiagonals and KU superdiagonals using the row and scaling factors
022: *  in the vectors R and C.
023: *
024: *  Arguments
025: *  =========
026: *
027: *  M       (input) INTEGER
028: *          The number of rows of the matrix A.  M >= 0.
029: *
030: *  N       (input) INTEGER
031: *          The number of columns of the matrix A.  N >= 0.
032: *
033: *  KL      (input) INTEGER
034: *          The number of subdiagonals within the band of A.  KL >= 0.
035: *
036: *  KU      (input) INTEGER
037: *          The number of superdiagonals within the band of A.  KU >= 0.
038: *
039: *  AB      (input/output) REAL array, dimension (LDAB,N)
040: *          On entry, the matrix A in band storage, in rows 1 to KL+KU+1.
041: *          The j-th column of A is stored in the j-th column of the
042: *          array AB as follows:
043: *          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl)
044: *
045: *          On exit, the equilibrated matrix, in the same storage format
046: *          as A.  See EQUED for the form of the equilibrated matrix.
047: *
048: *  LDAB    (input) INTEGER
049: *          The leading dimension of the array AB.  LDA >= KL+KU+1.
050: *
051: *  R       (input) REAL array, dimension (M)
052: *          The row scale factors for A.
053: *
054: *  C       (input) REAL array, dimension (N)
055: *          The column scale factors for A.
056: *
057: *  ROWCND  (input) REAL
058: *          Ratio of the smallest R(i) to the largest R(i).
059: *
060: *  COLCND  (input) REAL
061: *          Ratio of the smallest C(i) to the largest C(i).
062: *
063: *  AMAX    (input) REAL
064: *          Absolute value of largest matrix entry.
065: *
066: *  EQUED   (output) CHARACTER*1
067: *          Specifies the form of equilibration that was done.
068: *          = 'N':  No equilibration
069: *          = 'R':  Row equilibration, i.e., A has been premultiplied by
070: *                  diag(R).
071: *          = 'C':  Column equilibration, i.e., A has been postmultiplied
072: *                  by diag(C).
073: *          = 'B':  Both row and column equilibration, i.e., A has been
074: *                  replaced by diag(R) * A * diag(C).
075: *
076: *  Internal Parameters
077: *  ===================
078: *
079: *  THRESH is a threshold value used to decide if row or column scaling
080: *  should be done based on the ratio of the row or column scaling
081: *  factors.  If ROWCND < THRESH, row scaling is done, and if
082: *  COLCND < THRESH, column scaling is done.
083: *
084: *  LARGE and SMALL are threshold values used to decide if row scaling
085: *  should be done based on the absolute size of the largest matrix
086: *  element.  If AMAX > LARGE or AMAX < SMALL, row scaling is done.
087: *
088: *  =====================================================================
089: *
090: *     .. Parameters ..
091:       REAL               ONE, THRESH
092:       PARAMETER          ( ONE = 1.0E+0, THRESH = 0.1E+0 )
093: *     ..
094: *     .. Local Scalars ..
095:       INTEGER            I, J
096:       REAL               CJ, LARGE, SMALL
097: *     ..
098: *     .. External Functions ..
099:       REAL               SLAMCH
100:       EXTERNAL           SLAMCH
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC          MAX, MIN
104: *     ..
105: *     .. Executable Statements ..
106: *
107: *     Quick return if possible
108: *
109:       IF( M.LE.0 .OR. N.LE.0 ) THEN
110:          EQUED = 'N'
111:          RETURN
112:       END IF
113: *
114: *     Initialize LARGE and SMALL.
115: *
116:       SMALL = SLAMCH( 'Safe minimum' ) / SLAMCH( 'Precision' )
117:       LARGE = ONE / SMALL
118: *
119:       IF( ROWCND.GE.THRESH .AND. AMAX.GE.SMALL .AND. AMAX.LE.LARGE )
120:      $     THEN
121: *
122: *        No row scaling
123: *
124:          IF( COLCND.GE.THRESH ) THEN
125: *
126: *           No column scaling
127: *
128:             EQUED = 'N'
129:          ELSE
130: *
131: *           Column scaling
132: *
133:             DO 20 J = 1, N
134:                CJ = C( J )
135:                DO 10 I = MAX( 1, J-KU ), MIN( M, J+KL )
136:                   AB( KU+1+I-J, J ) = CJ*AB( KU+1+I-J, J )
137:    10          CONTINUE
138:    20       CONTINUE
139:             EQUED = 'C'
140:          END IF
141:       ELSE IF( COLCND.GE.THRESH ) THEN
142: *
143: *        Row scaling, no column scaling
144: *
145:          DO 40 J = 1, N
146:             DO 30 I = MAX( 1, J-KU ), MIN( M, J+KL )
147:                AB( KU+1+I-J, J ) = R( I )*AB( KU+1+I-J, J )
148:    30       CONTINUE
149:    40    CONTINUE
150:          EQUED = 'R'
151:       ELSE
152: *
153: *        Row and column scaling
154: *
155:          DO 60 J = 1, N
156:             CJ = C( J )
157:             DO 50 I = MAX( 1, J-KU ), MIN( M, J+KL )
158:                AB( KU+1+I-J, J ) = CJ*R( I )*AB( KU+1+I-J, J )
159:    50       CONTINUE
160:    60    CONTINUE
161:          EQUED = 'B'
162:       END IF
163: *
164:       RETURN
165: *
166: *     End of SLAQGB
167: *
168:       END
169: