00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static logical c_false = FALSE_;
00020 static integer c__2 = 2;
00021 static real c_b21 = 1.f;
00022 static real c_b25 = 0.f;
00023 static logical c_true = TRUE_;
00024
00025 int slaqtr_(logical *ltran, logical *lreal, integer *n, real
00026 *t, integer *ldt, real *b, real *w, real *scale, real *x, real *work,
00027 integer *info)
00028 {
00029
00030 integer t_dim1, t_offset, i__1, i__2;
00031 real r__1, r__2, r__3, r__4, r__5, r__6;
00032
00033
00034 real d__[4] ;
00035 integer i__, j, k;
00036 real v[4] , z__;
00037 integer j1, j2, n1, n2;
00038 real si, xj, sr, rec, eps, tjj, tmp;
00039 integer ierr;
00040 real smin;
00041 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00042 real xmax;
00043 extern int sscal_(integer *, real *, real *, integer *);
00044 integer jnext;
00045 extern doublereal sasum_(integer *, real *, integer *);
00046 real sminw, xnorm;
00047 extern int saxpy_(integer *, real *, real *, integer *,
00048 real *, integer *), slaln2_(logical *, integer *, integer *, real
00049 *, real *, real *, integer *, real *, real *, real *, integer *,
00050 real *, real *, real *, integer *, real *, real *, integer *);
00051 real scaloc;
00052 extern doublereal slamch_(char *), slange_(char *, integer *,
00053 integer *, real *, integer *, real *);
00054 real bignum;
00055 extern integer isamax_(integer *, real *, integer *);
00056 extern int sladiv_(real *, real *, real *, real *, real *
00057 , real *);
00058 logical notran;
00059 real smlnum;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 t_dim1 = *ldt;
00173 t_offset = 1 + t_dim1;
00174 t -= t_offset;
00175 --b;
00176 --x;
00177 --work;
00178
00179
00180 notran = ! (*ltran);
00181 *info = 0;
00182
00183
00184
00185 if (*n == 0) {
00186 return 0;
00187 }
00188
00189
00190
00191 eps = slamch_("P");
00192 smlnum = slamch_("S") / eps;
00193 bignum = 1.f / smlnum;
00194
00195 xnorm = slange_("M", n, n, &t[t_offset], ldt, d__);
00196 if (! (*lreal)) {
00197
00198 r__1 = xnorm, r__2 = dabs(*w), r__1 = max(r__1,r__2), r__2 = slange_(
00199 "M", n, &c__1, &b[1], n, d__);
00200 xnorm = dmax(r__1,r__2);
00201 }
00202
00203 r__1 = smlnum, r__2 = eps * xnorm;
00204 smin = dmax(r__1,r__2);
00205
00206
00207
00208
00209 work[1] = 0.f;
00210 i__1 = *n;
00211 for (j = 2; j <= i__1; ++j) {
00212 i__2 = j - 1;
00213 work[j] = sasum_(&i__2, &t[j * t_dim1 + 1], &c__1);
00214
00215 }
00216
00217 if (! (*lreal)) {
00218 i__1 = *n;
00219 for (i__ = 2; i__ <= i__1; ++i__) {
00220 work[i__] += (r__1 = b[i__], dabs(r__1));
00221
00222 }
00223 }
00224
00225 n2 = *n << 1;
00226 n1 = *n;
00227 if (! (*lreal)) {
00228 n1 = n2;
00229 }
00230 k = isamax_(&n1, &x[1], &c__1);
00231 xmax = (r__1 = x[k], dabs(r__1));
00232 *scale = 1.f;
00233
00234 if (xmax > bignum) {
00235 *scale = bignum / xmax;
00236 sscal_(&n1, scale, &x[1], &c__1);
00237 xmax = bignum;
00238 }
00239
00240 if (*lreal) {
00241
00242 if (notran) {
00243
00244
00245
00246 jnext = *n;
00247 for (j = *n; j >= 1; --j) {
00248 if (j > jnext) {
00249 goto L30;
00250 }
00251 j1 = j;
00252 j2 = j;
00253 jnext = j - 1;
00254 if (j > 1) {
00255 if (t[j + (j - 1) * t_dim1] != 0.f) {
00256 j1 = j - 1;
00257 jnext = j - 2;
00258 }
00259 }
00260
00261 if (j1 == j2) {
00262
00263
00264
00265
00266
00267
00268 xj = (r__1 = x[j1], dabs(r__1));
00269 tjj = (r__1 = t[j1 + j1 * t_dim1], dabs(r__1));
00270 tmp = t[j1 + j1 * t_dim1];
00271 if (tjj < smin) {
00272 tmp = smin;
00273 tjj = smin;
00274 *info = 1;
00275 }
00276
00277 if (xj == 0.f) {
00278 goto L30;
00279 }
00280
00281 if (tjj < 1.f) {
00282 if (xj > bignum * tjj) {
00283 rec = 1.f / xj;
00284 sscal_(n, &rec, &x[1], &c__1);
00285 *scale *= rec;
00286 xmax *= rec;
00287 }
00288 }
00289 x[j1] /= tmp;
00290 xj = (r__1 = x[j1], dabs(r__1));
00291
00292
00293
00294
00295 if (xj > 1.f) {
00296 rec = 1.f / xj;
00297 if (work[j1] > (bignum - xmax) * rec) {
00298 sscal_(n, &rec, &x[1], &c__1);
00299 *scale *= rec;
00300 }
00301 }
00302 if (j1 > 1) {
00303 i__1 = j1 - 1;
00304 r__1 = -x[j1];
00305 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
00306 , &c__1);
00307 i__1 = j1 - 1;
00308 k = isamax_(&i__1, &x[1], &c__1);
00309 xmax = (r__1 = x[k], dabs(r__1));
00310 }
00311
00312 } else {
00313
00314
00315
00316
00317
00318
00319 d__[0] = x[j1];
00320 d__[1] = x[j2];
00321 slaln2_(&c_false, &c__2, &c__1, &smin, &c_b21, &t[j1 + j1
00322 * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
00323 c_b25, &c_b25, v, &c__2, &scaloc, &xnorm, &ierr);
00324 if (ierr != 0) {
00325 *info = 2;
00326 }
00327
00328 if (scaloc != 1.f) {
00329 sscal_(n, &scaloc, &x[1], &c__1);
00330 *scale *= scaloc;
00331 }
00332 x[j1] = v[0];
00333 x[j2] = v[1];
00334
00335
00336
00337
00338
00339 r__1 = dabs(v[0]), r__2 = dabs(v[1]);
00340 xj = dmax(r__1,r__2);
00341 if (xj > 1.f) {
00342 rec = 1.f / xj;
00343
00344 r__1 = work[j1], r__2 = work[j2];
00345 if (dmax(r__1,r__2) > (bignum - xmax) * rec) {
00346 sscal_(n, &rec, &x[1], &c__1);
00347 *scale *= rec;
00348 }
00349 }
00350
00351
00352
00353 if (j1 > 1) {
00354 i__1 = j1 - 1;
00355 r__1 = -x[j1];
00356 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
00357 , &c__1);
00358 i__1 = j1 - 1;
00359 r__1 = -x[j2];
00360 saxpy_(&i__1, &r__1, &t[j2 * t_dim1 + 1], &c__1, &x[1]
00361 , &c__1);
00362 i__1 = j1 - 1;
00363 k = isamax_(&i__1, &x[1], &c__1);
00364 xmax = (r__1 = x[k], dabs(r__1));
00365 }
00366
00367 }
00368
00369 L30:
00370 ;
00371 }
00372
00373 } else {
00374
00375
00376
00377 jnext = 1;
00378 i__1 = *n;
00379 for (j = 1; j <= i__1; ++j) {
00380 if (j < jnext) {
00381 goto L40;
00382 }
00383 j1 = j;
00384 j2 = j;
00385 jnext = j + 1;
00386 if (j < *n) {
00387 if (t[j + 1 + j * t_dim1] != 0.f) {
00388 j2 = j + 1;
00389 jnext = j + 2;
00390 }
00391 }
00392
00393 if (j1 == j2) {
00394
00395
00396
00397
00398
00399
00400 xj = (r__1 = x[j1], dabs(r__1));
00401 if (xmax > 1.f) {
00402 rec = 1.f / xmax;
00403 if (work[j1] > (bignum - xj) * rec) {
00404 sscal_(n, &rec, &x[1], &c__1);
00405 *scale *= rec;
00406 xmax *= rec;
00407 }
00408 }
00409
00410 i__2 = j1 - 1;
00411 x[j1] -= sdot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[1], &
00412 c__1);
00413
00414 xj = (r__1 = x[j1], dabs(r__1));
00415 tjj = (r__1 = t[j1 + j1 * t_dim1], dabs(r__1));
00416 tmp = t[j1 + j1 * t_dim1];
00417 if (tjj < smin) {
00418 tmp = smin;
00419 tjj = smin;
00420 *info = 1;
00421 }
00422
00423 if (tjj < 1.f) {
00424 if (xj > bignum * tjj) {
00425 rec = 1.f / xj;
00426 sscal_(n, &rec, &x[1], &c__1);
00427 *scale *= rec;
00428 xmax *= rec;
00429 }
00430 }
00431 x[j1] /= tmp;
00432
00433 r__2 = xmax, r__3 = (r__1 = x[j1], dabs(r__1));
00434 xmax = dmax(r__2,r__3);
00435
00436 } else {
00437
00438
00439
00440
00441
00442
00443
00444 r__3 = (r__1 = x[j1], dabs(r__1)), r__4 = (r__2 = x[j2],
00445 dabs(r__2));
00446 xj = dmax(r__3,r__4);
00447 if (xmax > 1.f) {
00448 rec = 1.f / xmax;
00449
00450 r__1 = work[j2], r__2 = work[j1];
00451 if (dmax(r__1,r__2) > (bignum - xj) * rec) {
00452 sscal_(n, &rec, &x[1], &c__1);
00453 *scale *= rec;
00454 xmax *= rec;
00455 }
00456 }
00457
00458 i__2 = j1 - 1;
00459 d__[0] = x[j1] - sdot_(&i__2, &t[j1 * t_dim1 + 1], &c__1,
00460 &x[1], &c__1);
00461 i__2 = j1 - 1;
00462 d__[1] = x[j2] - sdot_(&i__2, &t[j2 * t_dim1 + 1], &c__1,
00463 &x[1], &c__1);
00464
00465 slaln2_(&c_true, &c__2, &c__1, &smin, &c_b21, &t[j1 + j1 *
00466 t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &c_b25,
00467 &c_b25, v, &c__2, &scaloc, &xnorm, &ierr);
00468 if (ierr != 0) {
00469 *info = 2;
00470 }
00471
00472 if (scaloc != 1.f) {
00473 sscal_(n, &scaloc, &x[1], &c__1);
00474 *scale *= scaloc;
00475 }
00476 x[j1] = v[0];
00477 x[j2] = v[1];
00478
00479 r__3 = (r__1 = x[j1], dabs(r__1)), r__4 = (r__2 = x[j2],
00480 dabs(r__2)), r__3 = max(r__3,r__4);
00481 xmax = dmax(r__3,xmax);
00482
00483 }
00484 L40:
00485 ;
00486 }
00487 }
00488
00489 } else {
00490
00491
00492 r__1 = eps * dabs(*w);
00493 sminw = dmax(r__1,smin);
00494 if (notran) {
00495
00496
00497
00498 jnext = *n;
00499 for (j = *n; j >= 1; --j) {
00500 if (j > jnext) {
00501 goto L70;
00502 }
00503 j1 = j;
00504 j2 = j;
00505 jnext = j - 1;
00506 if (j > 1) {
00507 if (t[j + (j - 1) * t_dim1] != 0.f) {
00508 j1 = j - 1;
00509 jnext = j - 2;
00510 }
00511 }
00512
00513 if (j1 == j2) {
00514
00515
00516
00517
00518
00519 z__ = *w;
00520 if (j1 == 1) {
00521 z__ = b[1];
00522 }
00523 xj = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[*n + j1],
00524 dabs(r__2));
00525 tjj = (r__1 = t[j1 + j1 * t_dim1], dabs(r__1)) + dabs(z__)
00526 ;
00527 tmp = t[j1 + j1 * t_dim1];
00528 if (tjj < sminw) {
00529 tmp = sminw;
00530 tjj = sminw;
00531 *info = 1;
00532 }
00533
00534 if (xj == 0.f) {
00535 goto L70;
00536 }
00537
00538 if (tjj < 1.f) {
00539 if (xj > bignum * tjj) {
00540 rec = 1.f / xj;
00541 sscal_(&n2, &rec, &x[1], &c__1);
00542 *scale *= rec;
00543 xmax *= rec;
00544 }
00545 }
00546 sladiv_(&x[j1], &x[*n + j1], &tmp, &z__, &sr, &si);
00547 x[j1] = sr;
00548 x[*n + j1] = si;
00549 xj = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[*n + j1],
00550 dabs(r__2));
00551
00552
00553
00554
00555 if (xj > 1.f) {
00556 rec = 1.f / xj;
00557 if (work[j1] > (bignum - xmax) * rec) {
00558 sscal_(&n2, &rec, &x[1], &c__1);
00559 *scale *= rec;
00560 }
00561 }
00562
00563 if (j1 > 1) {
00564 i__1 = j1 - 1;
00565 r__1 = -x[j1];
00566 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
00567 , &c__1);
00568 i__1 = j1 - 1;
00569 r__1 = -x[*n + j1];
00570 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[*
00571 n + 1], &c__1);
00572
00573 x[1] += b[j1] * x[*n + j1];
00574 x[*n + 1] -= b[j1] * x[j1];
00575
00576 xmax = 0.f;
00577 i__1 = j1 - 1;
00578 for (k = 1; k <= i__1; ++k) {
00579
00580 r__3 = xmax, r__4 = (r__1 = x[k], dabs(r__1)) + (
00581 r__2 = x[k + *n], dabs(r__2));
00582 xmax = dmax(r__3,r__4);
00583
00584 }
00585 }
00586
00587 } else {
00588
00589
00590
00591 d__[0] = x[j1];
00592 d__[1] = x[j2];
00593 d__[2] = x[*n + j1];
00594 d__[3] = x[*n + j2];
00595 r__1 = -(*w);
00596 slaln2_(&c_false, &c__2, &c__2, &sminw, &c_b21, &t[j1 +
00597 j1 * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
00598 c_b25, &r__1, v, &c__2, &scaloc, &xnorm, &ierr);
00599 if (ierr != 0) {
00600 *info = 2;
00601 }
00602
00603 if (scaloc != 1.f) {
00604 i__1 = *n << 1;
00605 sscal_(&i__1, &scaloc, &x[1], &c__1);
00606 *scale = scaloc * *scale;
00607 }
00608 x[j1] = v[0];
00609 x[j2] = v[1];
00610 x[*n + j1] = v[2];
00611 x[*n + j2] = v[3];
00612
00613
00614
00615
00616
00617 r__1 = dabs(v[0]) + dabs(v[2]), r__2 = dabs(v[1]) + dabs(
00618 v[3]);
00619 xj = dmax(r__1,r__2);
00620 if (xj > 1.f) {
00621 rec = 1.f / xj;
00622
00623 r__1 = work[j1], r__2 = work[j2];
00624 if (dmax(r__1,r__2) > (bignum - xmax) * rec) {
00625 sscal_(&n2, &rec, &x[1], &c__1);
00626 *scale *= rec;
00627 }
00628 }
00629
00630
00631
00632 if (j1 > 1) {
00633 i__1 = j1 - 1;
00634 r__1 = -x[j1];
00635 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[1]
00636 , &c__1);
00637 i__1 = j1 - 1;
00638 r__1 = -x[j2];
00639 saxpy_(&i__1, &r__1, &t[j2 * t_dim1 + 1], &c__1, &x[1]
00640 , &c__1);
00641
00642 i__1 = j1 - 1;
00643 r__1 = -x[*n + j1];
00644 saxpy_(&i__1, &r__1, &t[j1 * t_dim1 + 1], &c__1, &x[*
00645 n + 1], &c__1);
00646 i__1 = j1 - 1;
00647 r__1 = -x[*n + j2];
00648 saxpy_(&i__1, &r__1, &t[j2 * t_dim1 + 1], &c__1, &x[*
00649 n + 1], &c__1);
00650
00651 x[1] = x[1] + b[j1] * x[*n + j1] + b[j2] * x[*n + j2];
00652 x[*n + 1] = x[*n + 1] - b[j1] * x[j1] - b[j2] * x[j2];
00653
00654 xmax = 0.f;
00655 i__1 = j1 - 1;
00656 for (k = 1; k <= i__1; ++k) {
00657
00658 r__3 = (r__1 = x[k], dabs(r__1)) + (r__2 = x[k + *
00659 n], dabs(r__2));
00660 xmax = dmax(r__3,xmax);
00661
00662 }
00663 }
00664
00665 }
00666 L70:
00667 ;
00668 }
00669
00670 } else {
00671
00672
00673
00674 jnext = 1;
00675 i__1 = *n;
00676 for (j = 1; j <= i__1; ++j) {
00677 if (j < jnext) {
00678 goto L80;
00679 }
00680 j1 = j;
00681 j2 = j;
00682 jnext = j + 1;
00683 if (j < *n) {
00684 if (t[j + 1 + j * t_dim1] != 0.f) {
00685 j2 = j + 1;
00686 jnext = j + 2;
00687 }
00688 }
00689
00690 if (j1 == j2) {
00691
00692
00693
00694
00695
00696
00697 xj = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[j1 + *n],
00698 dabs(r__2));
00699 if (xmax > 1.f) {
00700 rec = 1.f / xmax;
00701 if (work[j1] > (bignum - xj) * rec) {
00702 sscal_(&n2, &rec, &x[1], &c__1);
00703 *scale *= rec;
00704 xmax *= rec;
00705 }
00706 }
00707
00708 i__2 = j1 - 1;
00709 x[j1] -= sdot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[1], &
00710 c__1);
00711 i__2 = j1 - 1;
00712 x[*n + j1] -= sdot_(&i__2, &t[j1 * t_dim1 + 1], &c__1, &x[
00713 *n + 1], &c__1);
00714 if (j1 > 1) {
00715 x[j1] -= b[j1] * x[*n + 1];
00716 x[*n + j1] += b[j1] * x[1];
00717 }
00718 xj = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[j1 + *n],
00719 dabs(r__2));
00720
00721 z__ = *w;
00722 if (j1 == 1) {
00723 z__ = b[1];
00724 }
00725
00726
00727
00728
00729 tjj = (r__1 = t[j1 + j1 * t_dim1], dabs(r__1)) + dabs(z__)
00730 ;
00731 tmp = t[j1 + j1 * t_dim1];
00732 if (tjj < sminw) {
00733 tmp = sminw;
00734 tjj = sminw;
00735 *info = 1;
00736 }
00737
00738 if (tjj < 1.f) {
00739 if (xj > bignum * tjj) {
00740 rec = 1.f / xj;
00741 sscal_(&n2, &rec, &x[1], &c__1);
00742 *scale *= rec;
00743 xmax *= rec;
00744 }
00745 }
00746 r__1 = -z__;
00747 sladiv_(&x[j1], &x[*n + j1], &tmp, &r__1, &sr, &si);
00748 x[j1] = sr;
00749 x[j1 + *n] = si;
00750
00751 r__3 = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[j1 + *n],
00752 dabs(r__2));
00753 xmax = dmax(r__3,xmax);
00754
00755 } else {
00756
00757
00758
00759
00760
00761
00762
00763 r__5 = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[*n + j1],
00764 dabs(r__2)), r__6 = (r__3 = x[j2], dabs(r__3)) + (
00765 r__4 = x[*n + j2], dabs(r__4));
00766 xj = dmax(r__5,r__6);
00767 if (xmax > 1.f) {
00768 rec = 1.f / xmax;
00769
00770 r__1 = work[j1], r__2 = work[j2];
00771 if (dmax(r__1,r__2) > (bignum - xj) / xmax) {
00772 sscal_(&n2, &rec, &x[1], &c__1);
00773 *scale *= rec;
00774 xmax *= rec;
00775 }
00776 }
00777
00778 i__2 = j1 - 1;
00779 d__[0] = x[j1] - sdot_(&i__2, &t[j1 * t_dim1 + 1], &c__1,
00780 &x[1], &c__1);
00781 i__2 = j1 - 1;
00782 d__[1] = x[j2] - sdot_(&i__2, &t[j2 * t_dim1 + 1], &c__1,
00783 &x[1], &c__1);
00784 i__2 = j1 - 1;
00785 d__[2] = x[*n + j1] - sdot_(&i__2, &t[j1 * t_dim1 + 1], &
00786 c__1, &x[*n + 1], &c__1);
00787 i__2 = j1 - 1;
00788 d__[3] = x[*n + j2] - sdot_(&i__2, &t[j2 * t_dim1 + 1], &
00789 c__1, &x[*n + 1], &c__1);
00790 d__[0] -= b[j1] * x[*n + 1];
00791 d__[1] -= b[j2] * x[*n + 1];
00792 d__[2] += b[j1] * x[1];
00793 d__[3] += b[j2] * x[1];
00794
00795 slaln2_(&c_true, &c__2, &c__2, &sminw, &c_b21, &t[j1 + j1
00796 * t_dim1], ldt, &c_b21, &c_b21, d__, &c__2, &
00797 c_b25, w, v, &c__2, &scaloc, &xnorm, &ierr);
00798 if (ierr != 0) {
00799 *info = 2;
00800 }
00801
00802 if (scaloc != 1.f) {
00803 sscal_(&n2, &scaloc, &x[1], &c__1);
00804 *scale = scaloc * *scale;
00805 }
00806 x[j1] = v[0];
00807 x[j2] = v[1];
00808 x[*n + j1] = v[2];
00809 x[*n + j2] = v[3];
00810
00811 r__5 = (r__1 = x[j1], dabs(r__1)) + (r__2 = x[*n + j1],
00812 dabs(r__2)), r__6 = (r__3 = x[j2], dabs(r__3)) + (
00813 r__4 = x[*n + j2], dabs(r__4)), r__5 = max(r__5,
00814 r__6);
00815 xmax = dmax(r__5,xmax);
00816
00817 }
00818
00819 L80:
00820 ;
00821 }
00822
00823 }
00824
00825 }
00826
00827 return 0;
00828
00829
00830
00831 }