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
00020 int slaein_(logical *rightv, logical *noinit, integer *n,
00021 real *h__, integer *ldh, real *wr, real *wi, real *vr, real *vi, real
00022 *b, integer *ldb, real *work, real *eps3, real *smlnum, real *bignum,
00023 integer *info)
00024 {
00025
00026 integer b_dim1, b_offset, h_dim1, h_offset, i__1, i__2, i__3, i__4;
00027 real r__1, r__2, r__3, r__4;
00028
00029
00030 double sqrt(doublereal);
00031
00032
00033 integer i__, j;
00034 real w, x, y;
00035 integer i1, i2, i3;
00036 real w1, ei, ej, xi, xr, rec;
00037 integer its, ierr;
00038 real temp, norm, vmax;
00039 extern doublereal snrm2_(integer *, real *, integer *);
00040 real scale;
00041 extern int sscal_(integer *, real *, real *, integer *);
00042 char trans[1];
00043 real vcrit;
00044 extern doublereal sasum_(integer *, real *, integer *);
00045 real rootn, vnorm;
00046 extern doublereal slapy2_(real *, real *);
00047 real absbii, absbjj;
00048 extern integer isamax_(integer *, real *, integer *);
00049 extern int sladiv_(real *, real *, real *, real *, real *
00050 , real *);
00051 char normin[1];
00052 real nrmsml;
00053 extern int slatrs_(char *, char *, char *, char *,
00054 integer *, real *, integer *, real *, real *, real *, integer *);
00055 real growto;
00056
00057
00058
00059
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 h_dim1 = *ldh;
00154 h_offset = 1 + h_dim1;
00155 h__ -= h_offset;
00156 --vr;
00157 --vi;
00158 b_dim1 = *ldb;
00159 b_offset = 1 + b_dim1;
00160 b -= b_offset;
00161 --work;
00162
00163
00164 *info = 0;
00165
00166
00167
00168
00169 rootn = sqrt((real) (*n));
00170 growto = .1f / rootn;
00171
00172 r__1 = 1.f, r__2 = *eps3 * rootn;
00173 nrmsml = dmax(r__1,r__2) * *smlnum;
00174
00175
00176
00177
00178 i__1 = *n;
00179 for (j = 1; j <= i__1; ++j) {
00180 i__2 = j - 1;
00181 for (i__ = 1; i__ <= i__2; ++i__) {
00182 b[i__ + j * b_dim1] = h__[i__ + j * h_dim1];
00183
00184 }
00185 b[j + j * b_dim1] = h__[j + j * h_dim1] - *wr;
00186
00187 }
00188
00189 if (*wi == 0.f) {
00190
00191
00192
00193 if (*noinit) {
00194
00195
00196
00197 i__1 = *n;
00198 for (i__ = 1; i__ <= i__1; ++i__) {
00199 vr[i__] = *eps3;
00200
00201 }
00202 } else {
00203
00204
00205
00206 vnorm = snrm2_(n, &vr[1], &c__1);
00207 r__1 = *eps3 * rootn / dmax(vnorm,nrmsml);
00208 sscal_(n, &r__1, &vr[1], &c__1);
00209 }
00210
00211 if (*rightv) {
00212
00213
00214
00215
00216 i__1 = *n - 1;
00217 for (i__ = 1; i__ <= i__1; ++i__) {
00218 ei = h__[i__ + 1 + i__ * h_dim1];
00219 if ((r__1 = b[i__ + i__ * b_dim1], dabs(r__1)) < dabs(ei)) {
00220
00221
00222
00223 x = b[i__ + i__ * b_dim1] / ei;
00224 b[i__ + i__ * b_dim1] = ei;
00225 i__2 = *n;
00226 for (j = i__ + 1; j <= i__2; ++j) {
00227 temp = b[i__ + 1 + j * b_dim1];
00228 b[i__ + 1 + j * b_dim1] = b[i__ + j * b_dim1] - x *
00229 temp;
00230 b[i__ + j * b_dim1] = temp;
00231
00232 }
00233 } else {
00234
00235
00236
00237 if (b[i__ + i__ * b_dim1] == 0.f) {
00238 b[i__ + i__ * b_dim1] = *eps3;
00239 }
00240 x = ei / b[i__ + i__ * b_dim1];
00241 if (x != 0.f) {
00242 i__2 = *n;
00243 for (j = i__ + 1; j <= i__2; ++j) {
00244 b[i__ + 1 + j * b_dim1] -= x * b[i__ + j * b_dim1]
00245 ;
00246
00247 }
00248 }
00249 }
00250
00251 }
00252 if (b[*n + *n * b_dim1] == 0.f) {
00253 b[*n + *n * b_dim1] = *eps3;
00254 }
00255
00256 *(unsigned char *)trans = 'N';
00257
00258 } else {
00259
00260
00261
00262
00263 for (j = *n; j >= 2; --j) {
00264 ej = h__[j + (j - 1) * h_dim1];
00265 if ((r__1 = b[j + j * b_dim1], dabs(r__1)) < dabs(ej)) {
00266
00267
00268
00269 x = b[j + j * b_dim1] / ej;
00270 b[j + j * b_dim1] = ej;
00271 i__1 = j - 1;
00272 for (i__ = 1; i__ <= i__1; ++i__) {
00273 temp = b[i__ + (j - 1) * b_dim1];
00274 b[i__ + (j - 1) * b_dim1] = b[i__ + j * b_dim1] - x *
00275 temp;
00276 b[i__ + j * b_dim1] = temp;
00277
00278 }
00279 } else {
00280
00281
00282
00283 if (b[j + j * b_dim1] == 0.f) {
00284 b[j + j * b_dim1] = *eps3;
00285 }
00286 x = ej / b[j + j * b_dim1];
00287 if (x != 0.f) {
00288 i__1 = j - 1;
00289 for (i__ = 1; i__ <= i__1; ++i__) {
00290 b[i__ + (j - 1) * b_dim1] -= x * b[i__ + j *
00291 b_dim1];
00292
00293 }
00294 }
00295 }
00296
00297 }
00298 if (b[b_dim1 + 1] == 0.f) {
00299 b[b_dim1 + 1] = *eps3;
00300 }
00301
00302 *(unsigned char *)trans = 'T';
00303
00304 }
00305
00306 *(unsigned char *)normin = 'N';
00307 i__1 = *n;
00308 for (its = 1; its <= i__1; ++its) {
00309
00310
00311
00312
00313
00314 slatrs_("Upper", trans, "Nonunit", normin, n, &b[b_offset], ldb, &
00315 vr[1], &scale, &work[1], &ierr);
00316 *(unsigned char *)normin = 'Y';
00317
00318
00319
00320 vnorm = sasum_(n, &vr[1], &c__1);
00321 if (vnorm >= growto * scale) {
00322 goto L120;
00323 }
00324
00325
00326
00327 temp = *eps3 / (rootn + 1.f);
00328 vr[1] = *eps3;
00329 i__2 = *n;
00330 for (i__ = 2; i__ <= i__2; ++i__) {
00331 vr[i__] = temp;
00332
00333 }
00334 vr[*n - its + 1] -= *eps3 * rootn;
00335
00336 }
00337
00338
00339
00340 *info = 1;
00341
00342 L120:
00343
00344
00345
00346 i__ = isamax_(n, &vr[1], &c__1);
00347 r__2 = 1.f / (r__1 = vr[i__], dabs(r__1));
00348 sscal_(n, &r__2, &vr[1], &c__1);
00349 } else {
00350
00351
00352
00353 if (*noinit) {
00354
00355
00356
00357 i__1 = *n;
00358 for (i__ = 1; i__ <= i__1; ++i__) {
00359 vr[i__] = *eps3;
00360 vi[i__] = 0.f;
00361
00362 }
00363 } else {
00364
00365
00366
00367 r__1 = snrm2_(n, &vr[1], &c__1);
00368 r__2 = snrm2_(n, &vi[1], &c__1);
00369 norm = slapy2_(&r__1, &r__2);
00370 rec = *eps3 * rootn / dmax(norm,nrmsml);
00371 sscal_(n, &rec, &vr[1], &c__1);
00372 sscal_(n, &rec, &vi[1], &c__1);
00373 }
00374
00375 if (*rightv) {
00376
00377
00378
00379
00380
00381
00382
00383 b[b_dim1 + 2] = -(*wi);
00384 i__1 = *n;
00385 for (i__ = 2; i__ <= i__1; ++i__) {
00386 b[i__ + 1 + b_dim1] = 0.f;
00387
00388 }
00389
00390 i__1 = *n - 1;
00391 for (i__ = 1; i__ <= i__1; ++i__) {
00392 absbii = slapy2_(&b[i__ + i__ * b_dim1], &b[i__ + 1 + i__ *
00393 b_dim1]);
00394 ei = h__[i__ + 1 + i__ * h_dim1];
00395 if (absbii < dabs(ei)) {
00396
00397
00398
00399 xr = b[i__ + i__ * b_dim1] / ei;
00400 xi = b[i__ + 1 + i__ * b_dim1] / ei;
00401 b[i__ + i__ * b_dim1] = ei;
00402 b[i__ + 1 + i__ * b_dim1] = 0.f;
00403 i__2 = *n;
00404 for (j = i__ + 1; j <= i__2; ++j) {
00405 temp = b[i__ + 1 + j * b_dim1];
00406 b[i__ + 1 + j * b_dim1] = b[i__ + j * b_dim1] - xr *
00407 temp;
00408 b[j + 1 + (i__ + 1) * b_dim1] = b[j + 1 + i__ *
00409 b_dim1] - xi * temp;
00410 b[i__ + j * b_dim1] = temp;
00411 b[j + 1 + i__ * b_dim1] = 0.f;
00412
00413 }
00414 b[i__ + 2 + i__ * b_dim1] = -(*wi);
00415 b[i__ + 1 + (i__ + 1) * b_dim1] -= xi * *wi;
00416 b[i__ + 2 + (i__ + 1) * b_dim1] += xr * *wi;
00417 } else {
00418
00419
00420
00421 if (absbii == 0.f) {
00422 b[i__ + i__ * b_dim1] = *eps3;
00423 b[i__ + 1 + i__ * b_dim1] = 0.f;
00424 absbii = *eps3;
00425 }
00426 ei = ei / absbii / absbii;
00427 xr = b[i__ + i__ * b_dim1] * ei;
00428 xi = -b[i__ + 1 + i__ * b_dim1] * ei;
00429 i__2 = *n;
00430 for (j = i__ + 1; j <= i__2; ++j) {
00431 b[i__ + 1 + j * b_dim1] = b[i__ + 1 + j * b_dim1] -
00432 xr * b[i__ + j * b_dim1] + xi * b[j + 1 + i__
00433 * b_dim1];
00434 b[j + 1 + (i__ + 1) * b_dim1] = -xr * b[j + 1 + i__ *
00435 b_dim1] - xi * b[i__ + j * b_dim1];
00436
00437 }
00438 b[i__ + 2 + (i__ + 1) * b_dim1] -= *wi;
00439 }
00440
00441
00442
00443 i__2 = *n - i__;
00444 i__3 = *n - i__;
00445 work[i__] = sasum_(&i__2, &b[i__ + (i__ + 1) * b_dim1], ldb)
00446 + sasum_(&i__3, &b[i__ + 2 + i__ * b_dim1], &c__1);
00447
00448 }
00449 if (b[*n + *n * b_dim1] == 0.f && b[*n + 1 + *n * b_dim1] == 0.f)
00450 {
00451 b[*n + *n * b_dim1] = *eps3;
00452 }
00453 work[*n] = 0.f;
00454
00455 i1 = *n;
00456 i2 = 1;
00457 i3 = -1;
00458 } else {
00459
00460
00461
00462
00463
00464
00465
00466 b[*n + 1 + *n * b_dim1] = *wi;
00467 i__1 = *n - 1;
00468 for (j = 1; j <= i__1; ++j) {
00469 b[*n + 1 + j * b_dim1] = 0.f;
00470
00471 }
00472
00473 for (j = *n; j >= 2; --j) {
00474 ej = h__[j + (j - 1) * h_dim1];
00475 absbjj = slapy2_(&b[j + j * b_dim1], &b[j + 1 + j * b_dim1]);
00476 if (absbjj < dabs(ej)) {
00477
00478
00479
00480 xr = b[j + j * b_dim1] / ej;
00481 xi = b[j + 1 + j * b_dim1] / ej;
00482 b[j + j * b_dim1] = ej;
00483 b[j + 1 + j * b_dim1] = 0.f;
00484 i__1 = j - 1;
00485 for (i__ = 1; i__ <= i__1; ++i__) {
00486 temp = b[i__ + (j - 1) * b_dim1];
00487 b[i__ + (j - 1) * b_dim1] = b[i__ + j * b_dim1] - xr *
00488 temp;
00489 b[j + i__ * b_dim1] = b[j + 1 + i__ * b_dim1] - xi *
00490 temp;
00491 b[i__ + j * b_dim1] = temp;
00492 b[j + 1 + i__ * b_dim1] = 0.f;
00493
00494 }
00495 b[j + 1 + (j - 1) * b_dim1] = *wi;
00496 b[j - 1 + (j - 1) * b_dim1] += xi * *wi;
00497 b[j + (j - 1) * b_dim1] -= xr * *wi;
00498 } else {
00499
00500
00501
00502 if (absbjj == 0.f) {
00503 b[j + j * b_dim1] = *eps3;
00504 b[j + 1 + j * b_dim1] = 0.f;
00505 absbjj = *eps3;
00506 }
00507 ej = ej / absbjj / absbjj;
00508 xr = b[j + j * b_dim1] * ej;
00509 xi = -b[j + 1 + j * b_dim1] * ej;
00510 i__1 = j - 1;
00511 for (i__ = 1; i__ <= i__1; ++i__) {
00512 b[i__ + (j - 1) * b_dim1] = b[i__ + (j - 1) * b_dim1]
00513 - xr * b[i__ + j * b_dim1] + xi * b[j + 1 +
00514 i__ * b_dim1];
00515 b[j + i__ * b_dim1] = -xr * b[j + 1 + i__ * b_dim1] -
00516 xi * b[i__ + j * b_dim1];
00517
00518 }
00519 b[j + (j - 1) * b_dim1] += *wi;
00520 }
00521
00522
00523
00524 i__1 = j - 1;
00525 i__2 = j - 1;
00526 work[j] = sasum_(&i__1, &b[j * b_dim1 + 1], &c__1) + sasum_(&
00527 i__2, &b[j + 1 + b_dim1], ldb);
00528
00529 }
00530 if (b[b_dim1 + 1] == 0.f && b[b_dim1 + 2] == 0.f) {
00531 b[b_dim1 + 1] = *eps3;
00532 }
00533 work[1] = 0.f;
00534
00535 i1 = 1;
00536 i2 = *n;
00537 i3 = 1;
00538 }
00539
00540 i__1 = *n;
00541 for (its = 1; its <= i__1; ++its) {
00542 scale = 1.f;
00543 vmax = 1.f;
00544 vcrit = *bignum;
00545
00546
00547
00548
00549
00550 i__2 = i2;
00551 i__3 = i3;
00552 for (i__ = i1; i__3 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__3)
00553 {
00554
00555 if (work[i__] > vcrit) {
00556 rec = 1.f / vmax;
00557 sscal_(n, &rec, &vr[1], &c__1);
00558 sscal_(n, &rec, &vi[1], &c__1);
00559 scale *= rec;
00560 vmax = 1.f;
00561 vcrit = *bignum;
00562 }
00563
00564 xr = vr[i__];
00565 xi = vi[i__];
00566 if (*rightv) {
00567 i__4 = *n;
00568 for (j = i__ + 1; j <= i__4; ++j) {
00569 xr = xr - b[i__ + j * b_dim1] * vr[j] + b[j + 1 + i__
00570 * b_dim1] * vi[j];
00571 xi = xi - b[i__ + j * b_dim1] * vi[j] - b[j + 1 + i__
00572 * b_dim1] * vr[j];
00573
00574 }
00575 } else {
00576 i__4 = i__ - 1;
00577 for (j = 1; j <= i__4; ++j) {
00578 xr = xr - b[j + i__ * b_dim1] * vr[j] + b[i__ + 1 + j
00579 * b_dim1] * vi[j];
00580 xi = xi - b[j + i__ * b_dim1] * vi[j] - b[i__ + 1 + j
00581 * b_dim1] * vr[j];
00582
00583 }
00584 }
00585
00586 w = (r__1 = b[i__ + i__ * b_dim1], dabs(r__1)) + (r__2 = b[
00587 i__ + 1 + i__ * b_dim1], dabs(r__2));
00588 if (w > *smlnum) {
00589 if (w < 1.f) {
00590 w1 = dabs(xr) + dabs(xi);
00591 if (w1 > w * *bignum) {
00592 rec = 1.f / w1;
00593 sscal_(n, &rec, &vr[1], &c__1);
00594 sscal_(n, &rec, &vi[1], &c__1);
00595 xr = vr[i__];
00596 xi = vi[i__];
00597 scale *= rec;
00598 vmax *= rec;
00599 }
00600 }
00601
00602
00603
00604 sladiv_(&xr, &xi, &b[i__ + i__ * b_dim1], &b[i__ + 1 +
00605 i__ * b_dim1], &vr[i__], &vi[i__]);
00606
00607 r__3 = (r__1 = vr[i__], dabs(r__1)) + (r__2 = vi[i__],
00608 dabs(r__2));
00609 vmax = dmax(r__3,vmax);
00610 vcrit = *bignum / vmax;
00611 } else {
00612 i__4 = *n;
00613 for (j = 1; j <= i__4; ++j) {
00614 vr[j] = 0.f;
00615 vi[j] = 0.f;
00616
00617 }
00618 vr[i__] = 1.f;
00619 vi[i__] = 1.f;
00620 scale = 0.f;
00621 vmax = 1.f;
00622 vcrit = *bignum;
00623 }
00624
00625 }
00626
00627
00628
00629 vnorm = sasum_(n, &vr[1], &c__1) + sasum_(n, &vi[1], &c__1);
00630 if (vnorm >= growto * scale) {
00631 goto L280;
00632 }
00633
00634
00635
00636 y = *eps3 / (rootn + 1.f);
00637 vr[1] = *eps3;
00638 vi[1] = 0.f;
00639
00640 i__3 = *n;
00641 for (i__ = 2; i__ <= i__3; ++i__) {
00642 vr[i__] = y;
00643 vi[i__] = 0.f;
00644
00645 }
00646 vr[*n - its + 1] -= *eps3 * rootn;
00647
00648 }
00649
00650
00651
00652 *info = 1;
00653
00654 L280:
00655
00656
00657
00658 vnorm = 0.f;
00659 i__1 = *n;
00660 for (i__ = 1; i__ <= i__1; ++i__) {
00661
00662 r__3 = vnorm, r__4 = (r__1 = vr[i__], dabs(r__1)) + (r__2 = vi[
00663 i__], dabs(r__2));
00664 vnorm = dmax(r__3,r__4);
00665
00666 }
00667 r__1 = 1.f / vnorm;
00668 sscal_(n, &r__1, &vr[1], &c__1);
00669 r__1 = 1.f / vnorm;
00670 sscal_(n, &r__1, &vi[1], &c__1);
00671
00672 }
00673
00674 return 0;
00675
00676
00677
00678 }