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