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__1 = 1;
00019
00020 int zhpevx_(char *jobz, char *range, char *uplo, integer *n,
00021 doublecomplex *ap, doublereal *vl, doublereal *vu, integer *il,
00022 integer *iu, doublereal *abstol, integer *m, doublereal *w,
00023 doublecomplex *z__, integer *ldz, doublecomplex *work, doublereal *
00024 rwork, integer *iwork, integer *ifail, integer *info)
00025 {
00026
00027 integer z_dim1, z_offset, i__1, i__2;
00028 doublereal d__1, d__2;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__, j, jj;
00035 doublereal eps, vll, vuu, tmp1;
00036 integer indd, inde;
00037 doublereal anrm;
00038 integer imax;
00039 doublereal rmin, rmax;
00040 logical test;
00041 integer itmp1, indee;
00042 extern int dscal_(integer *, doublereal *, doublereal *,
00043 integer *);
00044 doublereal sigma;
00045 extern logical lsame_(char *, char *);
00046 integer iinfo;
00047 char order[1];
00048 extern int dcopy_(integer *, doublereal *, integer *,
00049 doublereal *, integer *);
00050 logical wantz;
00051 extern int zswap_(integer *, doublecomplex *, integer *,
00052 doublecomplex *, integer *);
00053 extern doublereal dlamch_(char *);
00054 logical alleig, indeig;
00055 integer iscale, indibl;
00056 logical valeig;
00057 doublereal safmin;
00058 extern int xerbla_(char *, integer *), zdscal_(
00059 integer *, doublereal *, doublecomplex *, integer *);
00060 doublereal abstll, bignum;
00061 integer indiwk, indisp, indtau;
00062 extern int dsterf_(integer *, doublereal *, doublereal *,
00063 integer *), dstebz_(char *, char *, integer *, doublereal *,
00064 doublereal *, integer *, integer *, doublereal *, doublereal *,
00065 doublereal *, integer *, integer *, doublereal *, integer *,
00066 integer *, doublereal *, integer *, integer *);
00067 extern doublereal zlanhp_(char *, char *, integer *, doublecomplex *,
00068 doublereal *);
00069 integer indrwk, indwrk, nsplit;
00070 doublereal smlnum;
00071 extern int zhptrd_(char *, integer *, doublecomplex *,
00072 doublereal *, doublereal *, doublecomplex *, integer *),
00073 zstein_(integer *, doublereal *, doublereal *, integer *,
00074 doublereal *, integer *, integer *, doublecomplex *, integer *,
00075 doublereal *, integer *, integer *, integer *), zsteqr_(char *,
00076 integer *, doublereal *, doublereal *, doublecomplex *, integer *,
00077 doublereal *, integer *), zupgtr_(char *, integer *,
00078 doublecomplex *, doublecomplex *, doublecomplex *, integer *,
00079 doublecomplex *, integer *), zupmtr_(char *, char *, char
00080 *, integer *, integer *, doublecomplex *, doublecomplex *,
00081 doublecomplex *, integer *, doublecomplex *, integer *);
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 --ap;
00231 --w;
00232 z_dim1 = *ldz;
00233 z_offset = 1 + z_dim1;
00234 z__ -= z_offset;
00235 --work;
00236 --rwork;
00237 --iwork;
00238 --ifail;
00239
00240
00241 wantz = lsame_(jobz, "V");
00242 alleig = lsame_(range, "A");
00243 valeig = lsame_(range, "V");
00244 indeig = lsame_(range, "I");
00245
00246 *info = 0;
00247 if (! (wantz || lsame_(jobz, "N"))) {
00248 *info = -1;
00249 } else if (! (alleig || valeig || indeig)) {
00250 *info = -2;
00251 } else if (! (lsame_(uplo, "L") || lsame_(uplo,
00252 "U"))) {
00253 *info = -3;
00254 } else if (*n < 0) {
00255 *info = -4;
00256 } else {
00257 if (valeig) {
00258 if (*n > 0 && *vu <= *vl) {
00259 *info = -7;
00260 }
00261 } else if (indeig) {
00262 if (*il < 1 || *il > max(1,*n)) {
00263 *info = -8;
00264 } else if (*iu < min(*n,*il) || *iu > *n) {
00265 *info = -9;
00266 }
00267 }
00268 }
00269 if (*info == 0) {
00270 if (*ldz < 1 || wantz && *ldz < *n) {
00271 *info = -14;
00272 }
00273 }
00274
00275 if (*info != 0) {
00276 i__1 = -(*info);
00277 xerbla_("ZHPEVX", &i__1);
00278 return 0;
00279 }
00280
00281
00282
00283 *m = 0;
00284 if (*n == 0) {
00285 return 0;
00286 }
00287
00288 if (*n == 1) {
00289 if (alleig || indeig) {
00290 *m = 1;
00291 w[1] = ap[1].r;
00292 } else {
00293 if (*vl < ap[1].r && *vu >= ap[1].r) {
00294 *m = 1;
00295 w[1] = ap[1].r;
00296 }
00297 }
00298 if (wantz) {
00299 i__1 = z_dim1 + 1;
00300 z__[i__1].r = 1., z__[i__1].i = 0.;
00301 }
00302 return 0;
00303 }
00304
00305
00306
00307 safmin = dlamch_("Safe minimum");
00308 eps = dlamch_("Precision");
00309 smlnum = safmin / eps;
00310 bignum = 1. / smlnum;
00311 rmin = sqrt(smlnum);
00312
00313 d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00314 rmax = min(d__1,d__2);
00315
00316
00317
00318 iscale = 0;
00319 abstll = *abstol;
00320 if (valeig) {
00321 vll = *vl;
00322 vuu = *vu;
00323 } else {
00324 vll = 0.;
00325 vuu = 0.;
00326 }
00327 anrm = zlanhp_("M", uplo, n, &ap[1], &rwork[1]);
00328 if (anrm > 0. && anrm < rmin) {
00329 iscale = 1;
00330 sigma = rmin / anrm;
00331 } else if (anrm > rmax) {
00332 iscale = 1;
00333 sigma = rmax / anrm;
00334 }
00335 if (iscale == 1) {
00336 i__1 = *n * (*n + 1) / 2;
00337 zdscal_(&i__1, &sigma, &ap[1], &c__1);
00338 if (*abstol > 0.) {
00339 abstll = *abstol * sigma;
00340 }
00341 if (valeig) {
00342 vll = *vl * sigma;
00343 vuu = *vu * sigma;
00344 }
00345 }
00346
00347
00348
00349 indd = 1;
00350 inde = indd + *n;
00351 indrwk = inde + *n;
00352 indtau = 1;
00353 indwrk = indtau + *n;
00354 zhptrd_(uplo, n, &ap[1], &rwork[indd], &rwork[inde], &work[indtau], &
00355 iinfo);
00356
00357
00358
00359
00360
00361 test = FALSE_;
00362 if (indeig) {
00363 if (*il == 1 && *iu == *n) {
00364 test = TRUE_;
00365 }
00366 }
00367 if ((alleig || test) && *abstol <= 0.) {
00368 dcopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00369 indee = indrwk + (*n << 1);
00370 if (! wantz) {
00371 i__1 = *n - 1;
00372 dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00373 dsterf_(n, &w[1], &rwork[indee], info);
00374 } else {
00375 zupgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, &
00376 work[indwrk], &iinfo);
00377 i__1 = *n - 1;
00378 dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00379 zsteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00380 rwork[indrwk], info);
00381 if (*info == 0) {
00382 i__1 = *n;
00383 for (i__ = 1; i__ <= i__1; ++i__) {
00384 ifail[i__] = 0;
00385
00386 }
00387 }
00388 }
00389 if (*info == 0) {
00390 *m = *n;
00391 goto L20;
00392 }
00393 *info = 0;
00394 }
00395
00396
00397
00398 if (wantz) {
00399 *(unsigned char *)order = 'B';
00400 } else {
00401 *(unsigned char *)order = 'E';
00402 }
00403 indibl = 1;
00404 indisp = indibl + *n;
00405 indiwk = indisp + *n;
00406 dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
00407 rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00408 rwork[indrwk], &iwork[indiwk], info);
00409
00410 if (wantz) {
00411 zstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00412 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00413 indiwk], &ifail[1], info);
00414
00415
00416
00417
00418 indwrk = indtau + *n;
00419 zupmtr_("L", uplo, "N", n, m, &ap[1], &work[indtau], &z__[z_offset],
00420 ldz, &work[indwrk], &iinfo);
00421 }
00422
00423
00424
00425 L20:
00426 if (iscale == 1) {
00427 if (*info == 0) {
00428 imax = *m;
00429 } else {
00430 imax = *info - 1;
00431 }
00432 d__1 = 1. / sigma;
00433 dscal_(&imax, &d__1, &w[1], &c__1);
00434 }
00435
00436
00437
00438
00439 if (wantz) {
00440 i__1 = *m - 1;
00441 for (j = 1; j <= i__1; ++j) {
00442 i__ = 0;
00443 tmp1 = w[j];
00444 i__2 = *m;
00445 for (jj = j + 1; jj <= i__2; ++jj) {
00446 if (w[jj] < tmp1) {
00447 i__ = jj;
00448 tmp1 = w[jj];
00449 }
00450
00451 }
00452
00453 if (i__ != 0) {
00454 itmp1 = iwork[indibl + i__ - 1];
00455 w[i__] = w[j];
00456 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00457 w[j] = tmp1;
00458 iwork[indibl + j - 1] = itmp1;
00459 zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
00460 &c__1);
00461 if (*info != 0) {
00462 itmp1 = ifail[i__];
00463 ifail[i__] = ifail[j];
00464 ifail[j] = itmp1;
00465 }
00466 }
00467
00468 }
00469 }
00470
00471 return 0;
00472
00473
00474
00475 }