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 real c_b18 = -1.f;
00020 static real c_b19 = 1.f;
00021
00022 int sgtrfs_(char *trans, integer *n, integer *nrhs, real *dl,
00023 real *d__, real *du, real *dlf, real *df, real *duf, real *du2,
00024 integer *ipiv, real *b, integer *ldb, real *x, integer *ldx, real *
00025 ferr, real *berr, real *work, integer *iwork, integer *info)
00026 {
00027
00028 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
00029 real r__1, r__2, r__3, r__4;
00030
00031
00032 integer i__, j;
00033 real s;
00034 integer nz;
00035 real eps;
00036 integer kase;
00037 real safe1, safe2;
00038 extern logical lsame_(char *, char *);
00039 integer isave[3], count;
00040 extern int scopy_(integer *, real *, integer *, real *,
00041 integer *), saxpy_(integer *, real *, real *, integer *, real *,
00042 integer *), slacn2_(integer *, real *, real *, integer *, real *,
00043 integer *, integer *);
00044 extern doublereal slamch_(char *);
00045 real safmin;
00046 extern int xerbla_(char *, integer *), slagtm_(
00047 char *, integer *, integer *, real *, real *, real *, real *,
00048 real *, integer *, real *, real *, integer *);
00049 logical notran;
00050 char transn[1], transt[1];
00051 real lstres;
00052 extern int sgttrs_(char *, integer *, integer *, real *,
00053 real *, real *, real *, integer *, real *, integer *, integer *);
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
00179 --dl;
00180 --d__;
00181 --du;
00182 --dlf;
00183 --df;
00184 --duf;
00185 --du2;
00186 --ipiv;
00187 b_dim1 = *ldb;
00188 b_offset = 1 + b_dim1;
00189 b -= b_offset;
00190 x_dim1 = *ldx;
00191 x_offset = 1 + x_dim1;
00192 x -= x_offset;
00193 --ferr;
00194 --berr;
00195 --work;
00196 --iwork;
00197
00198
00199 *info = 0;
00200 notran = lsame_(trans, "N");
00201 if (! notran && ! lsame_(trans, "T") && ! lsame_(
00202 trans, "C")) {
00203 *info = -1;
00204 } else if (*n < 0) {
00205 *info = -2;
00206 } else if (*nrhs < 0) {
00207 *info = -3;
00208 } else if (*ldb < max(1,*n)) {
00209 *info = -13;
00210 } else if (*ldx < max(1,*n)) {
00211 *info = -15;
00212 }
00213 if (*info != 0) {
00214 i__1 = -(*info);
00215 xerbla_("SGTRFS", &i__1);
00216 return 0;
00217 }
00218
00219
00220
00221 if (*n == 0 || *nrhs == 0) {
00222 i__1 = *nrhs;
00223 for (j = 1; j <= i__1; ++j) {
00224 ferr[j] = 0.f;
00225 berr[j] = 0.f;
00226
00227 }
00228 return 0;
00229 }
00230
00231 if (notran) {
00232 *(unsigned char *)transn = 'N';
00233 *(unsigned char *)transt = 'T';
00234 } else {
00235 *(unsigned char *)transn = 'T';
00236 *(unsigned char *)transt = 'N';
00237 }
00238
00239
00240
00241 nz = 4;
00242 eps = slamch_("Epsilon");
00243 safmin = slamch_("Safe minimum");
00244 safe1 = nz * safmin;
00245 safe2 = safe1 / eps;
00246
00247
00248
00249 i__1 = *nrhs;
00250 for (j = 1; j <= i__1; ++j) {
00251
00252 count = 1;
00253 lstres = 3.f;
00254 L20:
00255
00256
00257
00258
00259
00260
00261 scopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00262 slagtm_(trans, n, &c__1, &c_b18, &dl[1], &d__[1], &du[1], &x[j *
00263 x_dim1 + 1], ldx, &c_b19, &work[*n + 1], n);
00264
00265
00266
00267
00268 if (notran) {
00269 if (*n == 1) {
00270 work[1] = (r__1 = b[j * b_dim1 + 1], dabs(r__1)) + (r__2 =
00271 d__[1] * x[j * x_dim1 + 1], dabs(r__2));
00272 } else {
00273 work[1] = (r__1 = b[j * b_dim1 + 1], dabs(r__1)) + (r__2 =
00274 d__[1] * x[j * x_dim1 + 1], dabs(r__2)) + (r__3 = du[
00275 1] * x[j * x_dim1 + 2], dabs(r__3));
00276 i__2 = *n - 1;
00277 for (i__ = 2; i__ <= i__2; ++i__) {
00278 work[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1)) + (
00279 r__2 = dl[i__ - 1] * x[i__ - 1 + j * x_dim1],
00280 dabs(r__2)) + (r__3 = d__[i__] * x[i__ + j *
00281 x_dim1], dabs(r__3)) + (r__4 = du[i__] * x[i__ +
00282 1 + j * x_dim1], dabs(r__4));
00283
00284 }
00285 work[*n] = (r__1 = b[*n + j * b_dim1], dabs(r__1)) + (r__2 =
00286 dl[*n - 1] * x[*n - 1 + j * x_dim1], dabs(r__2)) + (
00287 r__3 = d__[*n] * x[*n + j * x_dim1], dabs(r__3));
00288 }
00289 } else {
00290 if (*n == 1) {
00291 work[1] = (r__1 = b[j * b_dim1 + 1], dabs(r__1)) + (r__2 =
00292 d__[1] * x[j * x_dim1 + 1], dabs(r__2));
00293 } else {
00294 work[1] = (r__1 = b[j * b_dim1 + 1], dabs(r__1)) + (r__2 =
00295 d__[1] * x[j * x_dim1 + 1], dabs(r__2)) + (r__3 = dl[
00296 1] * x[j * x_dim1 + 2], dabs(r__3));
00297 i__2 = *n - 1;
00298 for (i__ = 2; i__ <= i__2; ++i__) {
00299 work[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1)) + (
00300 r__2 = du[i__ - 1] * x[i__ - 1 + j * x_dim1],
00301 dabs(r__2)) + (r__3 = d__[i__] * x[i__ + j *
00302 x_dim1], dabs(r__3)) + (r__4 = dl[i__] * x[i__ +
00303 1 + j * x_dim1], dabs(r__4));
00304
00305 }
00306 work[*n] = (r__1 = b[*n + j * b_dim1], dabs(r__1)) + (r__2 =
00307 du[*n - 1] * x[*n - 1 + j * x_dim1], dabs(r__2)) + (
00308 r__3 = d__[*n] * x[*n + j * x_dim1], dabs(r__3));
00309 }
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 s = 0.f;
00322 i__2 = *n;
00323 for (i__ = 1; i__ <= i__2; ++i__) {
00324 if (work[i__] > safe2) {
00325
00326 r__2 = s, r__3 = (r__1 = work[*n + i__], dabs(r__1)) / work[
00327 i__];
00328 s = dmax(r__2,r__3);
00329 } else {
00330
00331 r__2 = s, r__3 = ((r__1 = work[*n + i__], dabs(r__1)) + safe1)
00332 / (work[i__] + safe1);
00333 s = dmax(r__2,r__3);
00334 }
00335
00336 }
00337 berr[j] = s;
00338
00339
00340
00341
00342
00343
00344
00345 if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00346
00347
00348
00349 sgttrs_(trans, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[
00350 1], &work[*n + 1], n, info);
00351 saxpy_(n, &c_b19, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00352 ;
00353 lstres = berr[j];
00354 ++count;
00355 goto L20;
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 i__2 = *n;
00381 for (i__ = 1; i__ <= i__2; ++i__) {
00382 if (work[i__] > safe2) {
00383 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00384 work[i__];
00385 } else {
00386 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00387 work[i__] + safe1;
00388 }
00389
00390 }
00391
00392 kase = 0;
00393 L70:
00394 slacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00395 kase, isave);
00396 if (kase != 0) {
00397 if (kase == 1) {
00398
00399
00400
00401 sgttrs_(transt, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00402 ipiv[1], &work[*n + 1], n, info);
00403 i__2 = *n;
00404 for (i__ = 1; i__ <= i__2; ++i__) {
00405 work[*n + i__] = work[i__] * work[*n + i__];
00406
00407 }
00408 } else {
00409
00410
00411
00412 i__2 = *n;
00413 for (i__ = 1; i__ <= i__2; ++i__) {
00414 work[*n + i__] = work[i__] * work[*n + i__];
00415
00416 }
00417 sgttrs_(transn, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00418 ipiv[1], &work[*n + 1], n, info);
00419 }
00420 goto L70;
00421 }
00422
00423
00424
00425 lstres = 0.f;
00426 i__2 = *n;
00427 for (i__ = 1; i__ <= i__2; ++i__) {
00428
00429 r__2 = lstres, r__3 = (r__1 = x[i__ + j * x_dim1], dabs(r__1));
00430 lstres = dmax(r__2,r__3);
00431
00432 }
00433 if (lstres != 0.f) {
00434 ferr[j] /= lstres;
00435 }
00436
00437
00438 }
00439
00440 return 0;
00441
00442
00443
00444 }