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 real c_b16 = 1.f;
00021 static integer c__1 = 1;
00022
00023 int chbevx_(char *jobz, char *range, char *uplo, integer *n,
00024 integer *kd, complex *ab, integer *ldab, complex *q, integer *ldq,
00025 real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *
00026 m, real *w, complex *z__, integer *ldz, complex *work, real *rwork,
00027 integer *iwork, integer *ifail, integer *info)
00028 {
00029
00030 integer ab_dim1, ab_offset, q_dim1, q_offset, z_dim1, z_offset, i__1,
00031 i__2;
00032 real r__1, r__2;
00033
00034
00035 double sqrt(doublereal);
00036
00037
00038 integer i__, j, jj;
00039 real eps, vll, vuu, tmp1;
00040 integer indd, inde;
00041 real anrm;
00042 integer imax;
00043 real rmin, rmax;
00044 logical test;
00045 complex ctmp1;
00046 integer itmp1, indee;
00047 real sigma;
00048 extern logical lsame_(char *, char *);
00049 extern int cgemv_(char *, integer *, integer *, complex *
00050 , complex *, integer *, complex *, integer *, complex *, complex *
00051 , integer *);
00052 integer iinfo;
00053 extern int sscal_(integer *, real *, real *, integer *);
00054 char order[1];
00055 extern int ccopy_(integer *, complex *, integer *,
00056 complex *, integer *), cswap_(integer *, complex *, integer *,
00057 complex *, integer *);
00058 logical lower;
00059 extern int scopy_(integer *, real *, integer *, real *,
00060 integer *);
00061 logical wantz;
00062 extern doublereal clanhb_(char *, char *, integer *, integer *, complex *,
00063 integer *, real *);
00064 logical alleig, indeig;
00065 integer iscale, indibl;
00066 extern int clascl_(char *, integer *, integer *, real *,
00067 real *, integer *, integer *, complex *, integer *, integer *), chbtrd_(char *, char *, integer *, integer *, complex *,
00068 integer *, real *, real *, complex *, integer *, complex *,
00069 integer *);
00070 logical valeig;
00071 extern doublereal slamch_(char *);
00072 extern int clacpy_(char *, integer *, integer *, complex
00073 *, integer *, complex *, integer *);
00074 real safmin;
00075 extern int xerbla_(char *, integer *);
00076 real abstll, bignum;
00077 integer indiwk, indisp;
00078 extern int cstein_(integer *, real *, real *, integer *,
00079 real *, integer *, integer *, complex *, integer *, real *,
00080 integer *, integer *, integer *);
00081 integer indrwk, indwrk;
00082 extern int csteqr_(char *, integer *, real *, real *,
00083 complex *, integer *, real *, integer *), ssterf_(integer
00084 *, real *, real *, integer *);
00085 integer nsplit;
00086 extern int sstebz_(char *, char *, integer *, real *,
00087 real *, integer *, integer *, real *, real *, real *, integer *,
00088 integer *, real *, integer *, integer *, real *, integer *,
00089 integer *);
00090 real smlnum;
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 ab_dim1 = *ldab;
00254 ab_offset = 1 + ab_dim1;
00255 ab -= ab_offset;
00256 q_dim1 = *ldq;
00257 q_offset = 1 + q_dim1;
00258 q -= q_offset;
00259 --w;
00260 z_dim1 = *ldz;
00261 z_offset = 1 + z_dim1;
00262 z__ -= z_offset;
00263 --work;
00264 --rwork;
00265 --iwork;
00266 --ifail;
00267
00268
00269 wantz = lsame_(jobz, "V");
00270 alleig = lsame_(range, "A");
00271 valeig = lsame_(range, "V");
00272 indeig = lsame_(range, "I");
00273 lower = lsame_(uplo, "L");
00274
00275 *info = 0;
00276 if (! (wantz || lsame_(jobz, "N"))) {
00277 *info = -1;
00278 } else if (! (alleig || valeig || indeig)) {
00279 *info = -2;
00280 } else if (! (lower || lsame_(uplo, "U"))) {
00281 *info = -3;
00282 } else if (*n < 0) {
00283 *info = -4;
00284 } else if (*kd < 0) {
00285 *info = -5;
00286 } else if (*ldab < *kd + 1) {
00287 *info = -7;
00288 } else if (wantz && *ldq < max(1,*n)) {
00289 *info = -9;
00290 } else {
00291 if (valeig) {
00292 if (*n > 0 && *vu <= *vl) {
00293 *info = -11;
00294 }
00295 } else if (indeig) {
00296 if (*il < 1 || *il > max(1,*n)) {
00297 *info = -12;
00298 } else if (*iu < min(*n,*il) || *iu > *n) {
00299 *info = -13;
00300 }
00301 }
00302 }
00303 if (*info == 0) {
00304 if (*ldz < 1 || wantz && *ldz < *n) {
00305 *info = -18;
00306 }
00307 }
00308
00309 if (*info != 0) {
00310 i__1 = -(*info);
00311 xerbla_("CHBEVX", &i__1);
00312 return 0;
00313 }
00314
00315
00316
00317 *m = 0;
00318 if (*n == 0) {
00319 return 0;
00320 }
00321
00322 if (*n == 1) {
00323 *m = 1;
00324 if (lower) {
00325 i__1 = ab_dim1 + 1;
00326 ctmp1.r = ab[i__1].r, ctmp1.i = ab[i__1].i;
00327 } else {
00328 i__1 = *kd + 1 + ab_dim1;
00329 ctmp1.r = ab[i__1].r, ctmp1.i = ab[i__1].i;
00330 }
00331 tmp1 = ctmp1.r;
00332 if (valeig) {
00333 if (! (*vl < tmp1 && *vu >= tmp1)) {
00334 *m = 0;
00335 }
00336 }
00337 if (*m == 1) {
00338 w[1] = ctmp1.r;
00339 if (wantz) {
00340 i__1 = z_dim1 + 1;
00341 z__[i__1].r = 1.f, z__[i__1].i = 0.f;
00342 }
00343 }
00344 return 0;
00345 }
00346
00347
00348
00349 safmin = slamch_("Safe minimum");
00350 eps = slamch_("Precision");
00351 smlnum = safmin / eps;
00352 bignum = 1.f / smlnum;
00353 rmin = sqrt(smlnum);
00354
00355 r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
00356 rmax = dmin(r__1,r__2);
00357
00358
00359
00360 iscale = 0;
00361 abstll = *abstol;
00362 if (valeig) {
00363 vll = *vl;
00364 vuu = *vu;
00365 } else {
00366 vll = 0.f;
00367 vuu = 0.f;
00368 }
00369 anrm = clanhb_("M", uplo, n, kd, &ab[ab_offset], ldab, &rwork[1]);
00370 if (anrm > 0.f && anrm < rmin) {
00371 iscale = 1;
00372 sigma = rmin / anrm;
00373 } else if (anrm > rmax) {
00374 iscale = 1;
00375 sigma = rmax / anrm;
00376 }
00377 if (iscale == 1) {
00378 if (lower) {
00379 clascl_("B", kd, kd, &c_b16, &sigma, n, n, &ab[ab_offset], ldab,
00380 info);
00381 } else {
00382 clascl_("Q", kd, kd, &c_b16, &sigma, n, n, &ab[ab_offset], ldab,
00383 info);
00384 }
00385 if (*abstol > 0.f) {
00386 abstll = *abstol * sigma;
00387 }
00388 if (valeig) {
00389 vll = *vl * sigma;
00390 vuu = *vu * sigma;
00391 }
00392 }
00393
00394
00395
00396 indd = 1;
00397 inde = indd + *n;
00398 indrwk = inde + *n;
00399 indwrk = 1;
00400 chbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &rwork[indd], &rwork[
00401 inde], &q[q_offset], ldq, &work[indwrk], &iinfo);
00402
00403
00404
00405
00406
00407 test = FALSE_;
00408 if (indeig) {
00409 if (*il == 1 && *iu == *n) {
00410 test = TRUE_;
00411 }
00412 }
00413 if ((alleig || test) && *abstol <= 0.f) {
00414 scopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00415 indee = indrwk + (*n << 1);
00416 if (! wantz) {
00417 i__1 = *n - 1;
00418 scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00419 ssterf_(n, &w[1], &rwork[indee], info);
00420 } else {
00421 clacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz);
00422 i__1 = *n - 1;
00423 scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00424 csteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00425 rwork[indrwk], info);
00426 if (*info == 0) {
00427 i__1 = *n;
00428 for (i__ = 1; i__ <= i__1; ++i__) {
00429 ifail[i__] = 0;
00430
00431 }
00432 }
00433 }
00434 if (*info == 0) {
00435 *m = *n;
00436 goto L30;
00437 }
00438 *info = 0;
00439 }
00440
00441
00442
00443 if (wantz) {
00444 *(unsigned char *)order = 'B';
00445 } else {
00446 *(unsigned char *)order = 'E';
00447 }
00448 indibl = 1;
00449 indisp = indibl + *n;
00450 indiwk = indisp + *n;
00451 sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
00452 rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00453 rwork[indrwk], &iwork[indiwk], info);
00454
00455 if (wantz) {
00456 cstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00457 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00458 indiwk], &ifail[1], info);
00459
00460
00461
00462
00463 i__1 = *m;
00464 for (j = 1; j <= i__1; ++j) {
00465 ccopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1);
00466 cgemv_("N", n, n, &c_b2, &q[q_offset], ldq, &work[1], &c__1, &
00467 c_b1, &z__[j * z_dim1 + 1], &c__1);
00468
00469 }
00470 }
00471
00472
00473
00474 L30:
00475 if (iscale == 1) {
00476 if (*info == 0) {
00477 imax = *m;
00478 } else {
00479 imax = *info - 1;
00480 }
00481 r__1 = 1.f / sigma;
00482 sscal_(&imax, &r__1, &w[1], &c__1);
00483 }
00484
00485
00486
00487
00488 if (wantz) {
00489 i__1 = *m - 1;
00490 for (j = 1; j <= i__1; ++j) {
00491 i__ = 0;
00492 tmp1 = w[j];
00493 i__2 = *m;
00494 for (jj = j + 1; jj <= i__2; ++jj) {
00495 if (w[jj] < tmp1) {
00496 i__ = jj;
00497 tmp1 = w[jj];
00498 }
00499
00500 }
00501
00502 if (i__ != 0) {
00503 itmp1 = iwork[indibl + i__ - 1];
00504 w[i__] = w[j];
00505 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00506 w[j] = tmp1;
00507 iwork[indibl + j - 1] = itmp1;
00508 cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
00509 &c__1);
00510 if (*info != 0) {
00511 itmp1 = ifail[i__];
00512 ifail[i__] = ifail[j];
00513 ifail[j] = itmp1;
00514 }
00515 }
00516
00517 }
00518 }
00519
00520 return 0;
00521
00522
00523
00524 }