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