```001:       SUBROUTINE DGBSV( N, KL, KU, NRHS, AB, LDAB, IPIV, B, LDB, INFO )
002: *
003: *  -- LAPACK driver 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, LDB, N, NRHS
009: *     ..
010: *     .. Array Arguments ..
011:       INTEGER            IPIV( * )
012:       DOUBLE PRECISION   AB( LDAB, * ), B( LDB, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DGBSV computes the solution to a real system of linear equations
019: *  A * X = B, where A is a band matrix of order N with KL subdiagonals
020: *  and KU superdiagonals, and X and B are N-by-NRHS matrices.
021: *
022: *  The LU decomposition with partial pivoting and row interchanges is
023: *  used to factor A as A = L * U, where L is a product of permutation
024: *  and unit lower triangular matrices with KL subdiagonals, and U is
025: *  upper triangular with KL+KU superdiagonals.  The factored form of A
026: *  is then used to solve the system of equations A * X = B.
027: *
028: *  Arguments
029: *  =========
030: *
031: *  N       (input) INTEGER
032: *          The number of linear equations, i.e., the order of the
033: *          matrix A.  N >= 0.
034: *
035: *  KL      (input) INTEGER
036: *          The number of subdiagonals within the band of A.  KL >= 0.
037: *
038: *  KU      (input) INTEGER
039: *          The number of superdiagonals within the band of A.  KU >= 0.
040: *
041: *  NRHS    (input) INTEGER
042: *          The number of right hand sides, i.e., the number of columns
043: *          of the matrix B.  NRHS >= 0.
044: *
045: *  AB      (input/output) DOUBLE PRECISION array, dimension (LDAB,N)
046: *          On entry, the matrix A in band storage, in rows KL+1 to
047: *          2*KL+KU+1; rows 1 to KL of the array need not be set.
048: *          The j-th column of A is stored in the j-th column of the
049: *          array AB as follows:
050: *          AB(KL+KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+KL)
051: *          On exit, details of the factorization: U is stored as an
052: *          upper triangular band matrix with KL+KU superdiagonals in
053: *          rows 1 to KL+KU+1, and the multipliers used during the
054: *          factorization are stored in rows KL+KU+2 to 2*KL+KU+1.
055: *          See below for further details.
056: *
057: *  LDAB    (input) INTEGER
058: *          The leading dimension of the array AB.  LDAB >= 2*KL+KU+1.
059: *
060: *  IPIV    (output) INTEGER array, dimension (N)
061: *          The pivot indices that define the permutation matrix P;
062: *          row i of the matrix was interchanged with row IPIV(i).
063: *
064: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
065: *          On entry, the N-by-NRHS right hand side matrix B.
066: *          On exit, if INFO = 0, the N-by-NRHS solution matrix X.
067: *
068: *  LDB     (input) INTEGER
069: *          The leading dimension of the array B.  LDB >= max(1,N).
070: *
071: *  INFO    (output) INTEGER
072: *          = 0:  successful exit
073: *          < 0:  if INFO = -i, the i-th argument had an illegal value
074: *          > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
075: *                has been completed, but the factor U is exactly
076: *                singular, and the solution has not been computed.
077: *
078: *  Further Details
079: *  ===============
080: *
081: *  The band storage scheme is illustrated by the following example, when
082: *  M = N = 6, KL = 2, KU = 1:
083: *
084: *  On entry:                       On exit:
085: *
086: *      *    *    *    +    +    +       *    *    *   u14  u25  u36
087: *      *    *    +    +    +    +       *    *   u13  u24  u35  u46
088: *      *   a12  a23  a34  a45  a56      *   u12  u23  u34  u45  u56
089: *     a11  a22  a33  a44  a55  a66     u11  u22  u33  u44  u55  u66
090: *     a21  a32  a43  a54  a65   *      m21  m32  m43  m54  m65   *
091: *     a31  a42  a53  a64   *    *      m31  m42  m53  m64   *    *
092: *
093: *  Array elements marked * are not used by the routine; elements marked
094: *  + need not be set on entry, but are required by the routine to store
095: *  elements of U because of fill-in resulting from the row interchanges.
096: *
097: *  =====================================================================
098: *
099: *     .. External Subroutines ..
100:       EXTERNAL           DGBTRF, DGBTRS, XERBLA
101: *     ..
102: *     .. Intrinsic Functions ..
103:       INTRINSIC          MAX
104: *     ..
105: *     .. Executable Statements ..
106: *
107: *     Test the input parameters.
108: *
109:       INFO = 0
110:       IF( N.LT.0 ) THEN
111:          INFO = -1
112:       ELSE IF( KL.LT.0 ) THEN
113:          INFO = -2
114:       ELSE IF( KU.LT.0 ) THEN
115:          INFO = -3
116:       ELSE IF( NRHS.LT.0 ) THEN
117:          INFO = -4
118:       ELSE IF( LDAB.LT.2*KL+KU+1 ) THEN
119:          INFO = -6
120:       ELSE IF( LDB.LT.MAX( N, 1 ) ) THEN
121:          INFO = -9
122:       END IF
123:       IF( INFO.NE.0 ) THEN
124:          CALL XERBLA( 'DGBSV ', -INFO )
125:          RETURN
126:       END IF
127: *
128: *     Compute the LU factorization of the band matrix A.
129: *
130:       CALL DGBTRF( N, N, KL, KU, AB, LDAB, IPIV, INFO )
131:       IF( INFO.EQ.0 ) THEN
132: *
133: *        Solve the system A*X = B, overwriting B with X.
134: *
135:          CALL DGBTRS( 'No transpose', N, KL, KU, NRHS, AB, LDAB, IPIV,
136:      \$                B, LDB, INFO )
137:       END IF
138:       RETURN
139: *
140: *     End of DGBSV
141: *
142:       END
143: ```