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