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 logical c_true = TRUE_;
00020 static logical c_false = FALSE_;
00021
00022 int strsna_(char *job, char *howmny, logical *select,
00023 integer *n, real *t, integer *ldt, real *vl, integer *ldvl, real *vr,
00024 integer *ldvr, real *s, real *sep, integer *mm, integer *m, real *
00025 work, integer *ldwork, integer *iwork, integer *info)
00026 {
00027
00028 integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset,
00029 work_dim1, work_offset, i__1, i__2;
00030 real r__1, r__2;
00031
00032
00033 double sqrt(doublereal);
00034
00035
00036 integer i__, j, k, n2;
00037 real cs;
00038 integer nn, ks;
00039 real sn, mu, eps, est;
00040 integer kase;
00041 real cond;
00042 logical pair;
00043 integer ierr;
00044 real dumm, prod;
00045 integer ifst;
00046 real lnrm;
00047 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00048 integer ilst;
00049 real rnrm, prod1, prod2;
00050 extern doublereal snrm2_(integer *, real *, integer *);
00051 real scale, delta;
00052 extern logical lsame_(char *, char *);
00053 integer isave[3];
00054 logical wants;
00055 real dummy[1];
00056 extern int slacn2_(integer *, real *, real *, integer *,
00057 real *, integer *, integer *);
00058 extern doublereal slapy2_(real *, real *);
00059 extern int slabad_(real *, real *);
00060 extern doublereal slamch_(char *);
00061 extern int xerbla_(char *, integer *);
00062 real bignum;
00063 logical wantbh;
00064 extern int slacpy_(char *, integer *, integer *, real *,
00065 integer *, real *, integer *);
00066 logical somcon;
00067 extern int slaqtr_(logical *, logical *, integer *, real
00068 *, integer *, real *, real *, real *, real *, real *, integer *),
00069 strexc_(char *, integer *, real *, integer *, real *, integer *,
00070 integer *, integer *, real *, integer *);
00071 real smlnum;
00072 logical wantsp;
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
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 --select;
00260 t_dim1 = *ldt;
00261 t_offset = 1 + t_dim1;
00262 t -= t_offset;
00263 vl_dim1 = *ldvl;
00264 vl_offset = 1 + vl_dim1;
00265 vl -= vl_offset;
00266 vr_dim1 = *ldvr;
00267 vr_offset = 1 + vr_dim1;
00268 vr -= vr_offset;
00269 --s;
00270 --sep;
00271 work_dim1 = *ldwork;
00272 work_offset = 1 + work_dim1;
00273 work -= work_offset;
00274 --iwork;
00275
00276
00277 wantbh = lsame_(job, "B");
00278 wants = lsame_(job, "E") || wantbh;
00279 wantsp = lsame_(job, "V") || wantbh;
00280
00281 somcon = lsame_(howmny, "S");
00282
00283 *info = 0;
00284 if (! wants && ! wantsp) {
00285 *info = -1;
00286 } else if (! lsame_(howmny, "A") && ! somcon) {
00287 *info = -2;
00288 } else if (*n < 0) {
00289 *info = -4;
00290 } else if (*ldt < max(1,*n)) {
00291 *info = -6;
00292 } else if (*ldvl < 1 || wants && *ldvl < *n) {
00293 *info = -8;
00294 } else if (*ldvr < 1 || wants && *ldvr < *n) {
00295 *info = -10;
00296 } else {
00297
00298
00299
00300
00301 if (somcon) {
00302 *m = 0;
00303 pair = FALSE_;
00304 i__1 = *n;
00305 for (k = 1; k <= i__1; ++k) {
00306 if (pair) {
00307 pair = FALSE_;
00308 } else {
00309 if (k < *n) {
00310 if (t[k + 1 + k * t_dim1] == 0.f) {
00311 if (select[k]) {
00312 ++(*m);
00313 }
00314 } else {
00315 pair = TRUE_;
00316 if (select[k] || select[k + 1]) {
00317 *m += 2;
00318 }
00319 }
00320 } else {
00321 if (select[*n]) {
00322 ++(*m);
00323 }
00324 }
00325 }
00326
00327 }
00328 } else {
00329 *m = *n;
00330 }
00331
00332 if (*mm < *m) {
00333 *info = -13;
00334 } else if (*ldwork < 1 || wantsp && *ldwork < *n) {
00335 *info = -16;
00336 }
00337 }
00338 if (*info != 0) {
00339 i__1 = -(*info);
00340 xerbla_("STRSNA", &i__1);
00341 return 0;
00342 }
00343
00344
00345
00346 if (*n == 0) {
00347 return 0;
00348 }
00349
00350 if (*n == 1) {
00351 if (somcon) {
00352 if (! select[1]) {
00353 return 0;
00354 }
00355 }
00356 if (wants) {
00357 s[1] = 1.f;
00358 }
00359 if (wantsp) {
00360 sep[1] = (r__1 = t[t_dim1 + 1], dabs(r__1));
00361 }
00362 return 0;
00363 }
00364
00365
00366
00367 eps = slamch_("P");
00368 smlnum = slamch_("S") / eps;
00369 bignum = 1.f / smlnum;
00370 slabad_(&smlnum, &bignum);
00371
00372 ks = 0;
00373 pair = FALSE_;
00374 i__1 = *n;
00375 for (k = 1; k <= i__1; ++k) {
00376
00377
00378
00379 if (pair) {
00380 pair = FALSE_;
00381 goto L60;
00382 } else {
00383 if (k < *n) {
00384 pair = t[k + 1 + k * t_dim1] != 0.f;
00385 }
00386 }
00387
00388
00389
00390
00391 if (somcon) {
00392 if (pair) {
00393 if (! select[k] && ! select[k + 1]) {
00394 goto L60;
00395 }
00396 } else {
00397 if (! select[k]) {
00398 goto L60;
00399 }
00400 }
00401 }
00402
00403 ++ks;
00404
00405 if (wants) {
00406
00407
00408
00409
00410 if (! pair) {
00411
00412
00413
00414 prod = sdot_(n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks *
00415 vl_dim1 + 1], &c__1);
00416 rnrm = snrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00417 lnrm = snrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00418 s[ks] = dabs(prod) / (rnrm * lnrm);
00419 } else {
00420
00421
00422
00423 prod1 = sdot_(n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks *
00424 vl_dim1 + 1], &c__1);
00425 prod1 += sdot_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1, &vl[(ks
00426 + 1) * vl_dim1 + 1], &c__1);
00427 prod2 = sdot_(n, &vl[ks * vl_dim1 + 1], &c__1, &vr[(ks + 1) *
00428 vr_dim1 + 1], &c__1);
00429 prod2 -= sdot_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1, &vr[ks *
00430 vr_dim1 + 1], &c__1);
00431 r__1 = snrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00432 r__2 = snrm2_(n, &vr[(ks + 1) * vr_dim1 + 1], &c__1);
00433 rnrm = slapy2_(&r__1, &r__2);
00434 r__1 = snrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00435 r__2 = snrm2_(n, &vl[(ks + 1) * vl_dim1 + 1], &c__1);
00436 lnrm = slapy2_(&r__1, &r__2);
00437 cond = slapy2_(&prod1, &prod2) / (rnrm * lnrm);
00438 s[ks] = cond;
00439 s[ks + 1] = cond;
00440 }
00441 }
00442
00443 if (wantsp) {
00444
00445
00446
00447
00448
00449
00450
00451 slacpy_("Full", n, n, &t[t_offset], ldt, &work[work_offset],
00452 ldwork);
00453 ifst = k;
00454 ilst = 1;
00455 strexc_("No Q", n, &work[work_offset], ldwork, dummy, &c__1, &
00456 ifst, &ilst, &work[(*n + 1) * work_dim1 + 1], &ierr);
00457
00458 if (ierr == 1 || ierr == 2) {
00459
00460
00461
00462 scale = 1.f;
00463 est = bignum;
00464 } else {
00465
00466
00467
00468 if (work[work_dim1 + 2] == 0.f) {
00469
00470
00471
00472 i__2 = *n;
00473 for (i__ = 2; i__ <= i__2; ++i__) {
00474 work[i__ + i__ * work_dim1] -= work[work_dim1 + 1];
00475
00476 }
00477 n2 = 1;
00478 nn = *n - 1;
00479 } else {
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 mu = sqrt((r__1 = work[(work_dim1 << 1) + 1], dabs(r__1)))
00490 * sqrt((r__2 = work[work_dim1 + 2], dabs(r__2)));
00491 delta = slapy2_(&mu, &work[work_dim1 + 2]);
00492 cs = mu / delta;
00493 sn = -work[work_dim1 + 2] / delta;
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 i__2 = *n;
00507 for (j = 3; j <= i__2; ++j) {
00508 work[j * work_dim1 + 2] = cs * work[j * work_dim1 + 2]
00509 ;
00510 work[j + j * work_dim1] -= work[work_dim1 + 1];
00511
00512 }
00513 work[(work_dim1 << 1) + 2] = 0.f;
00514
00515 work[(*n + 1) * work_dim1 + 1] = mu * 2.f;
00516 i__2 = *n - 1;
00517 for (i__ = 2; i__ <= i__2; ++i__) {
00518 work[i__ + (*n + 1) * work_dim1] = sn * work[(i__ + 1)
00519 * work_dim1 + 1];
00520
00521 }
00522 n2 = 2;
00523 nn = *n - 1 << 1;
00524 }
00525
00526
00527
00528 est = 0.f;
00529 kase = 0;
00530 L50:
00531 slacn2_(&nn, &work[(*n + 2) * work_dim1 + 1], &work[(*n + 4) *
00532 work_dim1 + 1], &iwork[1], &est, &kase, isave);
00533 if (kase != 0) {
00534 if (kase == 1) {
00535 if (n2 == 1) {
00536
00537
00538
00539 i__2 = *n - 1;
00540 slaqtr_(&c_true, &c_true, &i__2, &work[(work_dim1
00541 << 1) + 2], ldwork, dummy, &dumm, &scale,
00542 &work[(*n + 4) * work_dim1 + 1], &work[(*
00543 n + 6) * work_dim1 + 1], &ierr);
00544 } else {
00545
00546
00547
00548
00549 i__2 = *n - 1;
00550 slaqtr_(&c_true, &c_false, &i__2, &work[(
00551 work_dim1 << 1) + 2], ldwork, &work[(*n +
00552 1) * work_dim1 + 1], &mu, &scale, &work[(*
00553 n + 4) * work_dim1 + 1], &work[(*n + 6) *
00554 work_dim1 + 1], &ierr);
00555 }
00556 } else {
00557 if (n2 == 1) {
00558
00559
00560
00561 i__2 = *n - 1;
00562 slaqtr_(&c_false, &c_true, &i__2, &work[(
00563 work_dim1 << 1) + 2], ldwork, dummy, &
00564 dumm, &scale, &work[(*n + 4) * work_dim1
00565 + 1], &work[(*n + 6) * work_dim1 + 1], &
00566 ierr);
00567 } else {
00568
00569
00570
00571
00572 i__2 = *n - 1;
00573 slaqtr_(&c_false, &c_false, &i__2, &work[(
00574 work_dim1 << 1) + 2], ldwork, &work[(*n +
00575 1) * work_dim1 + 1], &mu, &scale, &work[(*
00576 n + 4) * work_dim1 + 1], &work[(*n + 6) *
00577 work_dim1 + 1], &ierr);
00578
00579 }
00580 }
00581
00582 goto L50;
00583 }
00584 }
00585
00586 sep[ks] = scale / dmax(est,smlnum);
00587 if (pair) {
00588 sep[ks + 1] = sep[ks];
00589 }
00590 }
00591
00592 if (pair) {
00593 ++ks;
00594 }
00595
00596 L60:
00597 ;
00598 }
00599 return 0;
00600
00601
00602
00603 }