1 | SUBROUTINE STRSV(UPLO,TRANS,DIAG,N,A,LDA,X,INCX) |
---|
2 | * .. Scalar Arguments .. |
---|
3 | INTEGER INCX,LDA,N |
---|
4 | CHARACTER DIAG,TRANS,UPLO |
---|
5 | * .. |
---|
6 | * .. Array Arguments .. |
---|
7 | REAL A(LDA,*),X(*) |
---|
8 | * .. |
---|
9 | * |
---|
10 | * Purpose |
---|
11 | * ======= |
---|
12 | * |
---|
13 | * STRSV solves one of the systems of equations |
---|
14 | * |
---|
15 | * A*x = b, or A'*x = b, |
---|
16 | * |
---|
17 | * where b and x are n element vectors and A is an n by n unit, or |
---|
18 | * non-unit, upper or lower triangular matrix. |
---|
19 | * |
---|
20 | * No test for singularity or near-singularity is included in this |
---|
21 | * routine. Such tests must be performed before calling this routine. |
---|
22 | * |
---|
23 | * Arguments |
---|
24 | * ========== |
---|
25 | * |
---|
26 | * UPLO - CHARACTER*1. |
---|
27 | * On entry, UPLO specifies whether the matrix is an upper or |
---|
28 | * lower triangular matrix as follows: |
---|
29 | * |
---|
30 | * UPLO = 'U' or 'u' A is an upper triangular matrix. |
---|
31 | * |
---|
32 | * UPLO = 'L' or 'l' A is a lower triangular matrix. |
---|
33 | * |
---|
34 | * Unchanged on exit. |
---|
35 | * |
---|
36 | * TRANS - CHARACTER*1. |
---|
37 | * On entry, TRANS specifies the equations to be solved as |
---|
38 | * follows: |
---|
39 | * |
---|
40 | * TRANS = 'N' or 'n' A*x = b. |
---|
41 | * |
---|
42 | * TRANS = 'T' or 't' A'*x = b. |
---|
43 | * |
---|
44 | * TRANS = 'C' or 'c' A'*x = b. |
---|
45 | * |
---|
46 | * Unchanged on exit. |
---|
47 | * |
---|
48 | * DIAG - CHARACTER*1. |
---|
49 | * On entry, DIAG specifies whether or not A is unit |
---|
50 | * triangular as follows: |
---|
51 | * |
---|
52 | * DIAG = 'U' or 'u' A is assumed to be unit triangular. |
---|
53 | * |
---|
54 | * DIAG = 'N' or 'n' A is not assumed to be unit |
---|
55 | * triangular. |
---|
56 | * |
---|
57 | * Unchanged on exit. |
---|
58 | * |
---|
59 | * N - INTEGER. |
---|
60 | * On entry, N specifies the order of the matrix A. |
---|
61 | * N must be at least zero. |
---|
62 | * Unchanged on exit. |
---|
63 | * |
---|
64 | * A - REAL array of DIMENSION ( LDA, n ). |
---|
65 | * Before entry with UPLO = 'U' or 'u', the leading n by n |
---|
66 | * upper triangular part of the array A must contain the upper |
---|
67 | * triangular matrix and the strictly lower triangular part of |
---|
68 | * A is not referenced. |
---|
69 | * Before entry with UPLO = 'L' or 'l', the leading n by n |
---|
70 | * lower triangular part of the array A must contain the lower |
---|
71 | * triangular matrix and the strictly upper triangular part of |
---|
72 | * A is not referenced. |
---|
73 | * Note that when DIAG = 'U' or 'u', the diagonal elements of |
---|
74 | * A are not referenced either, but are assumed to be unity. |
---|
75 | * Unchanged on exit. |
---|
76 | * |
---|
77 | * LDA - INTEGER. |
---|
78 | * On entry, LDA specifies the first dimension of A as declared |
---|
79 | * in the calling (sub) program. LDA must be at least |
---|
80 | * max( 1, n ). |
---|
81 | * Unchanged on exit. |
---|
82 | * |
---|
83 | * X - REAL array of dimension at least |
---|
84 | * ( 1 + ( n - 1 )*abs( INCX ) ). |
---|
85 | * Before entry, the incremented array X must contain the n |
---|
86 | * element right-hand side vector b. On exit, X is overwritten |
---|
87 | * with the solution vector x. |
---|
88 | * |
---|
89 | * INCX - INTEGER. |
---|
90 | * On entry, INCX specifies the increment for the elements of |
---|
91 | * X. INCX must not be zero. |
---|
92 | * Unchanged on exit. |
---|
93 | * |
---|
94 | * |
---|
95 | * Level 2 Blas routine. |
---|
96 | * |
---|
97 | * -- Written on 22-October-1986. |
---|
98 | * Jack Dongarra, Argonne National Lab. |
---|
99 | * Jeremy Du Croz, Nag Central Office. |
---|
100 | * Sven Hammarling, Nag Central Office. |
---|
101 | * Richard Hanson, Sandia National Labs. |
---|
102 | * |
---|
103 | * |
---|
104 | * .. Parameters .. |
---|
105 | REAL ZERO |
---|
106 | PARAMETER (ZERO=0.0E+0) |
---|
107 | * .. |
---|
108 | * .. Local Scalars .. |
---|
109 | REAL TEMP |
---|
110 | INTEGER I,INFO,IX,J,JX,KX |
---|
111 | LOGICAL NOUNIT |
---|
112 | * .. |
---|
113 | * .. External Functions .. |
---|
114 | LOGICAL LSAME |
---|
115 | EXTERNAL LSAME |
---|
116 | * .. |
---|
117 | * .. External Subroutines .. |
---|
118 | EXTERNAL XERBLA |
---|
119 | * .. |
---|
120 | * .. Intrinsic Functions .. |
---|
121 | INTRINSIC MAX |
---|
122 | * .. |
---|
123 | * |
---|
124 | * Test the input parameters. |
---|
125 | * |
---|
126 | INFO = 0 |
---|
127 | IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN |
---|
128 | INFO = 1 |
---|
129 | ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND. |
---|
130 | + .NOT.LSAME(TRANS,'C')) THEN |
---|
131 | INFO = 2 |
---|
132 | ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN |
---|
133 | INFO = 3 |
---|
134 | ELSE IF (N.LT.0) THEN |
---|
135 | INFO = 4 |
---|
136 | ELSE IF (LDA.LT.MAX(1,N)) THEN |
---|
137 | INFO = 6 |
---|
138 | ELSE IF (INCX.EQ.0) THEN |
---|
139 | INFO = 8 |
---|
140 | END IF |
---|
141 | IF (INFO.NE.0) THEN |
---|
142 | CALL XERBLA('STRSV ',INFO) |
---|
143 | RETURN |
---|
144 | END IF |
---|
145 | * |
---|
146 | * Quick return if possible. |
---|
147 | * |
---|
148 | IF (N.EQ.0) RETURN |
---|
149 | * |
---|
150 | NOUNIT = LSAME(DIAG,'N') |
---|
151 | * |
---|
152 | * Set up the start point in X if the increment is not unity. This |
---|
153 | * will be ( N - 1 )*INCX too small for descending loops. |
---|
154 | * |
---|
155 | IF (INCX.LE.0) THEN |
---|
156 | KX = 1 - (N-1)*INCX |
---|
157 | ELSE IF (INCX.NE.1) THEN |
---|
158 | KX = 1 |
---|
159 | END IF |
---|
160 | * |
---|
161 | * Start the operations. In this version the elements of A are |
---|
162 | * accessed sequentially with one pass through A. |
---|
163 | * |
---|
164 | IF (LSAME(TRANS,'N')) THEN |
---|
165 | * |
---|
166 | * Form x := inv( A )*x. |
---|
167 | * |
---|
168 | IF (LSAME(UPLO,'U')) THEN |
---|
169 | IF (INCX.EQ.1) THEN |
---|
170 | DO 20 J = N,1,-1 |
---|
171 | IF (X(J).NE.ZERO) THEN |
---|
172 | IF (NOUNIT) X(J) = X(J)/A(J,J) |
---|
173 | TEMP = X(J) |
---|
174 | DO 10 I = J - 1,1,-1 |
---|
175 | X(I) = X(I) - TEMP*A(I,J) |
---|
176 | 10 CONTINUE |
---|
177 | END IF |
---|
178 | 20 CONTINUE |
---|
179 | ELSE |
---|
180 | JX = KX + (N-1)*INCX |
---|
181 | DO 40 J = N,1,-1 |
---|
182 | IF (X(JX).NE.ZERO) THEN |
---|
183 | IF (NOUNIT) X(JX) = X(JX)/A(J,J) |
---|
184 | TEMP = X(JX) |
---|
185 | IX = JX |
---|
186 | DO 30 I = J - 1,1,-1 |
---|
187 | IX = IX - INCX |
---|
188 | X(IX) = X(IX) - TEMP*A(I,J) |
---|
189 | 30 CONTINUE |
---|
190 | END IF |
---|
191 | JX = JX - INCX |
---|
192 | 40 CONTINUE |
---|
193 | END IF |
---|
194 | ELSE |
---|
195 | IF (INCX.EQ.1) THEN |
---|
196 | DO 60 J = 1,N |
---|
197 | IF (X(J).NE.ZERO) THEN |
---|
198 | IF (NOUNIT) X(J) = X(J)/A(J,J) |
---|
199 | TEMP = X(J) |
---|
200 | DO 50 I = J + 1,N |
---|
201 | X(I) = X(I) - TEMP*A(I,J) |
---|
202 | 50 CONTINUE |
---|
203 | END IF |
---|
204 | 60 CONTINUE |
---|
205 | ELSE |
---|
206 | JX = KX |
---|
207 | DO 80 J = 1,N |
---|
208 | IF (X(JX).NE.ZERO) THEN |
---|
209 | IF (NOUNIT) X(JX) = X(JX)/A(J,J) |
---|
210 | TEMP = X(JX) |
---|
211 | IX = JX |
---|
212 | DO 70 I = J + 1,N |
---|
213 | IX = IX + INCX |
---|
214 | X(IX) = X(IX) - TEMP*A(I,J) |
---|
215 | 70 CONTINUE |
---|
216 | END IF |
---|
217 | JX = JX + INCX |
---|
218 | 80 CONTINUE |
---|
219 | END IF |
---|
220 | END IF |
---|
221 | ELSE |
---|
222 | * |
---|
223 | * Form x := inv( A' )*x. |
---|
224 | * |
---|
225 | IF (LSAME(UPLO,'U')) THEN |
---|
226 | IF (INCX.EQ.1) THEN |
---|
227 | DO 100 J = 1,N |
---|
228 | TEMP = X(J) |
---|
229 | DO 90 I = 1,J - 1 |
---|
230 | TEMP = TEMP - A(I,J)*X(I) |
---|
231 | 90 CONTINUE |
---|
232 | IF (NOUNIT) TEMP = TEMP/A(J,J) |
---|
233 | X(J) = TEMP |
---|
234 | 100 CONTINUE |
---|
235 | ELSE |
---|
236 | JX = KX |
---|
237 | DO 120 J = 1,N |
---|
238 | TEMP = X(JX) |
---|
239 | IX = KX |
---|
240 | DO 110 I = 1,J - 1 |
---|
241 | TEMP = TEMP - A(I,J)*X(IX) |
---|
242 | IX = IX + INCX |
---|
243 | 110 CONTINUE |
---|
244 | IF (NOUNIT) TEMP = TEMP/A(J,J) |
---|
245 | X(JX) = TEMP |
---|
246 | JX = JX + INCX |
---|
247 | 120 CONTINUE |
---|
248 | END IF |
---|
249 | ELSE |
---|
250 | IF (INCX.EQ.1) THEN |
---|
251 | DO 140 J = N,1,-1 |
---|
252 | TEMP = X(J) |
---|
253 | DO 130 I = N,J + 1,-1 |
---|
254 | TEMP = TEMP - A(I,J)*X(I) |
---|
255 | 130 CONTINUE |
---|
256 | IF (NOUNIT) TEMP = TEMP/A(J,J) |
---|
257 | X(J) = TEMP |
---|
258 | 140 CONTINUE |
---|
259 | ELSE |
---|
260 | KX = KX + (N-1)*INCX |
---|
261 | JX = KX |
---|
262 | DO 160 J = N,1,-1 |
---|
263 | TEMP = X(JX) |
---|
264 | IX = KX |
---|
265 | DO 150 I = N,J + 1,-1 |
---|
266 | TEMP = TEMP - A(I,J)*X(IX) |
---|
267 | IX = IX - INCX |
---|
268 | 150 CONTINUE |
---|
269 | IF (NOUNIT) TEMP = TEMP/A(J,J) |
---|
270 | X(JX) = TEMP |
---|
271 | JX = JX - INCX |
---|
272 | 160 CONTINUE |
---|
273 | END IF |
---|
274 | END IF |
---|
275 | END IF |
---|
276 | * |
---|
277 | RETURN |
---|
278 | * |
---|
279 | * End of STRSV . |
---|
280 | * |
---|
281 | END |
---|