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