001:       SUBROUTINE STRTRS( UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB,
002:      $                   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, LDA, LDB, N, NRHS
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               A( LDA, * ), B( LDB, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  STRTRS solves a triangular system of the form
020: *
021: *     A * X = B  or  A**T * X = B,
022: *
023: *  where A is a triangular matrix of order N, and B is an N-by-NRHS
024: *  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 of 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: *  NRHS    (input) INTEGER
047: *          The number of right hand sides, i.e., the number of columns
048: *          of the matrix B.  NRHS >= 0.
049: *
050: *  A       (input) REAL array, dimension (LDA,N)
051: *          The triangular matrix A.  If UPLO = 'U', the leading N-by-N
052: *          upper triangular part of the array A contains the upper
053: *          triangular matrix, and the strictly lower triangular part of
054: *          A is not referenced.  If UPLO = 'L', the leading N-by-N lower
055: *          triangular part of the array A contains the lower triangular
056: *          matrix, and the strictly upper triangular part of A is not
057: *          referenced.  If DIAG = 'U', the diagonal elements of A are
058: *          also not referenced and are assumed to be 1.
059: *
060: *  LDA     (input) INTEGER
061: *          The leading dimension of the array A.  LDA >= max(1,N).
062: *
063: *  B       (input/output) REAL array, dimension (LDB,NRHS)
064: *          On entry, the right hand side matrix B.
065: *          On exit, if INFO = 0, the solution matrix X.
066: *
067: *  LDB     (input) INTEGER
068: *          The leading dimension of the array B.  LDB >= max(1,N).
069: *
070: *  INFO    (output) INTEGER
071: *          = 0:  successful exit
072: *          < 0: if INFO = -i, the i-th argument had an illegal value
073: *          > 0: if INFO = i, the i-th diagonal element of A is zero,
074: *               indicating that the matrix is singular and the solutions
075: *               X have not been computed.
076: *
077: *  =====================================================================
078: *
079: *     .. Parameters ..
080:       REAL               ZERO, ONE
081:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
082: *     ..
083: *     .. Local Scalars ..
084:       LOGICAL            NOUNIT
085: *     ..
086: *     .. External Functions ..
087:       LOGICAL            LSAME
088:       EXTERNAL           LSAME
089: *     ..
090: *     .. External Subroutines ..
091:       EXTERNAL           STRSM, XERBLA
092: *     ..
093: *     .. Intrinsic Functions ..
094:       INTRINSIC          MAX
095: *     ..
096: *     .. Executable Statements ..
097: *
098: *     Test the input parameters.
099: *
100:       INFO = 0
101:       NOUNIT = LSAME( DIAG, 'N' )
102:       IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
103:          INFO = -1
104:       ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.
105:      $         LSAME( TRANS, 'T' ) .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN
106:          INFO = -2
107:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
108:          INFO = -3
109:       ELSE IF( N.LT.0 ) THEN
110:          INFO = -4
111:       ELSE IF( NRHS.LT.0 ) THEN
112:          INFO = -5
113:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
114:          INFO = -7
115:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
116:          INFO = -9
117:       END IF
118:       IF( INFO.NE.0 ) THEN
119:          CALL XERBLA( 'STRTRS', -INFO )
120:          RETURN
121:       END IF
122: *
123: *     Quick return if possible
124: *
125:       IF( N.EQ.0 )
126:      $   RETURN
127: *
128: *     Check for singularity.
129: *
130:       IF( NOUNIT ) THEN
131:          DO 10 INFO = 1, N
132:             IF( A( INFO, INFO ).EQ.ZERO )
133:      $         RETURN
134:    10    CONTINUE
135:       END IF
136:       INFO = 0
137: *
138: *     Solve A * x = b  or  A' * x = b.
139: *
140:       CALL STRSM( 'Left', UPLO, TRANS, DIAG, N, NRHS, ONE, A, LDA, B,
141:      $            LDB )
142: *
143:       RETURN
144: *
145: *     End of STRTRS
146: *
147:       END
148: