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