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__0 = 0;
00019 static integer c__1 = 1;
00020 static doublereal c_b32 = 1.;
00021
00022 int dsterf_(integer *n, doublereal *d__, doublereal *e,
00023 integer *info)
00024 {
00025
00026 integer i__1;
00027 doublereal d__1, d__2, d__3;
00028
00029
00030 double sqrt(doublereal), d_sign(doublereal *, doublereal *);
00031
00032
00033 doublereal c__;
00034 integer i__, l, m;
00035 doublereal p, r__, s;
00036 integer l1;
00037 doublereal bb, rt1, rt2, eps, rte;
00038 integer lsv;
00039 doublereal eps2, oldc;
00040 integer lend, jtot;
00041 extern int dlae2_(doublereal *, doublereal *, doublereal
00042 *, doublereal *, doublereal *);
00043 doublereal gamma, alpha, sigma, anorm;
00044 extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
00045 integer iscale;
00046 extern int dlascl_(char *, integer *, integer *,
00047 doublereal *, doublereal *, integer *, integer *, doublereal *,
00048 integer *, integer *);
00049 doublereal oldgam, safmin;
00050 extern int xerbla_(char *, integer *);
00051 doublereal safmax;
00052 extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00053 extern int dlasrt_(char *, integer *, doublereal *,
00054 integer *);
00055 integer lendsv;
00056 doublereal ssfmin;
00057 integer nmaxit;
00058 doublereal ssfmax;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
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 --e;
00116 --d__;
00117
00118
00119 *info = 0;
00120
00121
00122
00123 if (*n < 0) {
00124 *info = -1;
00125 i__1 = -(*info);
00126 xerbla_("DSTERF", &i__1);
00127 return 0;
00128 }
00129 if (*n <= 1) {
00130 return 0;
00131 }
00132
00133
00134
00135 eps = dlamch_("E");
00136
00137 d__1 = eps;
00138 eps2 = d__1 * d__1;
00139 safmin = dlamch_("S");
00140 safmax = 1. / safmin;
00141 ssfmax = sqrt(safmax) / 3.;
00142 ssfmin = sqrt(safmin) / eps2;
00143
00144
00145
00146 nmaxit = *n * 30;
00147 sigma = 0.;
00148 jtot = 0;
00149
00150
00151
00152
00153
00154 l1 = 1;
00155
00156 L10:
00157 if (l1 > *n) {
00158 goto L170;
00159 }
00160 if (l1 > 1) {
00161 e[l1 - 1] = 0.;
00162 }
00163 i__1 = *n - 1;
00164 for (m = l1; m <= i__1; ++m) {
00165 if ((d__3 = e[m], abs(d__3)) <= sqrt((d__1 = d__[m], abs(d__1))) *
00166 sqrt((d__2 = d__[m + 1], abs(d__2))) * eps) {
00167 e[m] = 0.;
00168 goto L30;
00169 }
00170
00171 }
00172 m = *n;
00173
00174 L30:
00175 l = l1;
00176 lsv = l;
00177 lend = m;
00178 lendsv = lend;
00179 l1 = m + 1;
00180 if (lend == l) {
00181 goto L10;
00182 }
00183
00184
00185
00186 i__1 = lend - l + 1;
00187 anorm = dlanst_("I", &i__1, &d__[l], &e[l]);
00188 iscale = 0;
00189 if (anorm > ssfmax) {
00190 iscale = 1;
00191 i__1 = lend - l + 1;
00192 dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n,
00193 info);
00194 i__1 = lend - l;
00195 dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n,
00196 info);
00197 } else if (anorm < ssfmin) {
00198 iscale = 2;
00199 i__1 = lend - l + 1;
00200 dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n,
00201 info);
00202 i__1 = lend - l;
00203 dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n,
00204 info);
00205 }
00206
00207 i__1 = lend - 1;
00208 for (i__ = l; i__ <= i__1; ++i__) {
00209
00210 d__1 = e[i__];
00211 e[i__] = d__1 * d__1;
00212
00213 }
00214
00215
00216
00217 if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) {
00218 lend = lsv;
00219 l = lendsv;
00220 }
00221
00222 if (lend >= l) {
00223
00224
00225
00226
00227
00228 L50:
00229 if (l != lend) {
00230 i__1 = lend - 1;
00231 for (m = l; m <= i__1; ++m) {
00232 if ((d__2 = e[m], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m
00233 + 1], abs(d__1))) {
00234 goto L70;
00235 }
00236
00237 }
00238 }
00239 m = lend;
00240
00241 L70:
00242 if (m < lend) {
00243 e[m] = 0.;
00244 }
00245 p = d__[l];
00246 if (m == l) {
00247 goto L90;
00248 }
00249
00250
00251
00252
00253 if (m == l + 1) {
00254 rte = sqrt(e[l]);
00255 dlae2_(&d__[l], &rte, &d__[l + 1], &rt1, &rt2);
00256 d__[l] = rt1;
00257 d__[l + 1] = rt2;
00258 e[l] = 0.;
00259 l += 2;
00260 if (l <= lend) {
00261 goto L50;
00262 }
00263 goto L150;
00264 }
00265
00266 if (jtot == nmaxit) {
00267 goto L150;
00268 }
00269 ++jtot;
00270
00271
00272
00273 rte = sqrt(e[l]);
00274 sigma = (d__[l + 1] - p) / (rte * 2.);
00275 r__ = dlapy2_(&sigma, &c_b32);
00276 sigma = p - rte / (sigma + d_sign(&r__, &sigma));
00277
00278 c__ = 1.;
00279 s = 0.;
00280 gamma = d__[m] - sigma;
00281 p = gamma * gamma;
00282
00283
00284
00285 i__1 = l;
00286 for (i__ = m - 1; i__ >= i__1; --i__) {
00287 bb = e[i__];
00288 r__ = p + bb;
00289 if (i__ != m - 1) {
00290 e[i__ + 1] = s * r__;
00291 }
00292 oldc = c__;
00293 c__ = p / r__;
00294 s = bb / r__;
00295 oldgam = gamma;
00296 alpha = d__[i__];
00297 gamma = c__ * (alpha - sigma) - s * oldgam;
00298 d__[i__ + 1] = oldgam + (alpha - gamma);
00299 if (c__ != 0.) {
00300 p = gamma * gamma / c__;
00301 } else {
00302 p = oldc * bb;
00303 }
00304
00305 }
00306
00307 e[l] = s * p;
00308 d__[l] = sigma + gamma;
00309 goto L50;
00310
00311
00312
00313 L90:
00314 d__[l] = p;
00315
00316 ++l;
00317 if (l <= lend) {
00318 goto L50;
00319 }
00320 goto L150;
00321
00322 } else {
00323
00324
00325
00326
00327
00328 L100:
00329 i__1 = lend + 1;
00330 for (m = l; m >= i__1; --m) {
00331 if ((d__2 = e[m - 1], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m
00332 - 1], abs(d__1))) {
00333 goto L120;
00334 }
00335
00336 }
00337 m = lend;
00338
00339 L120:
00340 if (m > lend) {
00341 e[m - 1] = 0.;
00342 }
00343 p = d__[l];
00344 if (m == l) {
00345 goto L140;
00346 }
00347
00348
00349
00350
00351 if (m == l - 1) {
00352 rte = sqrt(e[l - 1]);
00353 dlae2_(&d__[l], &rte, &d__[l - 1], &rt1, &rt2);
00354 d__[l] = rt1;
00355 d__[l - 1] = rt2;
00356 e[l - 1] = 0.;
00357 l += -2;
00358 if (l >= lend) {
00359 goto L100;
00360 }
00361 goto L150;
00362 }
00363
00364 if (jtot == nmaxit) {
00365 goto L150;
00366 }
00367 ++jtot;
00368
00369
00370
00371 rte = sqrt(e[l - 1]);
00372 sigma = (d__[l - 1] - p) / (rte * 2.);
00373 r__ = dlapy2_(&sigma, &c_b32);
00374 sigma = p - rte / (sigma + d_sign(&r__, &sigma));
00375
00376 c__ = 1.;
00377 s = 0.;
00378 gamma = d__[m] - sigma;
00379 p = gamma * gamma;
00380
00381
00382
00383 i__1 = l - 1;
00384 for (i__ = m; i__ <= i__1; ++i__) {
00385 bb = e[i__];
00386 r__ = p + bb;
00387 if (i__ != m) {
00388 e[i__ - 1] = s * r__;
00389 }
00390 oldc = c__;
00391 c__ = p / r__;
00392 s = bb / r__;
00393 oldgam = gamma;
00394 alpha = d__[i__ + 1];
00395 gamma = c__ * (alpha - sigma) - s * oldgam;
00396 d__[i__] = oldgam + (alpha - gamma);
00397 if (c__ != 0.) {
00398 p = gamma * gamma / c__;
00399 } else {
00400 p = oldc * bb;
00401 }
00402
00403 }
00404
00405 e[l - 1] = s * p;
00406 d__[l] = sigma + gamma;
00407 goto L100;
00408
00409
00410
00411 L140:
00412 d__[l] = p;
00413
00414 --l;
00415 if (l >= lend) {
00416 goto L100;
00417 }
00418 goto L150;
00419
00420 }
00421
00422
00423
00424 L150:
00425 if (iscale == 1) {
00426 i__1 = lendsv - lsv + 1;
00427 dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv],
00428 n, info);
00429 }
00430 if (iscale == 2) {
00431 i__1 = lendsv - lsv + 1;
00432 dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv],
00433 n, info);
00434 }
00435
00436
00437
00438
00439 if (jtot < nmaxit) {
00440 goto L10;
00441 }
00442 i__1 = *n - 1;
00443 for (i__ = 1; i__ <= i__1; ++i__) {
00444 if (e[i__] != 0.) {
00445 ++(*info);
00446 }
00447
00448 }
00449 goto L180;
00450
00451
00452
00453 L170:
00454 dlasrt_("I", n, &d__[1], info);
00455
00456 L180:
00457 return 0;
00458
00459
00460
00461 }