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