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