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__1 = 1;
00019 static integer c__2 = 2;
00020 static integer c__10 = 10;
00021 static integer c__3 = 3;
00022 static integer c__4 = 4;
00023 static integer c__11 = 11;
00024
00025 int dlasq2_(integer *n, doublereal *z__, integer *info)
00026 {
00027
00028 integer i__1, i__2, i__3;
00029 doublereal d__1, d__2;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 doublereal d__, e, g;
00036 integer k;
00037 doublereal s, t;
00038 integer i0, i4, n0;
00039 doublereal dn;
00040 integer pp;
00041 doublereal dn1, dn2, dee, eps, tau, tol;
00042 integer ipn4;
00043 doublereal tol2;
00044 logical ieee;
00045 integer nbig;
00046 doublereal dmin__, emin, emax;
00047 integer kmin, ndiv, iter;
00048 doublereal qmin, temp, qmax, zmax;
00049 integer splt;
00050 doublereal dmin1, dmin2;
00051 integer nfail;
00052 doublereal desig, trace, sigma;
00053 integer iinfo, ttype;
00054 extern int dlasq3_(integer *, integer *, doublereal *,
00055 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
00056 integer *, integer *, integer *, logical *, integer *,
00057 doublereal *, doublereal *, doublereal *, doublereal *,
00058 doublereal *, doublereal *, doublereal *);
00059 extern doublereal dlamch_(char *);
00060 doublereal deemin;
00061 integer iwhila, iwhilb;
00062 doublereal oldemn, safmin;
00063 extern int xerbla_(char *, integer *);
00064 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00065 integer *, integer *);
00066 extern int dlasrt_(char *, integer *, doublereal *,
00067 integer *);
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
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 --z__;
00156
00157
00158 *info = 0;
00159 eps = dlamch_("Precision");
00160 safmin = dlamch_("Safe minimum");
00161 tol = eps * 100.;
00162
00163 d__1 = tol;
00164 tol2 = d__1 * d__1;
00165
00166 if (*n < 0) {
00167 *info = -1;
00168 xerbla_("DLASQ2", &c__1);
00169 return 0;
00170 } else if (*n == 0) {
00171 return 0;
00172 } else if (*n == 1) {
00173
00174
00175
00176 if (z__[1] < 0.) {
00177 *info = -201;
00178 xerbla_("DLASQ2", &c__2);
00179 }
00180 return 0;
00181 } else if (*n == 2) {
00182
00183
00184
00185 if (z__[2] < 0. || z__[3] < 0.) {
00186 *info = -2;
00187 xerbla_("DLASQ2", &c__2);
00188 return 0;
00189 } else if (z__[3] > z__[1]) {
00190 d__ = z__[3];
00191 z__[3] = z__[1];
00192 z__[1] = d__;
00193 }
00194 z__[5] = z__[1] + z__[2] + z__[3];
00195 if (z__[2] > z__[3] * tol2) {
00196 t = (z__[1] - z__[3] + z__[2]) * .5;
00197 s = z__[3] * (z__[2] / t);
00198 if (s <= t) {
00199 s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.) + 1.)));
00200 } else {
00201 s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
00202 }
00203 t = z__[1] + (s + z__[2]);
00204 z__[3] *= z__[1] / t;
00205 z__[1] = t;
00206 }
00207 z__[2] = z__[3];
00208 z__[6] = z__[2] + z__[1];
00209 return 0;
00210 }
00211
00212
00213
00214 z__[*n * 2] = 0.;
00215 emin = z__[2];
00216 qmax = 0.;
00217 zmax = 0.;
00218 d__ = 0.;
00219 e = 0.;
00220
00221 i__1 = *n - 1 << 1;
00222 for (k = 1; k <= i__1; k += 2) {
00223 if (z__[k] < 0.) {
00224 *info = -(k + 200);
00225 xerbla_("DLASQ2", &c__2);
00226 return 0;
00227 } else if (z__[k + 1] < 0.) {
00228 *info = -(k + 201);
00229 xerbla_("DLASQ2", &c__2);
00230 return 0;
00231 }
00232 d__ += z__[k];
00233 e += z__[k + 1];
00234
00235 d__1 = qmax, d__2 = z__[k];
00236 qmax = max(d__1,d__2);
00237
00238 d__1 = emin, d__2 = z__[k + 1];
00239 emin = min(d__1,d__2);
00240
00241 d__1 = max(qmax,zmax), d__2 = z__[k + 1];
00242 zmax = max(d__1,d__2);
00243
00244 }
00245 if (z__[(*n << 1) - 1] < 0.) {
00246 *info = -((*n << 1) + 199);
00247 xerbla_("DLASQ2", &c__2);
00248 return 0;
00249 }
00250 d__ += z__[(*n << 1) - 1];
00251
00252 d__1 = qmax, d__2 = z__[(*n << 1) - 1];
00253 qmax = max(d__1,d__2);
00254 zmax = max(qmax,zmax);
00255
00256
00257
00258 if (e == 0.) {
00259 i__1 = *n;
00260 for (k = 2; k <= i__1; ++k) {
00261 z__[k] = z__[(k << 1) - 1];
00262
00263 }
00264 dlasrt_("D", n, &z__[1], &iinfo);
00265 z__[(*n << 1) - 1] = d__;
00266 return 0;
00267 }
00268
00269 trace = d__ + e;
00270
00271
00272
00273 if (trace == 0.) {
00274 z__[(*n << 1) - 1] = 0.;
00275 return 0;
00276 }
00277
00278
00279
00280 ieee = ilaenv_(&c__10, "DLASQ2", "N", &c__1, &c__2, &c__3, &c__4) == 1 && ilaenv_(&c__11, "DLASQ2", "N", &c__1, &c__2,
00281 &c__3, &c__4) == 1;
00282
00283
00284
00285 for (k = *n << 1; k >= 2; k += -2) {
00286 z__[k * 2] = 0.;
00287 z__[(k << 1) - 1] = z__[k];
00288 z__[(k << 1) - 2] = 0.;
00289 z__[(k << 1) - 3] = z__[k - 1];
00290
00291 }
00292
00293 i0 = 1;
00294 n0 = *n;
00295
00296
00297
00298 if (z__[(i0 << 2) - 3] * 1.5 < z__[(n0 << 2) - 3]) {
00299 ipn4 = i0 + n0 << 2;
00300 i__1 = i0 + n0 - 1 << 1;
00301 for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
00302 temp = z__[i4 - 3];
00303 z__[i4 - 3] = z__[ipn4 - i4 - 3];
00304 z__[ipn4 - i4 - 3] = temp;
00305 temp = z__[i4 - 1];
00306 z__[i4 - 1] = z__[ipn4 - i4 - 5];
00307 z__[ipn4 - i4 - 5] = temp;
00308
00309 }
00310 }
00311
00312
00313
00314 pp = 0;
00315
00316 for (k = 1; k <= 2; ++k) {
00317
00318 d__ = z__[(n0 << 2) + pp - 3];
00319 i__1 = (i0 << 2) + pp;
00320 for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
00321 if (z__[i4 - 1] <= tol2 * d__) {
00322 z__[i4 - 1] = -0.;
00323 d__ = z__[i4 - 3];
00324 } else {
00325 d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
00326 }
00327
00328 }
00329
00330
00331
00332 emin = z__[(i0 << 2) + pp + 1];
00333 d__ = z__[(i0 << 2) + pp - 3];
00334 i__1 = (n0 - 1 << 2) + pp;
00335 for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
00336 z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
00337 if (z__[i4 - 1] <= tol2 * d__) {
00338 z__[i4 - 1] = -0.;
00339 z__[i4 - (pp << 1) - 2] = d__;
00340 z__[i4 - (pp << 1)] = 0.;
00341 d__ = z__[i4 + 1];
00342 } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] &&
00343 safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
00344 temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
00345 z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
00346 d__ *= temp;
00347 } else {
00348 z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
00349 pp << 1) - 2]);
00350 d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
00351 }
00352
00353 d__1 = emin, d__2 = z__[i4 - (pp << 1)];
00354 emin = min(d__1,d__2);
00355
00356 }
00357 z__[(n0 << 2) - pp - 2] = d__;
00358
00359
00360
00361 qmax = z__[(i0 << 2) - pp - 2];
00362 i__1 = (n0 << 2) - pp - 2;
00363 for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
00364
00365 d__1 = qmax, d__2 = z__[i4];
00366 qmax = max(d__1,d__2);
00367
00368 }
00369
00370
00371
00372 pp = 1 - pp;
00373
00374 }
00375
00376
00377
00378 ttype = 0;
00379 dmin1 = 0.;
00380 dmin2 = 0.;
00381 dn = 0.;
00382 dn1 = 0.;
00383 dn2 = 0.;
00384 g = 0.;
00385 tau = 0.;
00386
00387 iter = 2;
00388 nfail = 0;
00389 ndiv = n0 - i0 << 1;
00390
00391 i__1 = *n + 1;
00392 for (iwhila = 1; iwhila <= i__1; ++iwhila) {
00393 if (n0 < 1) {
00394 goto L170;
00395 }
00396
00397
00398
00399
00400
00401
00402 desig = 0.;
00403 if (n0 == *n) {
00404 sigma = 0.;
00405 } else {
00406 sigma = -z__[(n0 << 2) - 1];
00407 }
00408 if (sigma < 0.) {
00409 *info = 1;
00410 return 0;
00411 }
00412
00413
00414
00415
00416 emax = 0.;
00417 if (n0 > i0) {
00418 emin = (d__1 = z__[(n0 << 2) - 5], abs(d__1));
00419 } else {
00420 emin = 0.;
00421 }
00422 qmin = z__[(n0 << 2) - 3];
00423 qmax = qmin;
00424 for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
00425 if (z__[i4 - 5] <= 0.) {
00426 goto L100;
00427 }
00428 if (qmin >= emax * 4.) {
00429
00430 d__1 = qmin, d__2 = z__[i4 - 3];
00431 qmin = min(d__1,d__2);
00432
00433 d__1 = emax, d__2 = z__[i4 - 5];
00434 emax = max(d__1,d__2);
00435 }
00436
00437 d__1 = qmax, d__2 = z__[i4 - 7] + z__[i4 - 5];
00438 qmax = max(d__1,d__2);
00439
00440 d__1 = emin, d__2 = z__[i4 - 5];
00441 emin = min(d__1,d__2);
00442
00443 }
00444 i4 = 4;
00445
00446 L100:
00447 i0 = i4 / 4;
00448 pp = 0;
00449
00450 if (n0 - i0 > 1) {
00451 dee = z__[(i0 << 2) - 3];
00452 deemin = dee;
00453 kmin = i0;
00454 i__2 = (n0 << 2) - 3;
00455 for (i4 = (i0 << 2) + 1; i4 <= i__2; i4 += 4) {
00456 dee = z__[i4] * (dee / (dee + z__[i4 - 2]));
00457 if (dee <= deemin) {
00458 deemin = dee;
00459 kmin = (i4 + 3) / 4;
00460 }
00461
00462 }
00463 if (kmin - i0 << 1 < n0 - kmin && deemin <= z__[(n0 << 2) - 3] *
00464 .5) {
00465 ipn4 = i0 + n0 << 2;
00466 pp = 2;
00467 i__2 = i0 + n0 - 1 << 1;
00468 for (i4 = i0 << 2; i4 <= i__2; i4 += 4) {
00469 temp = z__[i4 - 3];
00470 z__[i4 - 3] = z__[ipn4 - i4 - 3];
00471 z__[ipn4 - i4 - 3] = temp;
00472 temp = z__[i4 - 2];
00473 z__[i4 - 2] = z__[ipn4 - i4 - 2];
00474 z__[ipn4 - i4 - 2] = temp;
00475 temp = z__[i4 - 1];
00476 z__[i4 - 1] = z__[ipn4 - i4 - 5];
00477 z__[ipn4 - i4 - 5] = temp;
00478 temp = z__[i4];
00479 z__[i4] = z__[ipn4 - i4 - 4];
00480 z__[ipn4 - i4 - 4] = temp;
00481
00482 }
00483 }
00484 }
00485
00486
00487
00488
00489 d__1 = 0., d__2 = qmin - sqrt(qmin) * 2. * sqrt(emax);
00490 dmin__ = -max(d__1,d__2);
00491
00492
00493
00494
00495
00496
00497
00498 nbig = (n0 - i0 + 1) * 30;
00499 i__2 = nbig;
00500 for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
00501 if (i0 > n0) {
00502 goto L150;
00503 }
00504
00505
00506
00507 dlasq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
00508 nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
00509 dn1, &dn2, &g, &tau);
00510
00511 pp = 1 - pp;
00512
00513
00514
00515 if (pp == 0 && n0 - i0 >= 3) {
00516 if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
00517 sigma) {
00518 splt = i0 - 1;
00519 qmax = z__[(i0 << 2) - 3];
00520 emin = z__[(i0 << 2) - 1];
00521 oldemn = z__[i0 * 4];
00522 i__3 = n0 - 3 << 2;
00523 for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
00524 if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <=
00525 tol2 * sigma) {
00526 z__[i4 - 1] = -sigma;
00527 splt = i4 / 4;
00528 qmax = 0.;
00529 emin = z__[i4 + 3];
00530 oldemn = z__[i4 + 4];
00531 } else {
00532
00533 d__1 = qmax, d__2 = z__[i4 + 1];
00534 qmax = max(d__1,d__2);
00535
00536 d__1 = emin, d__2 = z__[i4 - 1];
00537 emin = min(d__1,d__2);
00538
00539 d__1 = oldemn, d__2 = z__[i4];
00540 oldemn = min(d__1,d__2);
00541 }
00542
00543 }
00544 z__[(n0 << 2) - 1] = emin;
00545 z__[n0 * 4] = oldemn;
00546 i0 = splt + 1;
00547 }
00548 }
00549
00550
00551 }
00552
00553 *info = 2;
00554 return 0;
00555
00556
00557
00558 L150:
00559
00560
00561 ;
00562 }
00563
00564 *info = 3;
00565 return 0;
00566
00567
00568
00569 L170:
00570
00571
00572
00573 i__1 = *n;
00574 for (k = 2; k <= i__1; ++k) {
00575 z__[k] = z__[(k << 2) - 3];
00576
00577 }
00578
00579
00580
00581 dlasrt_("D", n, &z__[1], &iinfo);
00582
00583 e = 0.;
00584 for (k = *n; k >= 1; --k) {
00585 e += z__[k];
00586
00587 }
00588
00589
00590
00591 z__[(*n << 1) + 1] = trace;
00592 z__[(*n << 1) + 2] = e;
00593 z__[(*n << 1) + 3] = (doublereal) iter;
00594
00595 i__1 = *n;
00596 z__[(*n << 1) + 4] = (doublereal) ndiv / (doublereal) (i__1 * i__1);
00597 z__[(*n << 1) + 5] = nfail * 100. / (doublereal) iter;
00598 return 0;
00599
00600
00601
00602 }