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