00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016 int clar1v_(integer *n, integer *b1, integer *bn, real *
00017 lambda, real *d__, real *l, real *ld, real *lld, real *pivmin, real *
00018 gaptol, complex *z__, logical *wantnc, integer *negcnt, real *ztz,
00019 real *mingma, integer *r__, integer *isuppz, real *nrminv, real *
00020 resid, real *rqcorr, real *work)
00021 {
00022
00023 integer i__1, i__2, i__3, i__4;
00024 real r__1;
00025 complex q__1, q__2;
00026
00027
00028 double c_abs(complex *), sqrt(doublereal);
00029
00030
00031 integer i__;
00032 real s;
00033 integer r1, r2;
00034 real eps, tmp;
00035 integer neg1, neg2, indp, inds;
00036 real dplus;
00037 extern doublereal slamch_(char *);
00038 integer indlpl, indumn;
00039 extern logical sisnan_(real *);
00040 real dminus;
00041 logical sawnan1, sawnan2;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
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
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 --work;
00179 --isuppz;
00180 --z__;
00181 --lld;
00182 --ld;
00183 --l;
00184 --d__;
00185
00186
00187 eps = slamch_("Precision");
00188 if (*r__ == 0) {
00189 r1 = *b1;
00190 r2 = *bn;
00191 } else {
00192 r1 = *r__;
00193 r2 = *r__;
00194 }
00195
00196 indlpl = 0;
00197
00198 indumn = *n;
00199 inds = (*n << 1) + 1;
00200 indp = *n * 3 + 1;
00201 if (*b1 == 1) {
00202 work[inds] = 0.f;
00203 } else {
00204 work[inds + *b1 - 1] = lld[*b1 - 1];
00205 }
00206
00207
00208
00209
00210 sawnan1 = FALSE_;
00211 neg1 = 0;
00212 s = work[inds + *b1 - 1] - *lambda;
00213 i__1 = r1 - 1;
00214 for (i__ = *b1; i__ <= i__1; ++i__) {
00215 dplus = d__[i__] + s;
00216 work[indlpl + i__] = ld[i__] / dplus;
00217 if (dplus < 0.f) {
00218 ++neg1;
00219 }
00220 work[inds + i__] = s * work[indlpl + i__] * l[i__];
00221 s = work[inds + i__] - *lambda;
00222
00223 }
00224 sawnan1 = sisnan_(&s);
00225 if (sawnan1) {
00226 goto L60;
00227 }
00228 i__1 = r2 - 1;
00229 for (i__ = r1; i__ <= i__1; ++i__) {
00230 dplus = d__[i__] + s;
00231 work[indlpl + i__] = ld[i__] / dplus;
00232 work[inds + i__] = s * work[indlpl + i__] * l[i__];
00233 s = work[inds + i__] - *lambda;
00234
00235 }
00236 sawnan1 = sisnan_(&s);
00237
00238 L60:
00239 if (sawnan1) {
00240
00241 neg1 = 0;
00242 s = work[inds + *b1 - 1] - *lambda;
00243 i__1 = r1 - 1;
00244 for (i__ = *b1; i__ <= i__1; ++i__) {
00245 dplus = d__[i__] + s;
00246 if (dabs(dplus) < *pivmin) {
00247 dplus = -(*pivmin);
00248 }
00249 work[indlpl + i__] = ld[i__] / dplus;
00250 if (dplus < 0.f) {
00251 ++neg1;
00252 }
00253 work[inds + i__] = s * work[indlpl + i__] * l[i__];
00254 if (work[indlpl + i__] == 0.f) {
00255 work[inds + i__] = lld[i__];
00256 }
00257 s = work[inds + i__] - *lambda;
00258
00259 }
00260 i__1 = r2 - 1;
00261 for (i__ = r1; i__ <= i__1; ++i__) {
00262 dplus = d__[i__] + s;
00263 if (dabs(dplus) < *pivmin) {
00264 dplus = -(*pivmin);
00265 }
00266 work[indlpl + i__] = ld[i__] / dplus;
00267 work[inds + i__] = s * work[indlpl + i__] * l[i__];
00268 if (work[indlpl + i__] == 0.f) {
00269 work[inds + i__] = lld[i__];
00270 }
00271 s = work[inds + i__] - *lambda;
00272
00273 }
00274 }
00275
00276
00277
00278
00279 sawnan2 = FALSE_;
00280 neg2 = 0;
00281 work[indp + *bn - 1] = d__[*bn] - *lambda;
00282 i__1 = r1;
00283 for (i__ = *bn - 1; i__ >= i__1; --i__) {
00284 dminus = lld[i__] + work[indp + i__];
00285 tmp = d__[i__] / dminus;
00286 if (dminus < 0.f) {
00287 ++neg2;
00288 }
00289 work[indumn + i__] = l[i__] * tmp;
00290 work[indp + i__ - 1] = work[indp + i__] * tmp - *lambda;
00291
00292 }
00293 tmp = work[indp + r1 - 1];
00294 sawnan2 = sisnan_(&tmp);
00295 if (sawnan2) {
00296
00297 neg2 = 0;
00298 i__1 = r1;
00299 for (i__ = *bn - 1; i__ >= i__1; --i__) {
00300 dminus = lld[i__] + work[indp + i__];
00301 if (dabs(dminus) < *pivmin) {
00302 dminus = -(*pivmin);
00303 }
00304 tmp = d__[i__] / dminus;
00305 if (dminus < 0.f) {
00306 ++neg2;
00307 }
00308 work[indumn + i__] = l[i__] * tmp;
00309 work[indp + i__ - 1] = work[indp + i__] * tmp - *lambda;
00310 if (tmp == 0.f) {
00311 work[indp + i__ - 1] = d__[i__] - *lambda;
00312 }
00313
00314 }
00315 }
00316
00317
00318
00319
00320 *mingma = work[inds + r1 - 1] + work[indp + r1 - 1];
00321 if (*mingma < 0.f) {
00322 ++neg1;
00323 }
00324 if (*wantnc) {
00325 *negcnt = neg1 + neg2;
00326 } else {
00327 *negcnt = -1;
00328 }
00329 if (dabs(*mingma) == 0.f) {
00330 *mingma = eps * work[inds + r1 - 1];
00331 }
00332 *r__ = r1;
00333 i__1 = r2 - 1;
00334 for (i__ = r1; i__ <= i__1; ++i__) {
00335 tmp = work[inds + i__] + work[indp + i__];
00336 if (tmp == 0.f) {
00337 tmp = eps * work[inds + i__];
00338 }
00339 if (dabs(tmp) <= dabs(*mingma)) {
00340 *mingma = tmp;
00341 *r__ = i__ + 1;
00342 }
00343
00344 }
00345
00346
00347
00348 isuppz[1] = *b1;
00349 isuppz[2] = *bn;
00350 i__1 = *r__;
00351 z__[i__1].r = 1.f, z__[i__1].i = 0.f;
00352 *ztz = 1.f;
00353
00354
00355
00356 if (! sawnan1 && ! sawnan2) {
00357 i__1 = *b1;
00358 for (i__ = *r__ - 1; i__ >= i__1; --i__) {
00359 i__2 = i__;
00360 i__3 = indlpl + i__;
00361 i__4 = i__ + 1;
00362 q__2.r = work[i__3] * z__[i__4].r, q__2.i = work[i__3] * z__[i__4]
00363 .i;
00364 q__1.r = -q__2.r, q__1.i = -q__2.i;
00365 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00366 if ((c_abs(&z__[i__]) + c_abs(&z__[i__ + 1])) * (r__1 = ld[i__],
00367 dabs(r__1)) < *gaptol) {
00368 i__2 = i__;
00369 z__[i__2].r = 0.f, z__[i__2].i = 0.f;
00370 isuppz[1] = i__ + 1;
00371 goto L220;
00372 }
00373 i__2 = i__;
00374 i__3 = i__;
00375 q__1.r = z__[i__2].r * z__[i__3].r - z__[i__2].i * z__[i__3].i,
00376 q__1.i = z__[i__2].r * z__[i__3].i + z__[i__2].i * z__[
00377 i__3].r;
00378 *ztz += q__1.r;
00379
00380 }
00381 L220:
00382 ;
00383 } else {
00384
00385 i__1 = *b1;
00386 for (i__ = *r__ - 1; i__ >= i__1; --i__) {
00387 i__2 = i__ + 1;
00388 if (z__[i__2].r == 0.f && z__[i__2].i == 0.f) {
00389 i__2 = i__;
00390 r__1 = -(ld[i__ + 1] / ld[i__]);
00391 i__3 = i__ + 2;
00392 q__1.r = r__1 * z__[i__3].r, q__1.i = r__1 * z__[i__3].i;
00393 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00394 } else {
00395 i__2 = i__;
00396 i__3 = indlpl + i__;
00397 i__4 = i__ + 1;
00398 q__2.r = work[i__3] * z__[i__4].r, q__2.i = work[i__3] * z__[
00399 i__4].i;
00400 q__1.r = -q__2.r, q__1.i = -q__2.i;
00401 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00402 }
00403 if ((c_abs(&z__[i__]) + c_abs(&z__[i__ + 1])) * (r__1 = ld[i__],
00404 dabs(r__1)) < *gaptol) {
00405 i__2 = i__;
00406 z__[i__2].r = 0.f, z__[i__2].i = 0.f;
00407 isuppz[1] = i__ + 1;
00408 goto L240;
00409 }
00410 i__2 = i__;
00411 i__3 = i__;
00412 q__1.r = z__[i__2].r * z__[i__3].r - z__[i__2].i * z__[i__3].i,
00413 q__1.i = z__[i__2].r * z__[i__3].i + z__[i__2].i * z__[
00414 i__3].r;
00415 *ztz += q__1.r;
00416
00417 }
00418 L240:
00419 ;
00420 }
00421
00422 if (! sawnan1 && ! sawnan2) {
00423 i__1 = *bn - 1;
00424 for (i__ = *r__; i__ <= i__1; ++i__) {
00425 i__2 = i__ + 1;
00426 i__3 = indumn + i__;
00427 i__4 = i__;
00428 q__2.r = work[i__3] * z__[i__4].r, q__2.i = work[i__3] * z__[i__4]
00429 .i;
00430 q__1.r = -q__2.r, q__1.i = -q__2.i;
00431 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00432 if ((c_abs(&z__[i__]) + c_abs(&z__[i__ + 1])) * (r__1 = ld[i__],
00433 dabs(r__1)) < *gaptol) {
00434 i__2 = i__ + 1;
00435 z__[i__2].r = 0.f, z__[i__2].i = 0.f;
00436 isuppz[2] = i__;
00437 goto L260;
00438 }
00439 i__2 = i__ + 1;
00440 i__3 = i__ + 1;
00441 q__1.r = z__[i__2].r * z__[i__3].r - z__[i__2].i * z__[i__3].i,
00442 q__1.i = z__[i__2].r * z__[i__3].i + z__[i__2].i * z__[
00443 i__3].r;
00444 *ztz += q__1.r;
00445
00446 }
00447 L260:
00448 ;
00449 } else {
00450
00451 i__1 = *bn - 1;
00452 for (i__ = *r__; i__ <= i__1; ++i__) {
00453 i__2 = i__;
00454 if (z__[i__2].r == 0.f && z__[i__2].i == 0.f) {
00455 i__2 = i__ + 1;
00456 r__1 = -(ld[i__ - 1] / ld[i__]);
00457 i__3 = i__ - 1;
00458 q__1.r = r__1 * z__[i__3].r, q__1.i = r__1 * z__[i__3].i;
00459 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00460 } else {
00461 i__2 = i__ + 1;
00462 i__3 = indumn + i__;
00463 i__4 = i__;
00464 q__2.r = work[i__3] * z__[i__4].r, q__2.i = work[i__3] * z__[
00465 i__4].i;
00466 q__1.r = -q__2.r, q__1.i = -q__2.i;
00467 z__[i__2].r = q__1.r, z__[i__2].i = q__1.i;
00468 }
00469 if ((c_abs(&z__[i__]) + c_abs(&z__[i__ + 1])) * (r__1 = ld[i__],
00470 dabs(r__1)) < *gaptol) {
00471 i__2 = i__ + 1;
00472 z__[i__2].r = 0.f, z__[i__2].i = 0.f;
00473 isuppz[2] = i__;
00474 goto L280;
00475 }
00476 i__2 = i__ + 1;
00477 i__3 = i__ + 1;
00478 q__1.r = z__[i__2].r * z__[i__3].r - z__[i__2].i * z__[i__3].i,
00479 q__1.i = z__[i__2].r * z__[i__3].i + z__[i__2].i * z__[
00480 i__3].r;
00481 *ztz += q__1.r;
00482
00483 }
00484 L280:
00485 ;
00486 }
00487
00488
00489
00490 tmp = 1.f / *ztz;
00491 *nrminv = sqrt(tmp);
00492 *resid = dabs(*mingma) * *nrminv;
00493 *rqcorr = *mingma * tmp;
00494
00495
00496 return 0;
00497
00498
00499
00500 }