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 chbgvx_(char *jobz, char *range, char *uplo, integer *n,
00023 integer *ka, integer *kb, complex *ab, integer *ldab, complex *bb,
00024 integer *ldbb, complex *q, integer *ldq, real *vl, real *vu, integer *
00025 il, integer *iu, real *abstol, integer *m, real *w, complex *z__,
00026 integer *ldz, complex *work, real *rwork, integer *iwork, integer *
00027 ifail, integer *info)
00028 {
00029
00030 integer ab_dim1, ab_offset, bb_dim1, bb_offset, q_dim1, q_offset, z_dim1,
00031 z_offset, i__1, i__2;
00032
00033
00034 integer i__, j, jj;
00035 real tmp1;
00036 integer indd, inde;
00037 char vect[1];
00038 logical test;
00039 integer itmp1, indee;
00040 extern logical lsame_(char *, char *);
00041 extern int cgemv_(char *, integer *, integer *, complex *
00042 , complex *, integer *, complex *, integer *, complex *, complex *
00043 , integer *);
00044 integer iinfo;
00045 char order[1];
00046 extern int ccopy_(integer *, complex *, integer *,
00047 complex *, integer *), cswap_(integer *, complex *, integer *,
00048 complex *, integer *);
00049 logical upper;
00050 extern int scopy_(integer *, real *, integer *, real *,
00051 integer *);
00052 logical wantz, alleig, indeig;
00053 integer indibl;
00054 extern int chbtrd_(char *, char *, integer *, integer *,
00055 complex *, integer *, real *, real *, complex *, integer *,
00056 complex *, integer *);
00057 logical valeig;
00058 extern int chbgst_(char *, char *, integer *, integer *,
00059 integer *, complex *, integer *, complex *, integer *, complex *,
00060 integer *, complex *, real *, integer *), clacpy_(
00061 char *, integer *, integer *, complex *, integer *, complex *,
00062 integer *), xerbla_(char *, integer *), cpbstf_(
00063 char *, integer *, integer *, complex *, integer *, integer *);
00064 integer indiwk, indisp;
00065 extern int cstein_(integer *, real *, real *, integer *,
00066 real *, integer *, integer *, complex *, integer *, real *,
00067 integer *, integer *, integer *);
00068 integer indrwk, indwrk;
00069 extern int csteqr_(char *, integer *, real *, real *,
00070 complex *, integer *, real *, integer *), ssterf_(integer
00071 *, real *, real *, integer *);
00072 integer nsplit;
00073 extern int sstebz_(char *, char *, integer *, real *,
00074 real *, integer *, integer *, real *, real *, real *, integer *,
00075 integer *, real *, integer *, integer *, real *, integer *,
00076 integer *);
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
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
00257
00258
00259 ab_dim1 = *ldab;
00260 ab_offset = 1 + ab_dim1;
00261 ab -= ab_offset;
00262 bb_dim1 = *ldbb;
00263 bb_offset = 1 + bb_dim1;
00264 bb -= bb_offset;
00265 q_dim1 = *ldq;
00266 q_offset = 1 + q_dim1;
00267 q -= q_offset;
00268 --w;
00269 z_dim1 = *ldz;
00270 z_offset = 1 + z_dim1;
00271 z__ -= z_offset;
00272 --work;
00273 --rwork;
00274 --iwork;
00275 --ifail;
00276
00277
00278 wantz = lsame_(jobz, "V");
00279 upper = lsame_(uplo, "U");
00280 alleig = lsame_(range, "A");
00281 valeig = lsame_(range, "V");
00282 indeig = lsame_(range, "I");
00283
00284 *info = 0;
00285 if (! (wantz || lsame_(jobz, "N"))) {
00286 *info = -1;
00287 } else if (! (alleig || valeig || indeig)) {
00288 *info = -2;
00289 } else if (! (upper || lsame_(uplo, "L"))) {
00290 *info = -3;
00291 } else if (*n < 0) {
00292 *info = -4;
00293 } else if (*ka < 0) {
00294 *info = -5;
00295 } else if (*kb < 0 || *kb > *ka) {
00296 *info = -6;
00297 } else if (*ldab < *ka + 1) {
00298 *info = -8;
00299 } else if (*ldbb < *kb + 1) {
00300 *info = -10;
00301 } else if (*ldq < 1 || wantz && *ldq < *n) {
00302 *info = -12;
00303 } else {
00304 if (valeig) {
00305 if (*n > 0 && *vu <= *vl) {
00306 *info = -14;
00307 }
00308 } else if (indeig) {
00309 if (*il < 1 || *il > max(1,*n)) {
00310 *info = -15;
00311 } else if (*iu < min(*n,*il) || *iu > *n) {
00312 *info = -16;
00313 }
00314 }
00315 }
00316 if (*info == 0) {
00317 if (*ldz < 1 || wantz && *ldz < *n) {
00318 *info = -21;
00319 }
00320 }
00321
00322 if (*info != 0) {
00323 i__1 = -(*info);
00324 xerbla_("CHBGVX", &i__1);
00325 return 0;
00326 }
00327
00328
00329
00330 *m = 0;
00331 if (*n == 0) {
00332 return 0;
00333 }
00334
00335
00336
00337 cpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info);
00338 if (*info != 0) {
00339 *info = *n + *info;
00340 return 0;
00341 }
00342
00343
00344
00345 chbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb,
00346 &q[q_offset], ldq, &work[1], &rwork[1], &iinfo);
00347
00348
00349
00350
00351 indd = 1;
00352 inde = indd + *n;
00353 indrwk = inde + *n;
00354 indwrk = 1;
00355 if (wantz) {
00356 *(unsigned char *)vect = 'U';
00357 } else {
00358 *(unsigned char *)vect = 'N';
00359 }
00360 chbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &rwork[indd], &rwork[
00361 inde], &q[q_offset], ldq, &work[indwrk], &iinfo);
00362
00363
00364
00365
00366
00367 test = FALSE_;
00368 if (indeig) {
00369 if (*il == 1 && *iu == *n) {
00370 test = TRUE_;
00371 }
00372 }
00373 if ((alleig || test) && *abstol <= 0.f) {
00374 scopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00375 indee = indrwk + (*n << 1);
00376 i__1 = *n - 1;
00377 scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00378 if (! wantz) {
00379 ssterf_(n, &w[1], &rwork[indee], info);
00380 } else {
00381 clacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz);
00382 csteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00383 rwork[indrwk], info);
00384 if (*info == 0) {
00385 i__1 = *n;
00386 for (i__ = 1; i__ <= i__1; ++i__) {
00387 ifail[i__] = 0;
00388
00389 }
00390 }
00391 }
00392 if (*info == 0) {
00393 *m = *n;
00394 goto L30;
00395 }
00396 *info = 0;
00397 }
00398
00399
00400
00401
00402 if (wantz) {
00403 *(unsigned char *)order = 'B';
00404 } else {
00405 *(unsigned char *)order = 'E';
00406 }
00407 indibl = 1;
00408 indisp = indibl + *n;
00409 indiwk = indisp + *n;
00410 sstebz_(range, order, n, vl, vu, il, iu, abstol, &rwork[indd], &rwork[
00411 inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &rwork[
00412 indrwk], &iwork[indiwk], info);
00413
00414 if (wantz) {
00415 cstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00416 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00417 indiwk], &ifail[1], info);
00418
00419
00420
00421
00422 i__1 = *m;
00423 for (j = 1; j <= i__1; ++j) {
00424 ccopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1);
00425 cgemv_("N", n, n, &c_b2, &q[q_offset], ldq, &work[1], &c__1, &
00426 c_b1, &z__[j * z_dim1 + 1], &c__1);
00427
00428 }
00429 }
00430
00431 L30:
00432
00433
00434
00435
00436 if (wantz) {
00437 i__1 = *m - 1;
00438 for (j = 1; j <= i__1; ++j) {
00439 i__ = 0;
00440 tmp1 = w[j];
00441 i__2 = *m;
00442 for (jj = j + 1; jj <= i__2; ++jj) {
00443 if (w[jj] < tmp1) {
00444 i__ = jj;
00445 tmp1 = w[jj];
00446 }
00447
00448 }
00449
00450 if (i__ != 0) {
00451 itmp1 = iwork[indibl + i__ - 1];
00452 w[i__] = w[j];
00453 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00454 w[j] = tmp1;
00455 iwork[indibl + j - 1] = itmp1;
00456 cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
00457 &c__1);
00458 if (*info != 0) {
00459 itmp1 = ifail[i__];
00460 ifail[i__] = ifail[j];
00461 ifail[j] = itmp1;
00462 }
00463 }
00464
00465 }
00466 }
00467
00468 return 0;
00469
00470
00471
00472 }