001:       SUBROUTINE DTBTRS( UPLO, TRANS, DIAG, N, KD, NRHS, AB, LDAB, B,
002:      $                   LDB, INFO )
003: *
004: *  -- LAPACK routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          DIAG, TRANS, UPLO
010:       INTEGER            INFO, KD, LDAB, LDB, N, NRHS
011: *     ..
012: *     .. Array Arguments ..
013:       DOUBLE PRECISION   AB( LDAB, * ), B( LDB, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  DTBTRS solves a triangular system of the form
020: *
021: *     A * X = B  or  A**T * X = B,
022: *
023: *  where A is a triangular band matrix of order N, and B is an
024: *  N-by NRHS matrix.  A check is made to verify that A is nonsingular.
025: *
026: *  Arguments
027: *  =========
028: *
029: *  UPLO    (input) CHARACTER*1
030: *          = 'U':  A is upper triangular;
031: *          = 'L':  A is lower triangular.
032: *
033: *  TRANS   (input) CHARACTER*1
034: *          Specifies the form the system of equations:
035: *          = 'N':  A * X = B  (No transpose)
036: *          = 'T':  A**T * X = B  (Transpose)
037: *          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
038: *
039: *  DIAG    (input) CHARACTER*1
040: *          = 'N':  A is non-unit triangular;
041: *          = 'U':  A is unit triangular.
042: *
043: *  N       (input) INTEGER
044: *          The order of the matrix A.  N >= 0.
045: *
046: *  KD      (input) INTEGER
047: *          The number of superdiagonals or subdiagonals of the
048: *          triangular band matrix A.  KD >= 0.
049: *
050: *  NRHS    (input) INTEGER
051: *          The number of right hand sides, i.e., the number of columns
052: *          of the matrix B.  NRHS >= 0.
053: *
054: *  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N)
055: *          The upper or lower triangular band matrix A, stored in the
056: *          first kd+1 rows of AB.  The j-th column of A is stored
057: *          in the j-th column of the array AB as follows:
058: *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
059: *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
060: *          If DIAG = 'U', the diagonal elements of A are not referenced
061: *          and are assumed to be 1.
062: *
063: *  LDAB    (input) INTEGER
064: *          The leading dimension of the array AB.  LDAB >= KD+1.
065: *
066: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
067: *          On entry, the right hand side matrix B.
068: *          On exit, if INFO = 0, the solution matrix X.
069: *
070: *  LDB     (input) INTEGER
071: *          The leading dimension of the array B.  LDB >= max(1,N).
072: *
073: *  INFO    (output) INTEGER
074: *          = 0:  successful exit
075: *          < 0:  if INFO = -i, the i-th argument had an illegal value
076: *          > 0:  if INFO = i, the i-th diagonal element of A is zero,
077: *                indicating that the matrix is singular and the
078: *                solutions X have not been computed.
079: *
080: *  =====================================================================
081: *
082: *     .. Parameters ..
083:       DOUBLE PRECISION   ZERO
084:       PARAMETER          ( ZERO = 0.0D+0 )
085: *     ..
086: *     .. Local Scalars ..
087:       LOGICAL            NOUNIT, UPPER
088:       INTEGER            J
089: *     ..
090: *     .. External Functions ..
091:       LOGICAL            LSAME
092:       EXTERNAL           LSAME
093: *     ..
094: *     .. External Subroutines ..
095:       EXTERNAL           DTBSV, XERBLA
096: *     ..
097: *     .. Intrinsic Functions ..
098:       INTRINSIC          MAX
099: *     ..
100: *     .. Executable Statements ..
101: *
102: *     Test the input parameters.
103: *
104:       INFO = 0
105:       NOUNIT = LSAME( DIAG, 'N' )
106:       UPPER = LSAME( UPLO, 'U' )
107:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
108:          INFO = -1
109:       ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.
110:      $         LSAME( TRANS, 'T' ) .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN
111:          INFO = -2
112:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
113:          INFO = -3
114:       ELSE IF( N.LT.0 ) THEN
115:          INFO = -4
116:       ELSE IF( KD.LT.0 ) THEN
117:          INFO = -5
118:       ELSE IF( NRHS.LT.0 ) THEN
119:          INFO = -6
120:       ELSE IF( LDAB.LT.KD+1 ) THEN
121:          INFO = -8
122:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
123:          INFO = -10
124:       END IF
125:       IF( INFO.NE.0 ) THEN
126:          CALL XERBLA( 'DTBTRS', -INFO )
127:          RETURN
128:       END IF
129: *
130: *     Quick return if possible
131: *
132:       IF( N.EQ.0 )
133:      $   RETURN
134: *
135: *     Check for singularity.
136: *
137:       IF( NOUNIT ) THEN
138:          IF( UPPER ) THEN
139:             DO 10 INFO = 1, N
140:                IF( AB( KD+1, INFO ).EQ.ZERO )
141:      $            RETURN
142:    10       CONTINUE
143:          ELSE
144:             DO 20 INFO = 1, N
145:                IF( AB( 1, INFO ).EQ.ZERO )
146:      $            RETURN
147:    20       CONTINUE
148:          END IF
149:       END IF
150:       INFO = 0
151: *
152: *     Solve A * X = B  or  A' * X = B.
153: *
154:       DO 30 J = 1, NRHS
155:          CALL DTBSV( UPLO, TRANS, DIAG, N, KD, AB, LDAB, B( 1, J ), 1 )
156:    30 CONTINUE
157: *
158:       RETURN
159: *
160: *     End of DTBTRS
161: *
162:       END
163: