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