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