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__13 = 13;
00019 static integer c__15 = 15;
00020 static integer c_n1 = -1;
00021 static integer c__12 = 12;
00022 static integer c__14 = 14;
00023 static integer c__16 = 16;
00024 static logical c_false = FALSE_;
00025 static integer c__1 = 1;
00026 static integer c__3 = 3;
00027
00028 int claqr0_(logical *wantt, logical *wantz, integer *n,
00029 integer *ilo, integer *ihi, complex *h__, integer *ldh, complex *w,
00030 integer *iloz, integer *ihiz, complex *z__, integer *ldz, complex *
00031 work, integer *lwork, integer *info)
00032 {
00033
00034 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
00035 real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8;
00036 complex q__1, q__2, q__3, q__4, q__5;
00037
00038
00039 double r_imag(complex *);
00040 void c_sqrt(complex *, complex *);
00041
00042
00043 integer i__, k;
00044 real s;
00045 complex aa, bb, cc, dd;
00046 integer ld, nh, it, ks, kt, ku, kv, ls, ns, nw;
00047 complex tr2, det;
00048 integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot, nmin;
00049 complex swap;
00050 integer ktop;
00051 complex zdum[1] ;
00052 integer kacc22, itmax, nsmax, nwmax, kwtop;
00053 extern int claqr3_(logical *, logical *, integer *,
00054 integer *, integer *, integer *, complex *, integer *, integer *,
00055 integer *, complex *, integer *, integer *, integer *, complex *,
00056 complex *, integer *, integer *, complex *, integer *, integer *,
00057 complex *, integer *, complex *, integer *), claqr4_(logical *,
00058 logical *, integer *, integer *, integer *, complex *, integer *,
00059 complex *, integer *, integer *, complex *, integer *, complex *,
00060 integer *, integer *), claqr5_(logical *, logical *, integer *,
00061 integer *, integer *, integer *, integer *, complex *, complex *,
00062 integer *, integer *, integer *, complex *, integer *, complex *,
00063 integer *, complex *, integer *, integer *, complex *, integer *,
00064 integer *, complex *, integer *);
00065 integer nibble;
00066 extern int clahqr_(logical *, logical *, integer *,
00067 integer *, integer *, complex *, integer *, complex *, integer *,
00068 integer *, complex *, integer *, integer *), clacpy_(char *,
00069 integer *, integer *, complex *, integer *, complex *, integer *);
00070 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00071 integer *, integer *);
00072 char jbcmpz[2];
00073 complex rtdisc;
00074 integer nwupbd;
00075 logical sorted;
00076 integer lwkopt;
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
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 h_dim1 = *ldh;
00260 h_offset = 1 + h_dim1;
00261 h__ -= h_offset;
00262 --w;
00263 z_dim1 = *ldz;
00264 z_offset = 1 + z_dim1;
00265 z__ -= z_offset;
00266 --work;
00267
00268
00269 *info = 0;
00270
00271
00272
00273 if (*n == 0) {
00274 work[1].r = 1.f, work[1].i = 0.f;
00275 return 0;
00276 }
00277
00278 if (*n <= 11) {
00279
00280
00281
00282 lwkopt = 1;
00283 if (*lwork != -1) {
00284 clahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
00285 iloz, ihiz, &z__[z_offset], ldz, info);
00286 }
00287 } else {
00288
00289
00290
00291
00292
00293
00294 *info = 0;
00295
00296
00297
00298 if (*wantt) {
00299 *(unsigned char *)jbcmpz = 'S';
00300 } else {
00301 *(unsigned char *)jbcmpz = 'E';
00302 }
00303 if (*wantz) {
00304 *(unsigned char *)&jbcmpz[1] = 'V';
00305 } else {
00306 *(unsigned char *)&jbcmpz[1] = 'N';
00307 }
00308
00309
00310
00311
00312
00313
00314
00315 nwr = ilaenv_(&c__13, "CLAQR0", jbcmpz, n, ilo, ihi, lwork);
00316 nwr = max(2,nwr);
00317
00318 i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
00319 nwr = min(i__1,nwr);
00320
00321
00322
00323
00324
00325
00326 nsr = ilaenv_(&c__15, "CLAQR0", jbcmpz, n, ilo, ihi, lwork);
00327
00328 i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
00329 *ilo;
00330 nsr = min(i__1,i__2);
00331
00332 i__1 = 2, i__2 = nsr - nsr % 2;
00333 nsr = max(i__1,i__2);
00334
00335
00336
00337
00338
00339 i__1 = nwr + 1;
00340 claqr3_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
00341 ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
00342 ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
00343 &c_n1);
00344
00345
00346
00347
00348 i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
00349 lwkopt = max(i__1,i__2);
00350
00351
00352
00353 if (*lwork == -1) {
00354 r__1 = (real) lwkopt;
00355 q__1.r = r__1, q__1.i = 0.f;
00356 work[1].r = q__1.r, work[1].i = q__1.i;
00357 return 0;
00358 }
00359
00360
00361
00362 nmin = ilaenv_(&c__12, "CLAQR0", jbcmpz, n, ilo, ihi, lwork);
00363 nmin = max(11,nmin);
00364
00365
00366
00367 nibble = ilaenv_(&c__14, "CLAQR0", jbcmpz, n, ilo, ihi, lwork);
00368 nibble = max(0,nibble);
00369
00370
00371
00372
00373 kacc22 = ilaenv_(&c__16, "CLAQR0", jbcmpz, n, ilo, ihi, lwork);
00374 kacc22 = max(0,kacc22);
00375 kacc22 = min(2,kacc22);
00376
00377
00378
00379
00380
00381 i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
00382 nwmax = min(i__1,i__2);
00383 nw = nwmax;
00384
00385
00386
00387
00388
00389 i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
00390 nsmax = min(i__1,i__2);
00391 nsmax -= nsmax % 2;
00392
00393
00394
00395 ndfl = 1;
00396
00397
00398
00399
00400 i__1 = 10, i__2 = *ihi - *ilo + 1;
00401 itmax = max(i__1,i__2) * 30;
00402
00403
00404
00405 kbot = *ihi;
00406
00407
00408
00409 i__1 = itmax;
00410 for (it = 1; it <= i__1; ++it) {
00411
00412
00413
00414 if (kbot < *ilo) {
00415 goto L80;
00416 }
00417
00418
00419
00420 i__2 = *ilo + 1;
00421 for (k = kbot; k >= i__2; --k) {
00422 i__3 = k + (k - 1) * h_dim1;
00423 if (h__[i__3].r == 0.f && h__[i__3].i == 0.f) {
00424 goto L20;
00425 }
00426
00427 }
00428 k = *ilo;
00429 L20:
00430 ktop = k;
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 nh = kbot - ktop + 1;
00449 nwupbd = min(nh,nwmax);
00450 if (ndfl < 5) {
00451 nw = min(nwupbd,nwr);
00452 } else {
00453
00454 i__2 = nwupbd, i__3 = nw << 1;
00455 nw = min(i__2,i__3);
00456 }
00457 if (nw < nwmax) {
00458 if (nw >= nh - 1) {
00459 nw = nh;
00460 } else {
00461 kwtop = kbot - nw + 1;
00462 i__2 = kwtop + (kwtop - 1) * h_dim1;
00463 i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
00464 if ((r__1 = h__[i__2].r, dabs(r__1)) + (r__2 = r_imag(&
00465 h__[kwtop + (kwtop - 1) * h_dim1]), dabs(r__2)) >
00466 (r__3 = h__[i__3].r, dabs(r__3)) + (r__4 = r_imag(
00467 &h__[kwtop - 1 + (kwtop - 2) * h_dim1]), dabs(
00468 r__4))) {
00469 ++nw;
00470 }
00471 }
00472 }
00473 if (ndfl < 5) {
00474 ndec = -1;
00475 } else if (ndec >= 0 || nw >= nwupbd) {
00476 ++ndec;
00477 if (nw - ndec < 2) {
00478 ndec = 0;
00479 }
00480 nw -= ndec;
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 kv = *n - nw + 1;
00495 kt = nw + 1;
00496 nho = *n - nw - 1 - kt + 1;
00497 kwv = nw + 2;
00498 nve = *n - nw - kwv + 1;
00499
00500
00501
00502 claqr3_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
00503 iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
00504 + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
00505 h__[kwv + h_dim1], ldh, &work[1], lwork);
00506
00507
00508
00509 kbot -= ld;
00510
00511
00512
00513 ks = kbot - ls + 1;
00514
00515
00516
00517
00518
00519
00520
00521 if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
00522 nmin,nwmax)) {
00523
00524
00525
00526
00527
00528
00529
00530 i__4 = 2, i__5 = kbot - ktop;
00531 i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
00532 ns = min(i__2,i__3);
00533 ns -= ns % 2;
00534
00535
00536
00537
00538
00539
00540
00541
00542 if (ndfl % 6 == 0) {
00543 ks = kbot - ns + 1;
00544 i__2 = ks + 1;
00545 for (i__ = kbot; i__ >= i__2; i__ += -2) {
00546 i__3 = i__;
00547 i__4 = i__ + i__ * h_dim1;
00548 i__5 = i__ + (i__ - 1) * h_dim1;
00549 r__3 = ((r__1 = h__[i__5].r, dabs(r__1)) + (r__2 =
00550 r_imag(&h__[i__ + (i__ - 1) * h_dim1]), dabs(
00551 r__2))) * .75f;
00552 q__1.r = h__[i__4].r + r__3, q__1.i = h__[i__4].i;
00553 w[i__3].r = q__1.r, w[i__3].i = q__1.i;
00554 i__3 = i__ - 1;
00555 i__4 = i__;
00556 w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
00557
00558 }
00559 } else {
00560
00561
00562
00563
00564
00565
00566
00567 if (kbot - ks + 1 <= ns / 2) {
00568 ks = kbot - ns + 1;
00569 kt = *n - ns + 1;
00570 clacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
00571 h__[kt + h_dim1], ldh);
00572 if (ns > nmin) {
00573 claqr4_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
00574 kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
00575 zdum, &c__1, &work[1], lwork, &inf);
00576 } else {
00577 clahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
00578 kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
00579 zdum, &c__1, &inf);
00580 }
00581 ks += inf;
00582
00583
00584
00585
00586
00587
00588
00589
00590 if (ks >= kbot) {
00591 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00592 i__3 = kbot + (kbot - 1) * h_dim1;
00593 i__4 = kbot - 1 + kbot * h_dim1;
00594 i__5 = kbot + kbot * h_dim1;
00595 s = (r__1 = h__[i__2].r, dabs(r__1)) + (r__2 =
00596 r_imag(&h__[kbot - 1 + (kbot - 1) *
00597 h_dim1]), dabs(r__2)) + ((r__3 = h__[i__3]
00598 .r, dabs(r__3)) + (r__4 = r_imag(&h__[
00599 kbot + (kbot - 1) * h_dim1]), dabs(r__4)))
00600 + ((r__5 = h__[i__4].r, dabs(r__5)) + (
00601 r__6 = r_imag(&h__[kbot - 1 + kbot *
00602 h_dim1]), dabs(r__6))) + ((r__7 = h__[
00603 i__5].r, dabs(r__7)) + (r__8 = r_imag(&
00604 h__[kbot + kbot * h_dim1]), dabs(r__8)));
00605 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00606 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
00607 s;
00608 aa.r = q__1.r, aa.i = q__1.i;
00609 i__2 = kbot + (kbot - 1) * h_dim1;
00610 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
00611 s;
00612 cc.r = q__1.r, cc.i = q__1.i;
00613 i__2 = kbot - 1 + kbot * h_dim1;
00614 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
00615 s;
00616 bb.r = q__1.r, bb.i = q__1.i;
00617 i__2 = kbot + kbot * h_dim1;
00618 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
00619 s;
00620 dd.r = q__1.r, dd.i = q__1.i;
00621 q__2.r = aa.r + dd.r, q__2.i = aa.i + dd.i;
00622 q__1.r = q__2.r / 2.f, q__1.i = q__2.i / 2.f;
00623 tr2.r = q__1.r, tr2.i = q__1.i;
00624 q__3.r = aa.r - tr2.r, q__3.i = aa.i - tr2.i;
00625 q__4.r = dd.r - tr2.r, q__4.i = dd.i - tr2.i;
00626 q__2.r = q__3.r * q__4.r - q__3.i * q__4.i,
00627 q__2.i = q__3.r * q__4.i + q__3.i *
00628 q__4.r;
00629 q__5.r = bb.r * cc.r - bb.i * cc.i, q__5.i = bb.r
00630 * cc.i + bb.i * cc.r;
00631 q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
00632 q__5.i;
00633 det.r = q__1.r, det.i = q__1.i;
00634 q__2.r = -det.r, q__2.i = -det.i;
00635 c_sqrt(&q__1, &q__2);
00636 rtdisc.r = q__1.r, rtdisc.i = q__1.i;
00637 i__2 = kbot - 1;
00638 q__2.r = tr2.r + rtdisc.r, q__2.i = tr2.i +
00639 rtdisc.i;
00640 q__1.r = s * q__2.r, q__1.i = s * q__2.i;
00641 w[i__2].r = q__1.r, w[i__2].i = q__1.i;
00642 i__2 = kbot;
00643 q__2.r = tr2.r - rtdisc.r, q__2.i = tr2.i -
00644 rtdisc.i;
00645 q__1.r = s * q__2.r, q__1.i = s * q__2.i;
00646 w[i__2].r = q__1.r, w[i__2].i = q__1.i;
00647
00648 ks = kbot - 1;
00649 }
00650 }
00651
00652 if (kbot - ks + 1 > ns) {
00653
00654
00655
00656 sorted = FALSE_;
00657 i__2 = ks + 1;
00658 for (k = kbot; k >= i__2; --k) {
00659 if (sorted) {
00660 goto L60;
00661 }
00662 sorted = TRUE_;
00663 i__3 = k - 1;
00664 for (i__ = ks; i__ <= i__3; ++i__) {
00665 i__4 = i__;
00666 i__5 = i__ + 1;
00667 if ((r__1 = w[i__4].r, dabs(r__1)) + (r__2 =
00668 r_imag(&w[i__]), dabs(r__2)) < (r__3 =
00669 w[i__5].r, dabs(r__3)) + (r__4 =
00670 r_imag(&w[i__ + 1]), dabs(r__4))) {
00671 sorted = FALSE_;
00672 i__4 = i__;
00673 swap.r = w[i__4].r, swap.i = w[i__4].i;
00674 i__4 = i__;
00675 i__5 = i__ + 1;
00676 w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
00677 .i;
00678 i__4 = i__ + 1;
00679 w[i__4].r = swap.r, w[i__4].i = swap.i;
00680 }
00681
00682 }
00683
00684 }
00685 L60:
00686 ;
00687 }
00688 }
00689
00690
00691
00692
00693 if (kbot - ks + 1 == 2) {
00694 i__2 = kbot;
00695 i__3 = kbot + kbot * h_dim1;
00696 q__2.r = w[i__2].r - h__[i__3].r, q__2.i = w[i__2].i -
00697 h__[i__3].i;
00698 q__1.r = q__2.r, q__1.i = q__2.i;
00699 i__4 = kbot - 1;
00700 i__5 = kbot + kbot * h_dim1;
00701 q__4.r = w[i__4].r - h__[i__5].r, q__4.i = w[i__4].i -
00702 h__[i__5].i;
00703 q__3.r = q__4.r, q__3.i = q__4.i;
00704 if ((r__1 = q__1.r, dabs(r__1)) + (r__2 = r_imag(&q__1),
00705 dabs(r__2)) < (r__3 = q__3.r, dabs(r__3)) + (r__4
00706 = r_imag(&q__3), dabs(r__4))) {
00707 i__2 = kbot - 1;
00708 i__3 = kbot;
00709 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00710 } else {
00711 i__2 = kbot;
00712 i__3 = kbot - 1;
00713 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00714 }
00715 }
00716
00717
00718
00719
00720
00721
00722
00723 i__2 = ns, i__3 = kbot - ks + 1;
00724 ns = min(i__2,i__3);
00725 ns -= ns % 2;
00726 ks = kbot - ns + 1;
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739 kdu = ns * 3 - 3;
00740 ku = *n - kdu + 1;
00741 kwh = kdu + 1;
00742 nho = *n - kdu - 3 - (kdu + 1) + 1;
00743 kwv = kdu + 4;
00744 nve = *n - kdu - kwv + 1;
00745
00746
00747
00748 claqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
00749 h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
00750 work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
00751 kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
00752 ldh);
00753 }
00754
00755
00756
00757 if (ld > 0) {
00758 ndfl = 1;
00759 } else {
00760 ++ndfl;
00761 }
00762
00763
00764
00765 }
00766
00767
00768
00769
00770 *info = kbot;
00771 L80:
00772 ;
00773 }
00774
00775
00776
00777 r__1 = (real) lwkopt;
00778 q__1.r = r__1, q__1.i = 0.f;
00779 work[1].r = q__1.r, work[1].i = q__1.i;
00780
00781
00782
00783 return 0;
00784 }