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