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