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