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_b13 = 1.f;
00021 static integer c__1 = 1;
00022
00023 int chbevd_(char *jobz, char *uplo, integer *n, integer *kd,
00024 complex *ab, integer *ldab, real *w, complex *z__, integer *ldz,
00025 complex *work, integer *lwork, real *rwork, integer *lrwork, integer *
00026 iwork, integer *liwork, integer *info)
00027 {
00028
00029 integer ab_dim1, ab_offset, z_dim1, z_offset, i__1;
00030 real r__1;
00031
00032
00033 double sqrt(doublereal);
00034
00035
00036 real eps;
00037 integer inde;
00038 real anrm;
00039 integer imax;
00040 real rmin, rmax;
00041 integer llwk2;
00042 extern int cgemm_(char *, char *, integer *, integer *,
00043 integer *, complex *, complex *, integer *, complex *, integer *,
00044 complex *, complex *, integer *);
00045 real sigma;
00046 extern logical lsame_(char *, char *);
00047 integer iinfo;
00048 extern int sscal_(integer *, real *, real *, integer *);
00049 integer lwmin;
00050 logical lower;
00051 integer llrwk;
00052 logical wantz;
00053 integer indwk2;
00054 extern doublereal clanhb_(char *, char *, integer *, integer *, complex *,
00055 integer *, real *);
00056 integer iscale;
00057 extern int clascl_(char *, integer *, integer *, real *,
00058 real *, integer *, integer *, complex *, integer *, integer *), cstedc_(char *, integer *, real *, real *, complex *,
00059 integer *, complex *, integer *, real *, integer *, integer *,
00060 integer *, integer *), chbtrd_(char *, char *, integer *,
00061 integer *, complex *, integer *, real *, real *, complex *,
00062 integer *, complex *, integer *);
00063 extern doublereal slamch_(char *);
00064 extern int clacpy_(char *, integer *, integer *, complex
00065 *, integer *, complex *, integer *);
00066 real safmin;
00067 extern int xerbla_(char *, integer *);
00068 real bignum;
00069 integer indwrk, liwmin;
00070 extern int ssterf_(integer *, real *, real *, integer *);
00071 integer lrwmin;
00072 real smlnum;
00073 logical lquery;
00074
00075
00076
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 ab_dim1 = *ldab;
00219 ab_offset = 1 + ab_dim1;
00220 ab -= ab_offset;
00221 --w;
00222 z_dim1 = *ldz;
00223 z_offset = 1 + z_dim1;
00224 z__ -= z_offset;
00225 --work;
00226 --rwork;
00227 --iwork;
00228
00229
00230 wantz = lsame_(jobz, "V");
00231 lower = lsame_(uplo, "L");
00232 lquery = *lwork == -1 || *liwork == -1 || *lrwork == -1;
00233
00234 *info = 0;
00235 if (*n <= 1) {
00236 lwmin = 1;
00237 lrwmin = 1;
00238 liwmin = 1;
00239 } else {
00240 if (wantz) {
00241
00242 i__1 = *n;
00243 lwmin = i__1 * i__1 << 1;
00244
00245 i__1 = *n;
00246 lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
00247 liwmin = *n * 5 + 3;
00248 } else {
00249 lwmin = *n;
00250 lrwmin = *n;
00251 liwmin = 1;
00252 }
00253 }
00254 if (! (wantz || lsame_(jobz, "N"))) {
00255 *info = -1;
00256 } else if (! (lower || lsame_(uplo, "U"))) {
00257 *info = -2;
00258 } else if (*n < 0) {
00259 *info = -3;
00260 } else if (*kd < 0) {
00261 *info = -4;
00262 } else if (*ldab < *kd + 1) {
00263 *info = -6;
00264 } else if (*ldz < 1 || wantz && *ldz < *n) {
00265 *info = -9;
00266 }
00267
00268 if (*info == 0) {
00269 work[1].r = (real) lwmin, work[1].i = 0.f;
00270 rwork[1] = (real) lrwmin;
00271 iwork[1] = liwmin;
00272
00273 if (*lwork < lwmin && ! lquery) {
00274 *info = -11;
00275 } else if (*lrwork < lrwmin && ! lquery) {
00276 *info = -13;
00277 } else if (*liwork < liwmin && ! lquery) {
00278 *info = -15;
00279 }
00280 }
00281
00282 if (*info != 0) {
00283 i__1 = -(*info);
00284 xerbla_("CHBEVD", &i__1);
00285 return 0;
00286 } else if (lquery) {
00287 return 0;
00288 }
00289
00290
00291
00292 if (*n == 0) {
00293 return 0;
00294 }
00295
00296 if (*n == 1) {
00297 i__1 = ab_dim1 + 1;
00298 w[1] = ab[i__1].r;
00299 if (wantz) {
00300 i__1 = z_dim1 + 1;
00301 z__[i__1].r = 1.f, z__[i__1].i = 0.f;
00302 }
00303 return 0;
00304 }
00305
00306
00307
00308 safmin = slamch_("Safe minimum");
00309 eps = slamch_("Precision");
00310 smlnum = safmin / eps;
00311 bignum = 1.f / smlnum;
00312 rmin = sqrt(smlnum);
00313 rmax = sqrt(bignum);
00314
00315
00316
00317 anrm = clanhb_("M", uplo, n, kd, &ab[ab_offset], ldab, &rwork[1]);
00318 iscale = 0;
00319 if (anrm > 0.f && anrm < rmin) {
00320 iscale = 1;
00321 sigma = rmin / anrm;
00322 } else if (anrm > rmax) {
00323 iscale = 1;
00324 sigma = rmax / anrm;
00325 }
00326 if (iscale == 1) {
00327 if (lower) {
00328 clascl_("B", kd, kd, &c_b13, &sigma, n, n, &ab[ab_offset], ldab,
00329 info);
00330 } else {
00331 clascl_("Q", kd, kd, &c_b13, &sigma, n, n, &ab[ab_offset], ldab,
00332 info);
00333 }
00334 }
00335
00336
00337
00338 inde = 1;
00339 indwrk = inde + *n;
00340 indwk2 = *n * *n + 1;
00341 llwk2 = *lwork - indwk2 + 1;
00342 llrwk = *lrwork - indwrk + 1;
00343 chbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &rwork[inde], &
00344 z__[z_offset], ldz, &work[1], &iinfo);
00345
00346
00347
00348 if (! wantz) {
00349 ssterf_(n, &w[1], &rwork[inde], info);
00350 } else {
00351 cstedc_("I", n, &w[1], &rwork[inde], &work[1], n, &work[indwk2], &
00352 llwk2, &rwork[indwrk], &llrwk, &iwork[1], liwork, info);
00353 cgemm_("N", "N", n, n, n, &c_b2, &z__[z_offset], ldz, &work[1], n, &
00354 c_b1, &work[indwk2], n);
00355 clacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz);
00356 }
00357
00358
00359
00360 if (iscale == 1) {
00361 if (*info == 0) {
00362 imax = *n;
00363 } else {
00364 imax = *info - 1;
00365 }
00366 r__1 = 1.f / sigma;
00367 sscal_(&imax, &r__1, &w[1], &c__1);
00368 }
00369
00370 work[1].r = (real) lwmin, work[1].i = 0.f;
00371 rwork[1] = (real) lrwmin;
00372 iwork[1] = liwmin;
00373 return 0;
00374
00375
00376
00377 }