001:       SUBROUTINE CTRTRS( 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:       COMPLEX            A( LDA, * ), B( LDB, * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  CTRTRS solves a triangular system of the form
021: *
022: *     A * X = B,  A**T * X = B,  or  A**H * 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)
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) COMPLEX 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) COMPLEX 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:       COMPLEX            ZERO, ONE
082:       PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ),
083:      $                   ONE = ( 1.0E+0, 0.0E+0 ) )
084: *     ..
085: *     .. Local Scalars ..
086:       LOGICAL            NOUNIT
087: *     ..
088: *     .. External Functions ..
089:       LOGICAL            LSAME
090:       EXTERNAL           LSAME
091: *     ..
092: *     .. External Subroutines ..
093:       EXTERNAL           CTRSM, XERBLA
094: *     ..
095: *     .. Intrinsic Functions ..
096:       INTRINSIC          MAX
097: *     ..
098: *     .. Executable Statements ..
099: *
100: *     Test the input parameters.
101: *
102:       INFO = 0
103:       NOUNIT = LSAME( DIAG, 'N' )
104:       IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
105:          INFO = -1
106:       ELSE IF( .NOT.LSAME( TRANS, 'N' ) .AND. .NOT.
107:      $         LSAME( TRANS, 'T' ) .AND. .NOT.LSAME( TRANS, 'C' ) ) THEN
108:          INFO = -2
109:       ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
110:          INFO = -3
111:       ELSE IF( N.LT.0 ) THEN
112:          INFO = -4
113:       ELSE IF( NRHS.LT.0 ) THEN
114:          INFO = -5
115:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
116:          INFO = -7
117:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
118:          INFO = -9
119:       END IF
120:       IF( INFO.NE.0 ) THEN
121:          CALL XERBLA( 'CTRTRS', -INFO )
122:          RETURN
123:       END IF
124: *
125: *     Quick return if possible
126: *
127:       IF( N.EQ.0 )
128:      $   RETURN
129: *
130: *     Check for singularity.
131: *
132:       IF( NOUNIT ) THEN
133:          DO 10 INFO = 1, N
134:             IF( A( INFO, INFO ).EQ.ZERO )
135:      $         RETURN
136:    10    CONTINUE
137:       END IF
138:       INFO = 0
139: *
140: *     Solve A * x = b,  A**T * x = b,  or  A**H * x = b.
141: *
142:       CALL CTRSM( 'Left', UPLO, TRANS, DIAG, N, NRHS, ONE, A, LDA, B,
143:      $            LDB )
144: *
145:       RETURN
146: *
147: *     End of CTRTRS
148: *
149:       END
150: