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