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 doublereal c_b18 = 1.;
00022
00023 int zheevd_(char *jobz, char *uplo, integer *n,
00024 doublecomplex *a, integer *lda, doublereal *w, doublecomplex *work,
00025 integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork,
00026 integer *liwork, integer *info)
00027 {
00028
00029 integer a_dim1, a_offset, i__1, i__2;
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 lopt;
00042 extern int dscal_(integer *, doublereal *, doublereal *,
00043 integer *);
00044 doublereal sigma;
00045 extern logical lsame_(char *, char *);
00046 integer iinfo, lwmin, liopt;
00047 logical lower;
00048 integer llrwk, lropt;
00049 logical wantz;
00050 integer indwk2, llwrk2;
00051 extern doublereal dlamch_(char *);
00052 integer iscale;
00053 doublereal safmin;
00054 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00055 integer *, integer *);
00056 extern int xerbla_(char *, integer *);
00057 doublereal bignum;
00058 extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *,
00059 integer *, doublereal *);
00060 integer indtau;
00061 extern int dsterf_(integer *, doublereal *, doublereal *,
00062 integer *), zlascl_(char *, integer *, integer *, doublereal *,
00063 doublereal *, integer *, integer *, doublecomplex *, integer *,
00064 integer *), zstedc_(char *, integer *, doublereal *,
00065 doublereal *, doublecomplex *, integer *, doublecomplex *,
00066 integer *, doublereal *, integer *, integer *, integer *, integer
00067 *);
00068 integer indrwk, indwrk, liwmin;
00069 extern int zhetrd_(char *, integer *, doublecomplex *,
00070 integer *, doublereal *, doublereal *, doublecomplex *,
00071 doublecomplex *, integer *, integer *), zlacpy_(char *,
00072 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00073 integer *);
00074 integer lrwmin, llwork;
00075 doublereal smlnum;
00076 logical lquery;
00077 extern int zunmtr_(char *, char *, char *, integer *,
00078 integer *, doublecomplex *, integer *, doublecomplex *,
00079 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
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 a_dim1 = *lda;
00221 a_offset = 1 + a_dim1;
00222 a -= a_offset;
00223 --w;
00224 --work;
00225 --rwork;
00226 --iwork;
00227
00228
00229 wantz = lsame_(jobz, "V");
00230 lower = lsame_(uplo, "L");
00231 lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
00232
00233 *info = 0;
00234 if (! (wantz || lsame_(jobz, "N"))) {
00235 *info = -1;
00236 } else if (! (lower || lsame_(uplo, "U"))) {
00237 *info = -2;
00238 } else if (*n < 0) {
00239 *info = -3;
00240 } else if (*lda < max(1,*n)) {
00241 *info = -5;
00242 }
00243
00244 if (*info == 0) {
00245 if (*n <= 1) {
00246 lwmin = 1;
00247 lrwmin = 1;
00248 liwmin = 1;
00249 lopt = lwmin;
00250 lropt = lrwmin;
00251 liopt = liwmin;
00252 } else {
00253 if (wantz) {
00254 lwmin = (*n << 1) + *n * *n;
00255
00256 i__1 = *n;
00257 lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
00258 liwmin = *n * 5 + 3;
00259 } else {
00260 lwmin = *n + 1;
00261 lrwmin = *n;
00262 liwmin = 1;
00263 }
00264
00265 i__1 = lwmin, i__2 = *n + ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1,
00266 &c_n1, &c_n1);
00267 lopt = max(i__1,i__2);
00268 lropt = lrwmin;
00269 liopt = liwmin;
00270 }
00271 work[1].r = (doublereal) lopt, work[1].i = 0.;
00272 rwork[1] = (doublereal) lropt;
00273 iwork[1] = liopt;
00274
00275 if (*lwork < lwmin && ! lquery) {
00276 *info = -8;
00277 } else if (*lrwork < lrwmin && ! lquery) {
00278 *info = -10;
00279 } else if (*liwork < liwmin && ! lquery) {
00280 *info = -12;
00281 }
00282 }
00283
00284 if (*info != 0) {
00285 i__1 = -(*info);
00286 xerbla_("ZHEEVD", &i__1);
00287 return 0;
00288 } else if (lquery) {
00289 return 0;
00290 }
00291
00292
00293
00294 if (*n == 0) {
00295 return 0;
00296 }
00297
00298 if (*n == 1) {
00299 i__1 = a_dim1 + 1;
00300 w[1] = a[i__1].r;
00301 if (wantz) {
00302 i__1 = a_dim1 + 1;
00303 a[i__1].r = 1., a[i__1].i = 0.;
00304 }
00305 return 0;
00306 }
00307
00308
00309
00310 safmin = dlamch_("Safe minimum");
00311 eps = dlamch_("Precision");
00312 smlnum = safmin / eps;
00313 bignum = 1. / smlnum;
00314 rmin = sqrt(smlnum);
00315 rmax = sqrt(bignum);
00316
00317
00318
00319 anrm = zlanhe_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
00320 iscale = 0;
00321 if (anrm > 0. && anrm < rmin) {
00322 iscale = 1;
00323 sigma = rmin / anrm;
00324 } else if (anrm > rmax) {
00325 iscale = 1;
00326 sigma = rmax / anrm;
00327 }
00328 if (iscale == 1) {
00329 zlascl_(uplo, &c__0, &c__0, &c_b18, &sigma, n, n, &a[a_offset], lda,
00330 info);
00331 }
00332
00333
00334
00335 inde = 1;
00336 indtau = 1;
00337 indwrk = indtau + *n;
00338 indrwk = inde + *n;
00339 indwk2 = indwrk + *n * *n;
00340 llwork = *lwork - indwrk + 1;
00341 llwrk2 = *lwork - indwk2 + 1;
00342 llrwk = *lrwork - indrwk + 1;
00343 zhetrd_(uplo, n, &a[a_offset], lda, &w[1], &rwork[inde], &work[indtau], &
00344 work[indwrk], &llwork, &iinfo);
00345
00346
00347
00348
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[indwrk], n, &work[indwk2],
00356 &llwrk2, &rwork[indrwk], &llrwk, &iwork[1], liwork, info);
00357 zunmtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
00358 indwrk], n, &work[indwk2], &llwrk2, &iinfo);
00359 zlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
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) lopt, work[1].i = 0.;
00375 rwork[1] = (doublereal) lropt;
00376 iwork[1] = liopt;
00377
00378 return 0;
00379
00380
00381
00382 }