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