1 /* ./src_f77/slagts.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
slagts_(integer * job,integer * n,real * a,real * b,real * c__,real * d__,integer * in,real * y,real * tol,integer * info)8 /* Subroutine */ int slagts_(integer *job, integer *n, real *a, real *b, real
9 *c__, real *d__, integer *in, real *y, real *tol, integer *info)
10 {
11 /* System generated locals */
12 integer i__1;
13 real r__1, r__2, r__3, r__4, r__5;
14
15 /* Builtin functions */
16 double r_sign(real *, real *);
17
18 /* Local variables */
19 static integer k;
20 static real ak, eps, temp, pert, absak, sfmin;
21 extern doublereal slamch_(char *, ftnlen);
22 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
23 static real bignum;
24
25
26 /* -- LAPACK auxiliary routine (version 3.0) -- */
27 /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
28 /* Courant Institute, Argonne National Lab, and Rice University */
29 /* October 31, 1992 */
30
31 /* .. Scalar Arguments .. */
32 /* .. */
33 /* .. Array Arguments .. */
34 /* .. */
35
36 /* Purpose */
37 /* ======= */
38
39 /* SLAGTS may be used to solve one of the systems of equations */
40
41 /* (T - lambda*I)*x = y or (T - lambda*I)'*x = y, */
42
43 /* where T is an n by n tridiagonal matrix, for x, following the */
44 /* factorization of (T - lambda*I) as */
45
46 /* (T - lambda*I) = P*L*U , */
47
48 /* by routine SLAGTF. The choice of equation to be solved is */
49 /* controlled by the argument JOB, and in each case there is an option */
50 /* to perturb zero or very small diagonal elements of U, this option */
51 /* being intended for use in applications such as inverse iteration. */
52
53 /* Arguments */
54 /* ========= */
55
56 /* JOB (input) INTEGER */
57 /* Specifies the job to be performed by SLAGTS as follows: */
58 /* = 1: The equations (T - lambda*I)x = y are to be solved, */
59 /* but diagonal elements of U are not to be perturbed. */
60 /* = -1: The equations (T - lambda*I)x = y are to be solved */
61 /* and, if overflow would otherwise occur, the diagonal */
62 /* elements of U are to be perturbed. See argument TOL */
63 /* below. */
64 /* = 2: The equations (T - lambda*I)'x = y are to be solved, */
65 /* but diagonal elements of U are not to be perturbed. */
66 /* = -2: The equations (T - lambda*I)'x = y are to be solved */
67 /* and, if overflow would otherwise occur, the diagonal */
68 /* elements of U are to be perturbed. See argument TOL */
69 /* below. */
70
71 /* N (input) INTEGER */
72 /* The order of the matrix T. */
73
74 /* A (input) REAL array, dimension (N) */
75 /* On entry, A must contain the diagonal elements of U as */
76 /* returned from SLAGTF. */
77
78 /* B (input) REAL array, dimension (N-1) */
79 /* On entry, B must contain the first super-diagonal elements of */
80 /* U as returned from SLAGTF. */
81
82 /* C (input) REAL array, dimension (N-1) */
83 /* On entry, C must contain the sub-diagonal elements of L as */
84 /* returned from SLAGTF. */
85
86 /* D (input) REAL array, dimension (N-2) */
87 /* On entry, D must contain the second super-diagonal elements */
88 /* of U as returned from SLAGTF. */
89
90 /* IN (input) INTEGER array, dimension (N) */
91 /* On entry, IN must contain details of the matrix P as returned */
92 /* from SLAGTF. */
93
94 /* Y (input/output) REAL array, dimension (N) */
95 /* On entry, the right hand side vector y. */
96 /* On exit, Y is overwritten by the solution vector x. */
97
98 /* TOL (input/output) REAL */
99 /* On entry, with JOB .lt. 0, TOL should be the minimum */
100 /* perturbation to be made to very small diagonal elements of U. */
101 /* TOL should normally be chosen as about eps*norm(U), where eps */
102 /* is the relative machine precision, but if TOL is supplied as */
103 /* non-positive, then it is reset to eps*max( abs( u(i,j) ) ). */
104 /* If JOB .gt. 0 then TOL is not referenced. */
105
106 /* On exit, TOL is changed as described above, only if TOL is */
107 /* non-positive on entry. Otherwise TOL is unchanged. */
108
109 /* INFO (output) INTEGER */
110 /* = 0 : successful exit */
111 /* .lt. 0: if INFO = -i, the i-th argument had an illegal value */
112 /* .gt. 0: overflow would occur when computing the INFO(th) */
113 /* element of the solution vector x. This can only occur */
114 /* when JOB is supplied as positive and either means */
115 /* that a diagonal element of U is very small, or that */
116 /* the elements of the right-hand side vector y are very */
117 /* large. */
118
119 /* ===================================================================== */
120
121 /* .. Parameters .. */
122 /* .. */
123 /* .. Local Scalars .. */
124 /* .. */
125 /* .. Intrinsic Functions .. */
126 /* .. */
127 /* .. External Functions .. */
128 /* .. */
129 /* .. External Subroutines .. */
130 /* .. */
131 /* .. Executable Statements .. */
132
133 /* Parameter adjustments */
134 --y;
135 --in;
136 --d__;
137 --c__;
138 --b;
139 --a;
140
141 /* Function Body */
142 *info = 0;
143 if (abs(*job) > 2 || *job == 0) {
144 *info = -1;
145 } else if (*n < 0) {
146 *info = -2;
147 }
148 if (*info != 0) {
149 i__1 = -(*info);
150 xerbla_("SLAGTS", &i__1, (ftnlen)6);
151 return 0;
152 }
153
154 if (*n == 0) {
155 return 0;
156 }
157
158 eps = slamch_("Epsilon", (ftnlen)7);
159 sfmin = slamch_("Safe minimum", (ftnlen)12);
160 bignum = 1.f / sfmin;
161
162 if (*job < 0) {
163 if (*tol <= 0.f) {
164 *tol = dabs(a[1]);
165 if (*n > 1) {
166 /* Computing MAX */
167 r__1 = *tol, r__2 = dabs(a[2]), r__1 = max(r__1,r__2), r__2 =
168 dabs(b[1]);
169 *tol = dmax(r__1,r__2);
170 }
171 i__1 = *n;
172 for (k = 3; k <= i__1; ++k) {
173 /* Computing MAX */
174 r__4 = *tol, r__5 = (r__1 = a[k], dabs(r__1)), r__4 = max(
175 r__4,r__5), r__5 = (r__2 = b[k - 1], dabs(r__2)),
176 r__4 = max(r__4,r__5), r__5 = (r__3 = d__[k - 2],
177 dabs(r__3));
178 *tol = dmax(r__4,r__5);
179 /* L10: */
180 }
181 *tol *= eps;
182 if (*tol == 0.f) {
183 *tol = eps;
184 }
185 }
186 }
187
188 if (abs(*job) == 1) {
189 i__1 = *n;
190 for (k = 2; k <= i__1; ++k) {
191 if (in[k - 1] == 0) {
192 y[k] -= c__[k - 1] * y[k - 1];
193 } else {
194 temp = y[k - 1];
195 y[k - 1] = y[k];
196 y[k] = temp - c__[k - 1] * y[k];
197 }
198 /* L20: */
199 }
200 if (*job == 1) {
201 for (k = *n; k >= 1; --k) {
202 if (k <= *n - 2) {
203 temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
204 } else if (k == *n - 1) {
205 temp = y[k] - b[k] * y[k + 1];
206 } else {
207 temp = y[k];
208 }
209 ak = a[k];
210 absak = dabs(ak);
211 if (absak < 1.f) {
212 if (absak < sfmin) {
213 if (absak == 0.f || dabs(temp) * sfmin > absak) {
214 *info = k;
215 return 0;
216 } else {
217 temp *= bignum;
218 ak *= bignum;
219 }
220 } else if (dabs(temp) > absak * bignum) {
221 *info = k;
222 return 0;
223 }
224 }
225 y[k] = temp / ak;
226 /* L30: */
227 }
228 } else {
229 for (k = *n; k >= 1; --k) {
230 if (k <= *n - 2) {
231 temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
232 } else if (k == *n - 1) {
233 temp = y[k] - b[k] * y[k + 1];
234 } else {
235 temp = y[k];
236 }
237 ak = a[k];
238 pert = r_sign(tol, &ak);
239 L40:
240 absak = dabs(ak);
241 if (absak < 1.f) {
242 if (absak < sfmin) {
243 if (absak == 0.f || dabs(temp) * sfmin > absak) {
244 ak += pert;
245 pert *= 2;
246 goto L40;
247 } else {
248 temp *= bignum;
249 ak *= bignum;
250 }
251 } else if (dabs(temp) > absak * bignum) {
252 ak += pert;
253 pert *= 2;
254 goto L40;
255 }
256 }
257 y[k] = temp / ak;
258 /* L50: */
259 }
260 }
261 } else {
262
263 /* Come to here if JOB = 2 or -2 */
264
265 if (*job == 2) {
266 i__1 = *n;
267 for (k = 1; k <= i__1; ++k) {
268 if (k >= 3) {
269 temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
270 } else if (k == 2) {
271 temp = y[k] - b[k - 1] * y[k - 1];
272 } else {
273 temp = y[k];
274 }
275 ak = a[k];
276 absak = dabs(ak);
277 if (absak < 1.f) {
278 if (absak < sfmin) {
279 if (absak == 0.f || dabs(temp) * sfmin > absak) {
280 *info = k;
281 return 0;
282 } else {
283 temp *= bignum;
284 ak *= bignum;
285 }
286 } else if (dabs(temp) > absak * bignum) {
287 *info = k;
288 return 0;
289 }
290 }
291 y[k] = temp / ak;
292 /* L60: */
293 }
294 } else {
295 i__1 = *n;
296 for (k = 1; k <= i__1; ++k) {
297 if (k >= 3) {
298 temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
299 } else if (k == 2) {
300 temp = y[k] - b[k - 1] * y[k - 1];
301 } else {
302 temp = y[k];
303 }
304 ak = a[k];
305 pert = r_sign(tol, &ak);
306 L70:
307 absak = dabs(ak);
308 if (absak < 1.f) {
309 if (absak < sfmin) {
310 if (absak == 0.f || dabs(temp) * sfmin > absak) {
311 ak += pert;
312 pert *= 2;
313 goto L70;
314 } else {
315 temp *= bignum;
316 ak *= bignum;
317 }
318 } else if (dabs(temp) > absak * bignum) {
319 ak += pert;
320 pert *= 2;
321 goto L70;
322 }
323 }
324 y[k] = temp / ak;
325 /* L80: */
326 }
327 }
328
329 for (k = *n; k >= 2; --k) {
330 if (in[k - 1] == 0) {
331 y[k - 1] -= c__[k - 1] * y[k];
332 } else {
333 temp = y[k - 1];
334 y[k - 1] = y[k];
335 y[k] = temp - c__[k - 1] * y[k];
336 }
337 /* L90: */
338 }
339 }
340
341 /* End of SLAGTS */
342
343 return 0;
344 } /* slagts_ */
345
346