00001
00002
00003
00004
00005
00006 #include "f2c.h"
00007
00008
00009
00010 static integer c__1 = 1;
00011 static doublereal c_b36 = .5;
00012
00013 int dlatrs_(uplo, trans, diag, normin, n, a, lda, x, scale,
00014 cnorm, info, uplo_len, trans_len, diag_len, normin_len)
00015 char *uplo, *trans, *diag, *normin;
00016 integer *n;
00017 doublereal *a;
00018 integer *lda;
00019 doublereal *x, *scale, *cnorm;
00020 integer *info;
00021 ftnlen uplo_len;
00022 ftnlen trans_len;
00023 ftnlen diag_len;
00024 ftnlen normin_len;
00025 {
00026
00027 integer a_dim1, a_offset, i__1, i__2, i__3;
00028 doublereal d__1, d__2, d__3;
00029
00030
00031 static integer jinc;
00032 extern doublereal ddot_();
00033 static doublereal xbnd;
00034 static integer imax;
00035 static doublereal tmax, tjjs, xmax, grow, sumj;
00036 static integer i, j;
00037 extern int dscal_();
00038 extern logical lsame_();
00039 static doublereal tscal, uscal;
00040 extern doublereal dasum_();
00041 static integer jlast;
00042 extern int daxpy_();
00043 static logical upper;
00044 extern int dtrsv_();
00045 extern doublereal dlamch_();
00046 static doublereal xj;
00047 extern integer idamax_();
00048 extern int xerbla_();
00049 static doublereal bignum;
00050 static logical notran;
00051 static integer jfirst;
00052 static doublereal smlnum;
00053 static logical nounit;
00054 static doublereal rec, tjj;
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
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 a_dim1 = *lda;
00252 a_offset = a_dim1 + 1;
00253 a -= a_offset;
00254 --x;
00255 --cnorm;
00256
00257
00258 *info = 0;
00259 upper = lsame_(uplo, "U", 1L, 1L);
00260 notran = lsame_(trans, "N", 1L, 1L);
00261 nounit = lsame_(diag, "N", 1L, 1L);
00262
00263
00264
00265 if (! upper && ! lsame_(uplo, "L", 1L, 1L)) {
00266 *info = -1;
00267 } else if (! notran && ! lsame_(trans, "T", 1L, 1L) && ! lsame_(trans,
00268 "C", 1L, 1L)) {
00269 *info = -2;
00270 } else if (! nounit && ! lsame_(diag, "U", 1L, 1L)) {
00271 *info = -3;
00272 } else if (! lsame_(normin, "Y", 1L, 1L) && ! lsame_(normin, "N", 1L, 1L))
00273 {
00274 *info = -4;
00275 } else if (*n < 0) {
00276 *info = -5;
00277 } else if (*lda < max(1,*n)) {
00278 *info = -7;
00279 }
00280 if (*info != 0) {
00281 i__1 = -(*info);
00282 xerbla_("DLATRS", &i__1, 6L);
00283 return 0;
00284 }
00285
00286
00287
00288 if (*n == 0) {
00289 return 0;
00290 }
00291
00292
00293
00294 smlnum = dlamch_("Safe minimum", 12L) / dlamch_("Precision", 9L);
00295 bignum = 1. / smlnum;
00296 *scale = 1.;
00297
00298 if (lsame_(normin, "N", 1L, 1L)) {
00299
00300
00301
00302
00303 if (upper) {
00304
00305
00306
00307 i__1 = *n;
00308 for (j = 1; j <= i__1; ++j) {
00309 i__2 = j - 1;
00310 cnorm[j] = dasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
00311
00312 }
00313 } else {
00314
00315
00316
00317 i__1 = *n - 1;
00318 for (j = 1; j <= i__1; ++j) {
00319 i__2 = *n - j;
00320 cnorm[j] = dasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
00321
00322 }
00323 cnorm[*n] = 0.;
00324 }
00325 }
00326
00327
00328
00329
00330 imax = idamax_(n, &cnorm[1], &c__1);
00331 tmax = cnorm[imax];
00332 if (tmax <= bignum) {
00333 tscal = 1.;
00334 } else {
00335 tscal = 1. / (smlnum * tmax);
00336 dscal_(n, &tscal, &cnorm[1], &c__1);
00337 }
00338
00339
00340
00341
00342 j = idamax_(n, &x[1], &c__1);
00343 xmax = (d__1 = x[j], abs(d__1));
00344 xbnd = xmax;
00345 if (notran) {
00346
00347
00348
00349 if (upper) {
00350 jfirst = *n;
00351 jlast = 1;
00352 jinc = -1;
00353 } else {
00354 jfirst = 1;
00355 jlast = *n;
00356 jinc = 1;
00357 }
00358
00359 if (tscal != 1.) {
00360 grow = 0.;
00361 goto L50;
00362 }
00363
00364 if (nounit) {
00365
00366
00367
00368
00369
00370
00371 grow = 1. / max(xbnd,smlnum);
00372 xbnd = grow;
00373 i__1 = jlast;
00374 i__2 = jinc;
00375 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00376
00377
00378
00379
00380 if (grow <= smlnum) {
00381 goto L50;
00382 }
00383
00384
00385
00386 tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
00387
00388 d__1 = xbnd, d__2 = min(1.,tjj) * grow;
00389 xbnd = min(d__1,d__2);
00390 if (tjj + cnorm[j] >= smlnum) {
00391
00392
00393
00394
00395 grow *= tjj / (tjj + cnorm[j]);
00396 } else {
00397
00398
00399
00400 grow = 0.;
00401 }
00402
00403 }
00404 grow = xbnd;
00405 } else {
00406
00407
00408
00409
00410
00411
00412
00413 d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
00414 grow = min(d__1,d__2);
00415 i__2 = jlast;
00416 i__1 = jinc;
00417 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00418
00419
00420
00421
00422 if (grow <= smlnum) {
00423 goto L50;
00424 }
00425
00426
00427
00428 grow *= 1. / (cnorm[j] + 1.);
00429
00430 }
00431 }
00432 L50:
00433
00434 ;
00435 } else {
00436
00437
00438
00439 if (upper) {
00440 jfirst = 1;
00441 jlast = *n;
00442 jinc = 1;
00443 } else {
00444 jfirst = *n;
00445 jlast = 1;
00446 jinc = -1;
00447 }
00448
00449 if (tscal != 1.) {
00450 grow = 0.;
00451 goto L80;
00452 }
00453
00454 if (nounit) {
00455
00456
00457
00458
00459
00460
00461 grow = 1. / max(xbnd,smlnum);
00462 xbnd = grow;
00463 i__1 = jlast;
00464 i__2 = jinc;
00465 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00466
00467
00468
00469
00470 if (grow <= smlnum) {
00471 goto L80;
00472 }
00473
00474
00475
00476
00477 xj = cnorm[j] + 1.;
00478
00479 d__1 = grow, d__2 = xbnd / xj;
00480 grow = min(d__1,d__2);
00481
00482
00483
00484
00485 tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
00486 if (xj > tjj) {
00487 xbnd *= tjj / xj;
00488 }
00489
00490 }
00491 grow = min(grow,xbnd);
00492 } else {
00493
00494
00495
00496
00497
00498
00499
00500 d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
00501 grow = min(d__1,d__2);
00502 i__2 = jlast;
00503 i__1 = jinc;
00504 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00505
00506
00507
00508
00509 if (grow <= smlnum) {
00510 goto L80;
00511 }
00512
00513
00514
00515 xj = cnorm[j] + 1.;
00516 grow /= xj;
00517
00518 }
00519 }
00520 L80:
00521 ;
00522 }
00523
00524 if (grow * tscal > smlnum) {
00525
00526
00527
00528
00529
00530 dtrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1, 1L, 1L,
00531 1L);
00532 } else {
00533
00534
00535
00536 if (xmax > bignum) {
00537
00538
00539
00540
00541
00542 *scale = bignum / xmax;
00543 dscal_(n, scale, &x[1], &c__1);
00544 xmax = bignum;
00545 }
00546
00547 if (notran) {
00548
00549
00550
00551 i__1 = jlast;
00552 i__2 = jinc;
00553 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00554
00555
00556
00557
00558 xj = (d__1 = x[j], abs(d__1));
00559 if (nounit) {
00560 tjjs = a[j + j * a_dim1] * tscal;
00561 } else {
00562 tjjs = tscal;
00563 if (tscal == 1.) {
00564 goto L100;
00565 }
00566 }
00567 tjj = abs(tjjs);
00568 if (tjj > smlnum) {
00569
00570
00571
00572 if (tjj < 1.) {
00573 if (xj > tjj * bignum) {
00574
00575
00576
00577 rec = 1. / xj;
00578 dscal_(n, &rec, &x[1], &c__1);
00579 *scale *= rec;
00580 xmax *= rec;
00581 }
00582 }
00583 x[j] /= tjjs;
00584 xj = (d__1 = x[j], abs(d__1));
00585 } else if (tjj > 0.) {
00586
00587
00588
00589 if (xj > tjj * bignum) {
00590
00591
00592
00593
00594
00595
00596 rec = tjj * bignum / xj;
00597 if (cnorm[j] > 1.) {
00598
00599
00600
00601
00602
00603
00604 rec /= cnorm[j];
00605 }
00606 dscal_(n, &rec, &x[1], &c__1);
00607 *scale *= rec;
00608 xmax *= rec;
00609 }
00610 x[j] /= tjjs;
00611 xj = (d__1 = x[j], abs(d__1));
00612 } else {
00613
00614
00615
00616
00617
00618
00619 i__3 = *n;
00620 for (i = 1; i <= i__3; ++i) {
00621 x[i] = 0.;
00622
00623 }
00624 x[j] = 1.;
00625 xj = 1.;
00626 *scale = 0.;
00627 xmax = 0.;
00628 }
00629 L100:
00630
00631
00632
00633
00634
00635 if (xj > 1.) {
00636 rec = 1. / xj;
00637 if (cnorm[j] > (bignum - xmax) * rec) {
00638
00639
00640
00641 rec *= .5;
00642 dscal_(n, &rec, &x[1], &c__1);
00643 *scale *= rec;
00644 }
00645 } else if (xj * cnorm[j] > bignum - xmax) {
00646
00647
00648
00649 dscal_(n, &c_b36, &x[1], &c__1);
00650 *scale *= .5;
00651 }
00652
00653 if (upper) {
00654 if (j > 1) {
00655
00656
00657
00658
00659
00660 i__3 = j - 1;
00661 d__1 = -x[j] * tscal;
00662 daxpy_(&i__3, &d__1, &a[j * a_dim1 + 1], &c__1, &x[1],
00663 &c__1);
00664 i__3 = j - 1;
00665 i = idamax_(&i__3, &x[1], &c__1);
00666 xmax = (d__1 = x[i], abs(d__1));
00667 }
00668 } else {
00669 if (j < *n) {
00670
00671
00672
00673
00674
00675 i__3 = *n - j;
00676 d__1 = -x[j] * tscal;
00677 daxpy_(&i__3, &d__1, &a[j + 1 + j * a_dim1], &c__1, &
00678 x[j + 1], &c__1);
00679 i__3 = *n - j;
00680 i = j + idamax_(&i__3, &x[j + 1], &c__1);
00681 xmax = (d__1 = x[i], abs(d__1));
00682 }
00683 }
00684
00685 }
00686
00687 } else {
00688
00689
00690
00691 i__2 = jlast;
00692 i__1 = jinc;
00693 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00694
00695
00696
00697
00698 xj = (d__1 = x[j], abs(d__1));
00699 uscal = tscal;
00700 rec = 1. / max(xmax,1.);
00701 if (cnorm[j] > (bignum - xj) * rec) {
00702
00703
00704
00705
00706 rec *= .5;
00707 if (nounit) {
00708 tjjs = a[j + j * a_dim1] * tscal;
00709 } else {
00710 tjjs = tscal;
00711 }
00712 tjj = abs(tjjs);
00713 if (tjj > 1.) {
00714
00715
00716
00717
00718
00719 d__1 = 1., d__2 = rec * tjj;
00720 rec = min(d__1,d__2);
00721 uscal /= tjjs;
00722 }
00723 if (rec < 1.) {
00724 dscal_(n, &rec, &x[1], &c__1);
00725 *scale *= rec;
00726 xmax *= rec;
00727 }
00728 }
00729
00730 sumj = 0.;
00731 if (uscal == 1.) {
00732
00733
00734
00735
00736
00737
00738 if (upper) {
00739 i__3 = j - 1;
00740 sumj = ddot_(&i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
00741 &c__1);
00742 } else if (j < *n) {
00743 i__3 = *n - j;
00744 sumj = ddot_(&i__3, &a[j + 1 + j * a_dim1], &c__1, &x[
00745 j + 1], &c__1);
00746 }
00747 } else {
00748
00749
00750
00751
00752 if (upper) {
00753 i__3 = j - 1;
00754 for (i = 1; i <= i__3; ++i) {
00755 sumj += a[i + j * a_dim1] * uscal * x[i];
00756
00757 }
00758 } else if (j < *n) {
00759 i__3 = *n;
00760 for (i = j + 1; i <= i__3; ++i) {
00761 sumj += a[i + j * a_dim1] * uscal * x[i];
00762
00763 }
00764 }
00765 }
00766
00767 if (uscal == tscal) {
00768
00769
00770
00771
00772
00773
00774 x[j] -= sumj;
00775 xj = (d__1 = x[j], abs(d__1));
00776 if (nounit) {
00777 tjjs = a[j + j * a_dim1] * tscal;
00778 } else {
00779 tjjs = tscal;
00780 if (tscal == 1.) {
00781 goto L150;
00782 }
00783 }
00784
00785
00786
00787
00788 tjj = abs(tjjs);
00789 if (tjj > smlnum) {
00790
00791
00792
00793 if (tjj < 1.) {
00794 if (xj > tjj * bignum) {
00795
00796
00797
00798
00799 rec = 1. / xj;
00800 dscal_(n, &rec, &x[1], &c__1);
00801 *scale *= rec;
00802 xmax *= rec;
00803 }
00804 }
00805 x[j] /= tjjs;
00806 } else if (tjj > 0.) {
00807
00808
00809
00810 if (xj > tjj * bignum) {
00811
00812
00813
00814
00815 rec = tjj * bignum / xj;
00816 dscal_(n, &rec, &x[1], &c__1);
00817 *scale *= rec;
00818 xmax *= rec;
00819 }
00820 x[j] /= tjjs;
00821 } else {
00822
00823
00824
00825
00826
00827
00828 i__3 = *n;
00829 for (i = 1; i <= i__3; ++i) {
00830 x[i] = 0.;
00831
00832 }
00833 x[j] = 1.;
00834 *scale = 0.;
00835 xmax = 0.;
00836 }
00837 L150:
00838 ;
00839 } else {
00840
00841
00842
00843
00844
00845
00846 x[j] = x[j] / tjjs - sumj;
00847 }
00848
00849 d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
00850 xmax = max(d__2,d__3);
00851
00852 }
00853 }
00854 *scale /= tscal;
00855 }
00856
00857
00858
00859 if (tscal != 1.) {
00860 d__1 = 1. / tscal;
00861 dscal_(n, &d__1, &cnorm[1], &c__1);
00862 }
00863
00864 return 0;
00865
00866
00867
00868 }
00869