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__9 = 9;
00019 static integer c__0 = 0;
00020 static integer c__2 = 2;
00021 static doublereal c_b17 = 0.;
00022 static doublereal c_b18 = 1.;
00023 static integer c__1 = 1;
00024
00025 int zstedc_(char *compz, integer *n, doublereal *d__,
00026 doublereal *e, doublecomplex *z__, integer *ldz, doublecomplex *work,
00027 integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork,
00028 integer *liwork, integer *info)
00029 {
00030
00031 integer z_dim1, z_offset, i__1, i__2, i__3, i__4;
00032 doublereal d__1, d__2;
00033
00034
00035 double log(doublereal);
00036 integer pow_ii(integer *, integer *);
00037 double sqrt(doublereal);
00038
00039
00040 integer i__, j, k, m;
00041 doublereal p;
00042 integer ii, ll, lgn;
00043 doublereal eps, tiny;
00044 extern logical lsame_(char *, char *);
00045 integer lwmin, start;
00046 extern int zswap_(integer *, doublecomplex *, integer *,
00047 doublecomplex *, integer *), zlaed0_(integer *, integer *,
00048 doublereal *, doublereal *, doublecomplex *, integer *,
00049 doublecomplex *, integer *, doublereal *, integer *, integer *);
00050 extern doublereal dlamch_(char *);
00051 extern int dlascl_(char *, integer *, integer *,
00052 doublereal *, doublereal *, integer *, integer *, doublereal *,
00053 integer *, integer *), dstedc_(char *, integer *,
00054 doublereal *, doublereal *, doublereal *, integer *, doublereal *,
00055 integer *, integer *, integer *, integer *), dlaset_(
00056 char *, integer *, integer *, doublereal *, doublereal *,
00057 doublereal *, integer *), xerbla_(char *, integer *);
00058 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00059 integer *, integer *);
00060 integer finish;
00061 extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00062 extern int dsterf_(integer *, doublereal *, doublereal *,
00063 integer *), zlacrm_(integer *, integer *, doublecomplex *,
00064 integer *, doublereal *, integer *, doublecomplex *, integer *,
00065 doublereal *);
00066 integer liwmin, icompz;
00067 extern int dsteqr_(char *, integer *, doublereal *,
00068 doublereal *, doublereal *, integer *, doublereal *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *,
00069 integer *, doublecomplex *, integer *);
00070 doublereal orgnrm;
00071 integer lrwmin;
00072 logical lquery;
00073 integer smlsiz;
00074 extern int zsteqr_(char *, integer *, doublereal *,
00075 doublereal *, doublecomplex *, integer *, doublereal *, integer *);
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
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 --d__;
00229 --e;
00230 z_dim1 = *ldz;
00231 z_offset = 1 + z_dim1;
00232 z__ -= z_offset;
00233 --work;
00234 --rwork;
00235 --iwork;
00236
00237
00238 *info = 0;
00239 lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
00240
00241 if (lsame_(compz, "N")) {
00242 icompz = 0;
00243 } else if (lsame_(compz, "V")) {
00244 icompz = 1;
00245 } else if (lsame_(compz, "I")) {
00246 icompz = 2;
00247 } else {
00248 icompz = -1;
00249 }
00250 if (icompz < 0) {
00251 *info = -1;
00252 } else if (*n < 0) {
00253 *info = -2;
00254 } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
00255 *info = -6;
00256 }
00257
00258 if (*info == 0) {
00259
00260
00261
00262 smlsiz = ilaenv_(&c__9, "ZSTEDC", " ", &c__0, &c__0, &c__0, &c__0);
00263 if (*n <= 1 || icompz == 0) {
00264 lwmin = 1;
00265 liwmin = 1;
00266 lrwmin = 1;
00267 } else if (*n <= smlsiz) {
00268 lwmin = 1;
00269 liwmin = 1;
00270 lrwmin = *n - 1 << 1;
00271 } else if (icompz == 1) {
00272 lgn = (integer) (log((doublereal) (*n)) / log(2.));
00273 if (pow_ii(&c__2, &lgn) < *n) {
00274 ++lgn;
00275 }
00276 if (pow_ii(&c__2, &lgn) < *n) {
00277 ++lgn;
00278 }
00279 lwmin = *n * *n;
00280
00281 i__1 = *n;
00282 lrwmin = *n * 3 + 1 + (*n << 1) * lgn + i__1 * i__1 * 3;
00283 liwmin = *n * 6 + 6 + *n * 5 * lgn;
00284 } else if (icompz == 2) {
00285 lwmin = 1;
00286
00287 i__1 = *n;
00288 lrwmin = (*n << 2) + 1 + (i__1 * i__1 << 1);
00289 liwmin = *n * 5 + 3;
00290 }
00291 work[1].r = (doublereal) lwmin, work[1].i = 0.;
00292 rwork[1] = (doublereal) lrwmin;
00293 iwork[1] = liwmin;
00294
00295 if (*lwork < lwmin && ! lquery) {
00296 *info = -8;
00297 } else if (*lrwork < lrwmin && ! lquery) {
00298 *info = -10;
00299 } else if (*liwork < liwmin && ! lquery) {
00300 *info = -12;
00301 }
00302 }
00303
00304 if (*info != 0) {
00305 i__1 = -(*info);
00306 xerbla_("ZSTEDC", &i__1);
00307 return 0;
00308 } else if (lquery) {
00309 return 0;
00310 }
00311
00312
00313
00314 if (*n == 0) {
00315 return 0;
00316 }
00317 if (*n == 1) {
00318 if (icompz != 0) {
00319 i__1 = z_dim1 + 1;
00320 z__[i__1].r = 1., z__[i__1].i = 0.;
00321 }
00322 return 0;
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 if (icompz == 0) {
00337 dsterf_(n, &d__[1], &e[1], info);
00338 goto L70;
00339 }
00340
00341
00342
00343
00344 if (*n <= smlsiz) {
00345
00346 zsteqr_(compz, n, &d__[1], &e[1], &z__[z_offset], ldz, &rwork[1],
00347 info);
00348
00349 } else {
00350
00351
00352
00353 if (icompz == 2) {
00354 dlaset_("Full", n, n, &c_b17, &c_b18, &rwork[1], n);
00355 ll = *n * *n + 1;
00356 i__1 = *lrwork - ll + 1;
00357 dstedc_("I", n, &d__[1], &e[1], &rwork[1], n, &rwork[ll], &i__1, &
00358 iwork[1], liwork, info);
00359 i__1 = *n;
00360 for (j = 1; j <= i__1; ++j) {
00361 i__2 = *n;
00362 for (i__ = 1; i__ <= i__2; ++i__) {
00363 i__3 = i__ + j * z_dim1;
00364 i__4 = (j - 1) * *n + i__;
00365 z__[i__3].r = rwork[i__4], z__[i__3].i = 0.;
00366
00367 }
00368
00369 }
00370 goto L70;
00371 }
00372
00373
00374
00375
00376
00377
00378 orgnrm = dlanst_("M", n, &d__[1], &e[1]);
00379 if (orgnrm == 0.) {
00380 goto L70;
00381 }
00382
00383 eps = dlamch_("Epsilon");
00384
00385 start = 1;
00386
00387
00388
00389 L30:
00390 if (start <= *n) {
00391
00392
00393
00394
00395
00396
00397
00398 finish = start;
00399 L40:
00400 if (finish < *n) {
00401 tiny = eps * sqrt((d__1 = d__[finish], abs(d__1))) * sqrt((
00402 d__2 = d__[finish + 1], abs(d__2)));
00403 if ((d__1 = e[finish], abs(d__1)) > tiny) {
00404 ++finish;
00405 goto L40;
00406 }
00407 }
00408
00409
00410
00411 m = finish - start + 1;
00412 if (m > smlsiz) {
00413
00414
00415
00416 orgnrm = dlanst_("M", &m, &d__[start], &e[start]);
00417 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &m, &c__1, &d__[
00418 start], &m, info);
00419 i__1 = m - 1;
00420 i__2 = m - 1;
00421 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &i__1, &c__1, &e[
00422 start], &i__2, info);
00423
00424 zlaed0_(n, &m, &d__[start], &e[start], &z__[start * z_dim1 +
00425 1], ldz, &work[1], n, &rwork[1], &iwork[1], info);
00426 if (*info > 0) {
00427 *info = (*info / (m + 1) + start - 1) * (*n + 1) + *info %
00428 (m + 1) + start - 1;
00429 goto L70;
00430 }
00431
00432
00433
00434 dlascl_("G", &c__0, &c__0, &c_b18, &orgnrm, &m, &c__1, &d__[
00435 start], &m, info);
00436
00437 } else {
00438 dsteqr_("I", &m, &d__[start], &e[start], &rwork[1], &m, &
00439 rwork[m * m + 1], info);
00440 zlacrm_(n, &m, &z__[start * z_dim1 + 1], ldz, &rwork[1], &m, &
00441 work[1], n, &rwork[m * m + 1]);
00442 zlacpy_("A", n, &m, &work[1], n, &z__[start * z_dim1 + 1],
00443 ldz);
00444 if (*info > 0) {
00445 *info = start * (*n + 1) + finish;
00446 goto L70;
00447 }
00448 }
00449
00450 start = finish + 1;
00451 goto L30;
00452 }
00453
00454
00455
00456
00457
00458
00459
00460 if (m != *n) {
00461
00462
00463
00464 i__1 = *n;
00465 for (ii = 2; ii <= i__1; ++ii) {
00466 i__ = ii - 1;
00467 k = i__;
00468 p = d__[i__];
00469 i__2 = *n;
00470 for (j = ii; j <= i__2; ++j) {
00471 if (d__[j] < p) {
00472 k = j;
00473 p = d__[j];
00474 }
00475
00476 }
00477 if (k != i__) {
00478 d__[k] = d__[i__];
00479 d__[i__] = p;
00480 zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * z_dim1
00481 + 1], &c__1);
00482 }
00483
00484 }
00485 }
00486 }
00487
00488 L70:
00489 work[1].r = (doublereal) lwmin, work[1].i = 0.;
00490 rwork[1] = (doublereal) lrwmin;
00491 iwork[1] = liwmin;
00492
00493 return 0;
00494
00495
00496
00497 }