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