2
SUBROUTINE CTRSV (UPLO, TRANS, DIAG, N, A, LDA, X, INCX)
3
C***BEGIN PROLOGUE CTRSV
4
C***PURPOSE Solve a complex triangular system of equations.
5
C***LIBRARY SLATEC (BLAS)
7
C***TYPE COMPLEX (STRSV-S, DTRSV-D, CTRSV-C)
8
C***KEYWORDS LEVEL 2 BLAS, LINEAR ALGEBRA
9
C***AUTHOR Dongarra, J. J., (ANL)
11
C Hammarling, S., (NAG)
12
C Hanson, R. J., (SNLA)
15
C CTRSV solves one of the systems of equations
17
C A*x = b, or A'*x = b, or conjg( A')*x = b,
19
C where b and x are n element vectors and A is an n by n unit, or
20
C non-unit, upper or lower triangular matrix.
22
C No test for singularity or near-singularity is included in this
23
C routine. Such tests must be performed before calling this routine.
29
C On entry, UPLO specifies whether the matrix is an upper or
30
C lower triangular matrix as follows:
32
C UPLO = 'U' or 'u' A is an upper triangular matrix.
34
C UPLO = 'L' or 'l' A is a lower triangular matrix.
38
C TRANS - CHARACTER*1.
39
C On entry, TRANS specifies the equations to be solved as
42
C TRANS = 'N' or 'n' A*x = b.
44
C TRANS = 'T' or 't' A'*x = b.
46
C TRANS = 'C' or 'c' conjg( A' )*x = b.
51
C On entry, DIAG specifies whether or not A is unit
52
C triangular as follows:
54
C DIAG = 'U' or 'u' A is assumed to be unit triangular.
56
C DIAG = 'N' or 'n' A is not assumed to be unit
62
C On entry, N specifies the order of the matrix A.
63
C N must be at least zero.
66
C A - COMPLEX array of DIMENSION ( LDA, n ).
67
C Before entry with UPLO = 'U' or 'u', the leading n by n
68
C upper triangular part of the array A must contain the upper
69
C triangular matrix and the strictly lower triangular part of
70
C A is not referenced.
71
C Before entry with UPLO = 'L' or 'l', the leading n by n
72
C lower triangular part of the array A must contain the lower
73
C triangular matrix and the strictly upper triangular part of
74
C A is not referenced.
75
C Note that when DIAG = 'U' or 'u', the diagonal elements of
76
C A are not referenced either, but are assumed to be unity.
80
C On entry, LDA specifies the first dimension of A as declared
81
C in the calling (sub) program. LDA must be at least
85
C X - COMPLEX array of dimension at least
86
C ( 1 + ( n - 1 )*abs( INCX ) ).
87
C Before entry, the incremented array X must contain the n
88
C element right-hand side vector b. On exit, X is overwritten
89
C with the solution vector x.
92
C On entry, INCX specifies the increment for the elements of
93
C X. INCX must not be zero.
96
C***REFERENCES Dongarra, J. J., Du Croz, J., Hammarling, S., and
97
C Hanson, R. J. An extended set of Fortran basic linear
98
C algebra subprograms. ACM TOMS, Vol. 14, No. 1,
99
C pp. 1-17, March 1988.
100
C***ROUTINES CALLED LSAME, XERBLA
101
C***REVISION HISTORY (YYMMDD)
102
C 861022 DATE WRITTEN
103
C 910605 Modified to meet SLATEC prologue standards. Only comment
104
C lines were modified. (BKS)
105
C***END PROLOGUE CTRSV
106
C .. Scalar Arguments ..
108
CHARACTER*1 DIAG, TRANS, UPLO
109
C .. Array Arguments ..
110
COMPLEX A( LDA, * ), X( * )
113
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
114
C .. Local Scalars ..
116
INTEGER I, INFO, IX, J, JX, KX
117
LOGICAL NOCONJ, NOUNIT
118
C .. External Functions ..
121
C .. External Subroutines ..
123
C .. Intrinsic Functions ..
125
C***FIRST EXECUTABLE STATEMENT CTRSV
127
C Test the input parameters.
130
IF ( .NOT.LSAME( UPLO , 'U' ).AND.
131
$ .NOT.LSAME( UPLO , 'L' ) )THEN
133
ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.
134
$ .NOT.LSAME( TRANS, 'T' ).AND.
135
$ .NOT.LSAME( TRANS, 'C' ) )THEN
137
ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.
138
$ .NOT.LSAME( DIAG , 'N' ) )THEN
140
ELSE IF( N.LT.0 )THEN
142
ELSE IF( LDA.LT.MAX( 1, N ) )THEN
144
ELSE IF( INCX.EQ.0 )THEN
148
CALL XERBLA( 'CTRSV ', INFO )
152
C Quick return if possible.
157
NOCONJ = LSAME( TRANS, 'T' )
158
NOUNIT = LSAME( DIAG , 'N' )
160
C Set up the start point in X if the increment is not unity. This
161
C will be ( N - 1 )*INCX too small for descending loops.
164
KX = 1 - ( N - 1 )*INCX
165
ELSE IF( INCX.NE.1 )THEN
169
C Start the operations. In this version the elements of A are
170
C accessed sequentially with one pass through A.
172
IF( LSAME( TRANS, 'N' ) )THEN
174
C Form x := inv( A )*x.
176
IF( LSAME( UPLO, 'U' ) )THEN
179
IF( X( J ).NE.ZERO )THEN
181
$ X( J ) = X( J )/A( J, J )
183
DO 10, I = J - 1, 1, -1
184
X( I ) = X( I ) - TEMP*A( I, J )
189
JX = KX + ( N - 1 )*INCX
191
IF( X( JX ).NE.ZERO )THEN
193
$ X( JX ) = X( JX )/A( J, J )
196
DO 30, I = J - 1, 1, -1
198
X( IX ) = X( IX ) - TEMP*A( I, J )
207
IF( X( J ).NE.ZERO )THEN
209
$ X( J ) = X( J )/A( J, J )
212
X( I ) = X( I ) - TEMP*A( I, J )
219
IF( X( JX ).NE.ZERO )THEN
221
$ X( JX ) = X( JX )/A( J, J )
226
X( IX ) = X( IX ) - TEMP*A( I, J )
235
C Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.
237
IF( LSAME( UPLO, 'U' ) )THEN
243
TEMP = TEMP - A( I, J )*X( I )
246
$ TEMP = TEMP/A( J, J )
249
TEMP = TEMP - CONJG( A( I, J ) )*X( I )
252
$ TEMP = TEMP/CONJG( A( J, J ) )
263
TEMP = TEMP - A( I, J )*X( IX )
267
$ TEMP = TEMP/A( J, J )
270
TEMP = TEMP - CONJG( A( I, J ) )*X( IX )
274
$ TEMP = TEMP/CONJG( A( J, J ) )
285
DO 150, I = N, J + 1, -1
286
TEMP = TEMP - A( I, J )*X( I )
289
$ TEMP = TEMP/A( J, J )
291
DO 160, I = N, J + 1, -1
292
TEMP = TEMP - CONJG( A( I, J ) )*X( I )
295
$ TEMP = TEMP/CONJG( A( J, J ) )
300
KX = KX + ( N - 1 )*INCX
306
DO 180, I = N, J + 1, -1
307
TEMP = TEMP - A( I, J )*X( IX )
311
$ TEMP = TEMP/A( J, J )
313
DO 190, I = N, J + 1, -1
314
TEMP = TEMP - CONJG( A( I, J ) )*X( IX )
318
$ TEMP = TEMP/CONJG( A( J, J ) )