1 /* dlasy2.f -- translated by f2c (version 20061008).
2 You must link the resulting object file with libf2c:
3 on Microsoft Windows system, link with libf2c.lib;
4 on Linux or Unix systems, link with .../path/to/libf2c.a -lm
5 or, if you install libf2c.a in a standard place, with -lf2c -lm
6 -- in that order, at the end of the command line, as in
7 cc *.o -lf2c -lm
8 Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
9
10 http://www.netlib.org/f2c/libf2c.zip
11 */
12
13 #include "f2c.h"
14 #include "blaswrap.h"
15
16 /* Table of constant values */
17
18 static integer c__4 = 4;
19 static integer c__1 = 1;
20 static integer c__16 = 16;
21 static integer c__0 = 0;
22
dlasy2_(logical * ltranl,logical * ltranr,integer * isgn,integer * n1,integer * n2,doublereal * tl,integer * ldtl,doublereal * tr,integer * ldtr,doublereal * b,integer * ldb,doublereal * scale,doublereal * x,integer * ldx,doublereal * xnorm,integer * info)23 /* Subroutine */ int dlasy2_(logical *ltranl, logical *ltranr, integer *isgn,
24 integer *n1, integer *n2, doublereal *tl, integer *ldtl, doublereal *
25 tr, integer *ldtr, doublereal *b, integer *ldb, doublereal *scale,
26 doublereal *x, integer *ldx, doublereal *xnorm, integer *info)
27 {
28 /* Initialized data */
29
30 static integer locu12[4] = { 3,4,1,2 };
31 static integer locl21[4] = { 2,1,4,3 };
32 static integer locu22[4] = { 4,3,2,1 };
33 static logical xswpiv[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
34 static logical bswpiv[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
35
36 /* System generated locals */
37 integer b_dim1, b_offset, tl_dim1, tl_offset, tr_dim1, tr_offset, x_dim1,
38 x_offset;
39 doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
40
41 /* Local variables */
42 integer i__, j, k;
43 doublereal x2[2], l21, u11, u12;
44 integer ip, jp;
45 doublereal u22, t16[16] /* was [4][4] */, gam, bet, eps, sgn, tmp[4],
46 tau1, btmp[4], smin;
47 integer ipiv;
48 doublereal temp;
49 integer jpiv[4];
50 doublereal xmax;
51 integer ipsv, jpsv;
52 logical bswap;
53 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
54 doublereal *, integer *), dswap_(integer *, doublereal *, integer
55 *, doublereal *, integer *);
56 logical xswap;
57 extern doublereal dlamch_(char *);
58 extern integer idamax_(integer *, doublereal *, integer *);
59 doublereal smlnum;
60
61
62 /* -- LAPACK auxiliary routine (version 3.2) -- */
63 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
64 /* November 2006 */
65
66 /* .. Scalar Arguments .. */
67 /* .. */
68 /* .. Array Arguments .. */
69 /* .. */
70
71 /* Purpose */
72 /* ======= */
73
74 /* DLASY2 solves for the N1 by N2 matrix X, 1 <= N1,N2 <= 2, in */
75
76 /* op(TL)*X + ISGN*X*op(TR) = SCALE*B, */
77
78 /* where TL is N1 by N1, TR is N2 by N2, B is N1 by N2, and ISGN = 1 or */
79 /* -1. op(T) = T or T', where T' denotes the transpose of T. */
80
81 /* Arguments */
82 /* ========= */
83
84 /* LTRANL (input) LOGICAL */
85 /* On entry, LTRANL specifies the op(TL): */
86 /* = .FALSE., op(TL) = TL, */
87 /* = .TRUE., op(TL) = TL'. */
88
89 /* LTRANR (input) LOGICAL */
90 /* On entry, LTRANR specifies the op(TR): */
91 /* = .FALSE., op(TR) = TR, */
92 /* = .TRUE., op(TR) = TR'. */
93
94 /* ISGN (input) INTEGER */
95 /* On entry, ISGN specifies the sign of the equation */
96 /* as described before. ISGN may only be 1 or -1. */
97
98 /* N1 (input) INTEGER */
99 /* On entry, N1 specifies the order of matrix TL. */
100 /* N1 may only be 0, 1 or 2. */
101
102 /* N2 (input) INTEGER */
103 /* On entry, N2 specifies the order of matrix TR. */
104 /* N2 may only be 0, 1 or 2. */
105
106 /* TL (input) DOUBLE PRECISION array, dimension (LDTL,2) */
107 /* On entry, TL contains an N1 by N1 matrix. */
108
109 /* LDTL (input) INTEGER */
110 /* The leading dimension of the matrix TL. LDTL >= max(1,N1). */
111
112 /* TR (input) DOUBLE PRECISION array, dimension (LDTR,2) */
113 /* On entry, TR contains an N2 by N2 matrix. */
114
115 /* LDTR (input) INTEGER */
116 /* The leading dimension of the matrix TR. LDTR >= max(1,N2). */
117
118 /* B (input) DOUBLE PRECISION array, dimension (LDB,2) */
119 /* On entry, the N1 by N2 matrix B contains the right-hand */
120 /* side of the equation. */
121
122 /* LDB (input) INTEGER */
123 /* The leading dimension of the matrix B. LDB >= max(1,N1). */
124
125 /* SCALE (output) DOUBLE PRECISION */
126 /* On exit, SCALE contains the scale factor. SCALE is chosen */
127 /* less than or equal to 1 to prevent the solution overflowing. */
128
129 /* X (output) DOUBLE PRECISION array, dimension (LDX,2) */
130 /* On exit, X contains the N1 by N2 solution. */
131
132 /* LDX (input) INTEGER */
133 /* The leading dimension of the matrix X. LDX >= max(1,N1). */
134
135 /* XNORM (output) DOUBLE PRECISION */
136 /* On exit, XNORM is the infinity-norm of the solution. */
137
138 /* INFO (output) INTEGER */
139 /* On exit, INFO is set to */
140 /* 0: successful exit. */
141 /* 1: TL and TR have too close eigenvalues, so TL or */
142 /* TR is perturbed to get a nonsingular equation. */
143 /* NOTE: In the interests of speed, this routine does not */
144 /* check the inputs for errors. */
145
146 /* ===================================================================== */
147
148 /* .. Parameters .. */
149 /* .. */
150 /* .. Local Scalars .. */
151 /* .. */
152 /* .. Local Arrays .. */
153 /* .. */
154 /* .. External Functions .. */
155 /* .. */
156 /* .. External Subroutines .. */
157 /* .. */
158 /* .. Intrinsic Functions .. */
159 /* .. */
160 /* .. Data statements .. */
161 /* Parameter adjustments */
162 tl_dim1 = *ldtl;
163 tl_offset = 1 + tl_dim1;
164 tl -= tl_offset;
165 tr_dim1 = *ldtr;
166 tr_offset = 1 + tr_dim1;
167 tr -= tr_offset;
168 b_dim1 = *ldb;
169 b_offset = 1 + b_dim1;
170 b -= b_offset;
171 x_dim1 = *ldx;
172 x_offset = 1 + x_dim1;
173 x -= x_offset;
174
175 /* Function Body */
176 /* .. */
177 /* .. Executable Statements .. */
178
179 /* Do not check the input parameters for errors */
180
181 *info = 0;
182
183 /* Quick return if possible */
184
185 if (*n1 == 0 || *n2 == 0) {
186 return 0;
187 }
188
189 /* Set constants to control overflow */
190
191 eps = dlamch_("P");
192 smlnum = dlamch_("S") / eps;
193 sgn = (doublereal) (*isgn);
194
195 k = *n1 + *n1 + *n2 - 2;
196 switch (k) {
197 case 1: goto L10;
198 case 2: goto L20;
199 case 3: goto L30;
200 case 4: goto L50;
201 }
202
203 /* 1 by 1: TL11*X + SGN*X*TR11 = B11 */
204
205 L10:
206 tau1 = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
207 bet = abs(tau1);
208 if (bet <= smlnum) {
209 tau1 = smlnum;
210 bet = smlnum;
211 *info = 1;
212 }
213
214 *scale = 1.;
215 gam = (d__1 = b[b_dim1 + 1], abs(d__1));
216 if (smlnum * gam > bet) {
217 *scale = 1. / gam;
218 }
219
220 x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / tau1;
221 *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
222 return 0;
223
224 /* 1 by 2: */
225 /* TL11*[X11 X12] + ISGN*[X11 X12]*op[TR11 TR12] = [B11 B12] */
226 /* [TR21 TR22] */
227
228 L20:
229
230 /* Computing MAX */
231 /* Computing MAX */
232 d__7 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__8 = (d__2 = tr[tr_dim1 + 1]
233 , abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tr[(tr_dim1 <<
234 1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tr[
235 tr_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
236 tr[(tr_dim1 << 1) + 2], abs(d__5));
237 d__6 = eps * max(d__7,d__8);
238 smin = max(d__6,smlnum);
239 tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
240 tmp[3] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
241 if (*ltranr) {
242 tmp[1] = sgn * tr[tr_dim1 + 2];
243 tmp[2] = sgn * tr[(tr_dim1 << 1) + 1];
244 } else {
245 tmp[1] = sgn * tr[(tr_dim1 << 1) + 1];
246 tmp[2] = sgn * tr[tr_dim1 + 2];
247 }
248 btmp[0] = b[b_dim1 + 1];
249 btmp[1] = b[(b_dim1 << 1) + 1];
250 goto L40;
251
252 /* 2 by 1: */
253 /* op[TL11 TL12]*[X11] + ISGN* [X11]*TR11 = [B11] */
254 /* [TL21 TL22] [X21] [X21] [B21] */
255
256 L30:
257 /* Computing MAX */
258 /* Computing MAX */
259 d__7 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__8 = (d__2 = tl[tl_dim1 + 1]
260 , abs(d__2)), d__7 = max(d__7,d__8), d__8 = (d__3 = tl[(tl_dim1 <<
261 1) + 1], abs(d__3)), d__7 = max(d__7,d__8), d__8 = (d__4 = tl[
262 tl_dim1 + 2], abs(d__4)), d__7 = max(d__7,d__8), d__8 = (d__5 =
263 tl[(tl_dim1 << 1) + 2], abs(d__5));
264 d__6 = eps * max(d__7,d__8);
265 smin = max(d__6,smlnum);
266 tmp[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
267 tmp[3] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
268 if (*ltranl) {
269 tmp[1] = tl[(tl_dim1 << 1) + 1];
270 tmp[2] = tl[tl_dim1 + 2];
271 } else {
272 tmp[1] = tl[tl_dim1 + 2];
273 tmp[2] = tl[(tl_dim1 << 1) + 1];
274 }
275 btmp[0] = b[b_dim1 + 1];
276 btmp[1] = b[b_dim1 + 2];
277 L40:
278
279 /* Solve 2 by 2 system using complete pivoting. */
280 /* Set pivots less than SMIN to SMIN. */
281
282 ipiv = idamax_(&c__4, tmp, &c__1);
283 u11 = tmp[ipiv - 1];
284 if (abs(u11) <= smin) {
285 *info = 1;
286 u11 = smin;
287 }
288 u12 = tmp[locu12[ipiv - 1] - 1];
289 l21 = tmp[locl21[ipiv - 1] - 1] / u11;
290 u22 = tmp[locu22[ipiv - 1] - 1] - u12 * l21;
291 xswap = xswpiv[ipiv - 1];
292 bswap = bswpiv[ipiv - 1];
293 if (abs(u22) <= smin) {
294 *info = 1;
295 u22 = smin;
296 }
297 if (bswap) {
298 temp = btmp[1];
299 btmp[1] = btmp[0] - l21 * temp;
300 btmp[0] = temp;
301 } else {
302 btmp[1] -= l21 * btmp[0];
303 }
304 *scale = 1.;
305 if (smlnum * 2. * abs(btmp[1]) > abs(u22) || smlnum * 2. * abs(btmp[0]) >
306 abs(u11)) {
307 /* Computing MAX */
308 d__1 = abs(btmp[0]), d__2 = abs(btmp[1]);
309 *scale = .5 / max(d__1,d__2);
310 btmp[0] *= *scale;
311 btmp[1] *= *scale;
312 }
313 x2[1] = btmp[1] / u22;
314 x2[0] = btmp[0] / u11 - u12 / u11 * x2[1];
315 if (xswap) {
316 temp = x2[1];
317 x2[1] = x2[0];
318 x2[0] = temp;
319 }
320 x[x_dim1 + 1] = x2[0];
321 if (*n1 == 1) {
322 x[(x_dim1 << 1) + 1] = x2[1];
323 *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 << 1)
324 + 1], abs(d__2));
325 } else {
326 x[x_dim1 + 2] = x2[1];
327 /* Computing MAX */
328 d__3 = (d__1 = x[x_dim1 + 1], abs(d__1)), d__4 = (d__2 = x[x_dim1 + 2]
329 , abs(d__2));
330 *xnorm = max(d__3,d__4);
331 }
332 return 0;
333
334 /* 2 by 2: */
335 /* op[TL11 TL12]*[X11 X12] +ISGN* [X11 X12]*op[TR11 TR12] = [B11 B12] */
336 /* [TL21 TL22] [X21 X22] [X21 X22] [TR21 TR22] [B21 B22] */
337
338 /* Solve equivalent 4 by 4 system using complete pivoting. */
339 /* Set pivots less than SMIN to SMIN. */
340
341 L50:
342 /* Computing MAX */
343 d__5 = (d__1 = tr[tr_dim1 + 1], abs(d__1)), d__6 = (d__2 = tr[(tr_dim1 <<
344 1) + 1], abs(d__2)), d__5 = max(d__5,d__6), d__6 = (d__3 = tr[
345 tr_dim1 + 2], abs(d__3)), d__5 = max(d__5,d__6), d__6 = (d__4 =
346 tr[(tr_dim1 << 1) + 2], abs(d__4));
347 smin = max(d__5,d__6);
348 /* Computing MAX */
349 d__5 = smin, d__6 = (d__1 = tl[tl_dim1 + 1], abs(d__1)), d__5 = max(d__5,
350 d__6), d__6 = (d__2 = tl[(tl_dim1 << 1) + 1], abs(d__2)), d__5 =
351 max(d__5,d__6), d__6 = (d__3 = tl[tl_dim1 + 2], abs(d__3)), d__5 =
352 max(d__5,d__6), d__6 = (d__4 = tl[(tl_dim1 << 1) + 2], abs(d__4))
353 ;
354 smin = max(d__5,d__6);
355 /* Computing MAX */
356 d__1 = eps * smin;
357 smin = max(d__1,smlnum);
358 btmp[0] = 0.;
359 dcopy_(&c__16, btmp, &c__0, t16, &c__1);
360 t16[0] = tl[tl_dim1 + 1] + sgn * tr[tr_dim1 + 1];
361 t16[5] = tl[(tl_dim1 << 1) + 2] + sgn * tr[tr_dim1 + 1];
362 t16[10] = tl[tl_dim1 + 1] + sgn * tr[(tr_dim1 << 1) + 2];
363 t16[15] = tl[(tl_dim1 << 1) + 2] + sgn * tr[(tr_dim1 << 1) + 2];
364 if (*ltranl) {
365 t16[4] = tl[tl_dim1 + 2];
366 t16[1] = tl[(tl_dim1 << 1) + 1];
367 t16[14] = tl[tl_dim1 + 2];
368 t16[11] = tl[(tl_dim1 << 1) + 1];
369 } else {
370 t16[4] = tl[(tl_dim1 << 1) + 1];
371 t16[1] = tl[tl_dim1 + 2];
372 t16[14] = tl[(tl_dim1 << 1) + 1];
373 t16[11] = tl[tl_dim1 + 2];
374 }
375 if (*ltranr) {
376 t16[8] = sgn * tr[(tr_dim1 << 1) + 1];
377 t16[13] = sgn * tr[(tr_dim1 << 1) + 1];
378 t16[2] = sgn * tr[tr_dim1 + 2];
379 t16[7] = sgn * tr[tr_dim1 + 2];
380 } else {
381 t16[8] = sgn * tr[tr_dim1 + 2];
382 t16[13] = sgn * tr[tr_dim1 + 2];
383 t16[2] = sgn * tr[(tr_dim1 << 1) + 1];
384 t16[7] = sgn * tr[(tr_dim1 << 1) + 1];
385 }
386 btmp[0] = b[b_dim1 + 1];
387 btmp[1] = b[b_dim1 + 2];
388 btmp[2] = b[(b_dim1 << 1) + 1];
389 btmp[3] = b[(b_dim1 << 1) + 2];
390
391 /* Perform elimination */
392
393 for (i__ = 1; i__ <= 3; ++i__) {
394 xmax = 0.;
395 for (ip = i__; ip <= 4; ++ip) {
396 for (jp = i__; jp <= 4; ++jp) {
397 if ((d__1 = t16[ip + (jp << 2) - 5], abs(d__1)) >= xmax) {
398 xmax = (d__1 = t16[ip + (jp << 2) - 5], abs(d__1));
399 ipsv = ip;
400 jpsv = jp;
401 }
402 /* L60: */
403 }
404 /* L70: */
405 }
406 if (ipsv != i__) {
407 dswap_(&c__4, &t16[ipsv - 1], &c__4, &t16[i__ - 1], &c__4);
408 temp = btmp[i__ - 1];
409 btmp[i__ - 1] = btmp[ipsv - 1];
410 btmp[ipsv - 1] = temp;
411 }
412 if (jpsv != i__) {
413 dswap_(&c__4, &t16[(jpsv << 2) - 4], &c__1, &t16[(i__ << 2) - 4],
414 &c__1);
415 }
416 jpiv[i__ - 1] = jpsv;
417 if ((d__1 = t16[i__ + (i__ << 2) - 5], abs(d__1)) < smin) {
418 *info = 1;
419 t16[i__ + (i__ << 2) - 5] = smin;
420 }
421 for (j = i__ + 1; j <= 4; ++j) {
422 t16[j + (i__ << 2) - 5] /= t16[i__ + (i__ << 2) - 5];
423 btmp[j - 1] -= t16[j + (i__ << 2) - 5] * btmp[i__ - 1];
424 for (k = i__ + 1; k <= 4; ++k) {
425 t16[j + (k << 2) - 5] -= t16[j + (i__ << 2) - 5] * t16[i__ + (
426 k << 2) - 5];
427 /* L80: */
428 }
429 /* L90: */
430 }
431 /* L100: */
432 }
433 if (abs(t16[15]) < smin) {
434 t16[15] = smin;
435 }
436 *scale = 1.;
437 if (smlnum * 8. * abs(btmp[0]) > abs(t16[0]) || smlnum * 8. * abs(btmp[1])
438 > abs(t16[5]) || smlnum * 8. * abs(btmp[2]) > abs(t16[10]) ||
439 smlnum * 8. * abs(btmp[3]) > abs(t16[15])) {
440 /* Computing MAX */
441 d__1 = abs(btmp[0]), d__2 = abs(btmp[1]), d__1 = max(d__1,d__2), d__2
442 = abs(btmp[2]), d__1 = max(d__1,d__2), d__2 = abs(btmp[3]);
443 *scale = .125 / max(d__1,d__2);
444 btmp[0] *= *scale;
445 btmp[1] *= *scale;
446 btmp[2] *= *scale;
447 btmp[3] *= *scale;
448 }
449 for (i__ = 1; i__ <= 4; ++i__) {
450 k = 5 - i__;
451 temp = 1. / t16[k + (k << 2) - 5];
452 tmp[k - 1] = btmp[k - 1] * temp;
453 for (j = k + 1; j <= 4; ++j) {
454 tmp[k - 1] -= temp * t16[k + (j << 2) - 5] * tmp[j - 1];
455 /* L110: */
456 }
457 /* L120: */
458 }
459 for (i__ = 1; i__ <= 3; ++i__) {
460 if (jpiv[4 - i__ - 1] != 4 - i__) {
461 temp = tmp[4 - i__ - 1];
462 tmp[4 - i__ - 1] = tmp[jpiv[4 - i__ - 1] - 1];
463 tmp[jpiv[4 - i__ - 1] - 1] = temp;
464 }
465 /* L130: */
466 }
467 x[x_dim1 + 1] = tmp[0];
468 x[x_dim1 + 2] = tmp[1];
469 x[(x_dim1 << 1) + 1] = tmp[2];
470 x[(x_dim1 << 1) + 2] = tmp[3];
471 /* Computing MAX */
472 d__1 = abs(tmp[0]) + abs(tmp[2]), d__2 = abs(tmp[1]) + abs(tmp[3]);
473 *xnorm = max(d__1,d__2);
474 return 0;
475
476 /* End of DLASY2 */
477
478 } /* dlasy2_ */
479