001:       SUBROUTINE SGBTF2( M, N, KL, KU, AB, LDAB, IPIV, 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:       INTEGER            INFO, KL, KU, LDAB, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       INTEGER            IPIV( * )
012:       REAL               AB( LDAB, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  SGBTF2 computes an LU factorization of a real m-by-n band matrix A
019: *  using partial pivoting with row interchanges.
020: *
021: *  This is the unblocked version of the algorithm, calling Level 2 BLAS.
022: *
023: *  Arguments
024: *  =========
025: *
026: *  M       (input) INTEGER
027: *          The number of rows of the matrix A.  M >= 0.
028: *
029: *  N       (input) INTEGER
030: *          The number of columns of the matrix A.  N >= 0.
031: *
032: *  KL      (input) INTEGER
033: *          The number of subdiagonals within the band of A.  KL >= 0.
034: *
035: *  KU      (input) INTEGER
036: *          The number of superdiagonals within the band of A.  KU >= 0.
037: *
038: *  AB      (input/output) REAL array, dimension (LDAB,N)
039: *          On entry, the matrix A in band storage, in rows KL+1 to
040: *          2*KL+KU+1; rows 1 to KL of the array need not be set.
041: *          The j-th column of A is stored in the j-th column of the
042: *          array AB as follows:
043: *          AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl)
044: *
045: *          On exit, details of the factorization: U is stored as an
046: *          upper triangular band matrix with KL+KU superdiagonals in
047: *          rows 1 to KL+KU+1, and the multipliers used during the
048: *          factorization are stored in rows KL+KU+2 to 2*KL+KU+1.
049: *          See below for further details.
050: *
051: *  LDAB    (input) INTEGER
052: *          The leading dimension of the array AB.  LDAB >= 2*KL+KU+1.
053: *
054: *  IPIV    (output) INTEGER array, dimension (min(M,N))
055: *          The pivot indices; for 1 <= i <= min(M,N), row i of the
056: *          matrix was interchanged with row IPIV(i).
057: *
058: *  INFO    (output) INTEGER
059: *          = 0: successful exit
060: *          < 0: if INFO = -i, the i-th argument had an illegal value
061: *          > 0: if INFO = +i, U(i,i) is exactly zero. The factorization
062: *               has been completed, but the factor U is exactly
063: *               singular, and division by zero will occur if it is used
064: *               to solve a system of equations.
065: *
066: *  Further Details
067: *  ===============
068: *
069: *  The band storage scheme is illustrated by the following example, when
070: *  M = N = 6, KL = 2, KU = 1:
071: *
072: *  On entry:                       On exit:
073: *
074: *      *    *    *    +    +    +       *    *    *   u14  u25  u36
075: *      *    *    +    +    +    +       *    *   u13  u24  u35  u46
076: *      *   a12  a23  a34  a45  a56      *   u12  u23  u34  u45  u56
077: *     a11  a22  a33  a44  a55  a66     u11  u22  u33  u44  u55  u66
078: *     a21  a32  a43  a54  a65   *      m21  m32  m43  m54  m65   *
079: *     a31  a42  a53  a64   *    *      m31  m42  m53  m64   *    *
080: *
081: *  Array elements marked * are not used by the routine; elements marked
082: *  + need not be set on entry, but are required by the routine to store
083: *  elements of U, because of fill-in resulting from the row
084: *  interchanges.
085: *
086: *  =====================================================================
087: *
088: *     .. Parameters ..
089:       REAL               ONE, ZERO
090:       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
091: *     ..
092: *     .. Local Scalars ..
093:       INTEGER            I, J, JP, JU, KM, KV
094: *     ..
095: *     .. External Functions ..
096:       INTEGER            ISAMAX
097:       EXTERNAL           ISAMAX
098: *     ..
099: *     .. External Subroutines ..
100:       EXTERNAL           SGER, SSCAL, SSWAP, XERBLA
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC          MAX, MIN
104: *     ..
105: *     .. Executable Statements ..
106: *
107: *     KV is the number of superdiagonals in the factor U, allowing for
108: *     fill-in.
109: *
110:       KV = KU + KL
111: *
112: *     Test the input parameters.
113: *
114:       INFO = 0
115:       IF( M.LT.0 ) THEN
116:          INFO = -1
117:       ELSE IF( N.LT.0 ) THEN
118:          INFO = -2
119:       ELSE IF( KL.LT.0 ) THEN
120:          INFO = -3
121:       ELSE IF( KU.LT.0 ) THEN
122:          INFO = -4
123:       ELSE IF( LDAB.LT.KL+KV+1 ) THEN
124:          INFO = -6
125:       END IF
126:       IF( INFO.NE.0 ) THEN
127:          CALL XERBLA( 'SGBTF2', -INFO )
128:          RETURN
129:       END IF
130: *
131: *     Quick return if possible
132: *
133:       IF( M.EQ.0 .OR. N.EQ.0 )
134:      $   RETURN
135: *
136: *     Gaussian elimination with partial pivoting
137: *
138: *     Set fill-in elements in columns KU+2 to KV to zero.
139: *
140:       DO 20 J = KU + 2, MIN( KV, N )
141:          DO 10 I = KV - J + 2, KL
142:             AB( I, J ) = ZERO
143:    10    CONTINUE
144:    20 CONTINUE
145: *
146: *     JU is the index of the last column affected by the current stage
147: *     of the factorization.
148: *
149:       JU = 1
150: *
151:       DO 40 J = 1, MIN( M, N )
152: *
153: *        Set fill-in elements in column J+KV to zero.
154: *
155:          IF( J+KV.LE.N ) THEN
156:             DO 30 I = 1, KL
157:                AB( I, J+KV ) = ZERO
158:    30       CONTINUE
159:          END IF
160: *
161: *        Find pivot and test for singularity. KM is the number of
162: *        subdiagonal elements in the current column.
163: *
164:          KM = MIN( KL, M-J )
165:          JP = ISAMAX( KM+1, AB( KV+1, J ), 1 )
166:          IPIV( J ) = JP + J - 1
167:          IF( AB( KV+JP, J ).NE.ZERO ) THEN
168:             JU = MAX( JU, MIN( J+KU+JP-1, N ) )
169: *
170: *           Apply interchange to columns J to JU.
171: *
172:             IF( JP.NE.1 )
173:      $         CALL SSWAP( JU-J+1, AB( KV+JP, J ), LDAB-1,
174:      $                     AB( KV+1, J ), LDAB-1 )
175: *
176:             IF( KM.GT.0 ) THEN
177: *
178: *              Compute multipliers.
179: *
180:                CALL SSCAL( KM, ONE / AB( KV+1, J ), AB( KV+2, J ), 1 )
181: *
182: *              Update trailing submatrix within the band.
183: *
184:                IF( JU.GT.J )
185:      $            CALL SGER( KM, JU-J, -ONE, AB( KV+2, J ), 1,
186:      $                       AB( KV, J+1 ), LDAB-1, AB( KV+1, J+1 ),
187:      $                       LDAB-1 )
188:             END IF
189:          ELSE
190: *
191: *           If pivot is zero, set INFO to the index of the pivot
192: *           unless a zero pivot has already been found.
193: *
194:             IF( INFO.EQ.0 )
195:      $         INFO = J
196:          END IF
197:    40 CONTINUE
198:       RETURN
199: *
200: *     End of SGBTF2
201: *
202:       END
203: