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