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