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
00020 int ctbrfs_(char *uplo, char *trans, char *diag, integer *n,
00021 integer *kd, integer *nrhs, complex *ab, integer *ldab, complex *b,
00022 integer *ldb, complex *x, integer *ldx, real *ferr, real *berr,
00023 complex *work, real *rwork, integer *info)
00024 {
00025
00026 integer ab_dim1, ab_offset, b_dim1, b_offset, x_dim1, x_offset, i__1,
00027 i__2, i__3, i__4, i__5;
00028 real r__1, r__2, r__3, r__4;
00029 complex q__1;
00030
00031
00032 double r_imag(complex *);
00033
00034
00035 integer i__, j, k;
00036 real s, 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 ctbmv_(char *, char *, char *, integer *,
00044 integer *, complex *, integer *, complex *, integer *), ccopy_(integer *, complex *, integer *, complex *
00045 , integer *), ctbsv_(char *, char *, char *, integer *, integer *,
00046 complex *, integer *, complex *, integer *), caxpy_(integer *, complex *, complex *, integer *,
00047 complex *, integer *);
00048 logical upper;
00049 extern int clacn2_(integer *, complex *, complex *, real
00050 *, integer *, integer *);
00051 extern doublereal slamch_(char *);
00052 real safmin;
00053 extern int xerbla_(char *, integer *);
00054 logical notran;
00055 char transn[1], transt[1];
00056 logical nounit;
00057 real lstres;
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 ab_dim1 = *ldab;
00181 ab_offset = 1 + ab_dim1;
00182 ab -= ab_offset;
00183 b_dim1 = *ldb;
00184 b_offset = 1 + b_dim1;
00185 b -= b_offset;
00186 x_dim1 = *ldx;
00187 x_offset = 1 + x_dim1;
00188 x -= x_offset;
00189 --ferr;
00190 --berr;
00191 --work;
00192 --rwork;
00193
00194
00195 *info = 0;
00196 upper = lsame_(uplo, "U");
00197 notran = lsame_(trans, "N");
00198 nounit = lsame_(diag, "N");
00199
00200 if (! upper && ! lsame_(uplo, "L")) {
00201 *info = -1;
00202 } else if (! notran && ! lsame_(trans, "T") && !
00203 lsame_(trans, "C")) {
00204 *info = -2;
00205 } else if (! nounit && ! lsame_(diag, "U")) {
00206 *info = -3;
00207 } else if (*n < 0) {
00208 *info = -4;
00209 } else if (*kd < 0) {
00210 *info = -5;
00211 } else if (*nrhs < 0) {
00212 *info = -6;
00213 } else if (*ldab < *kd + 1) {
00214 *info = -8;
00215 } else if (*ldb < max(1,*n)) {
00216 *info = -10;
00217 } else if (*ldx < max(1,*n)) {
00218 *info = -12;
00219 }
00220 if (*info != 0) {
00221 i__1 = -(*info);
00222 xerbla_("CTBRFS", &i__1);
00223 return 0;
00224 }
00225
00226
00227
00228 if (*n == 0 || *nrhs == 0) {
00229 i__1 = *nrhs;
00230 for (j = 1; j <= i__1; ++j) {
00231 ferr[j] = 0.f;
00232 berr[j] = 0.f;
00233
00234 }
00235 return 0;
00236 }
00237
00238 if (notran) {
00239 *(unsigned char *)transn = 'N';
00240 *(unsigned char *)transt = 'C';
00241 } else {
00242 *(unsigned char *)transn = 'C';
00243 *(unsigned char *)transt = 'N';
00244 }
00245
00246
00247
00248 nz = *kd + 2;
00249 eps = slamch_("Epsilon");
00250 safmin = slamch_("Safe minimum");
00251 safe1 = nz * safmin;
00252 safe2 = safe1 / eps;
00253
00254
00255
00256 i__1 = *nrhs;
00257 for (j = 1; j <= i__1; ++j) {
00258
00259
00260
00261
00262 ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00263 ctbmv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[1], &
00264 c__1);
00265 q__1.r = -1.f, q__1.i = -0.f;
00266 caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 i__2 = *n;
00278 for (i__ = 1; i__ <= i__2; ++i__) {
00279 i__3 = i__ + j * b_dim1;
00280 rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00281 i__ + j * b_dim1]), dabs(r__2));
00282
00283 }
00284
00285 if (notran) {
00286
00287
00288
00289 if (upper) {
00290 if (nounit) {
00291 i__2 = *n;
00292 for (k = 1; k <= i__2; ++k) {
00293 i__3 = k + j * x_dim1;
00294 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00295 x[k + j * x_dim1]), dabs(r__2));
00296
00297 i__3 = 1, i__4 = k - *kd;
00298 i__5 = k;
00299 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00300 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
00301 rwork[i__] += ((r__1 = ab[i__3].r, dabs(r__1)) + (
00302 r__2 = r_imag(&ab[*kd + 1 + i__ - k + k *
00303 ab_dim1]), dabs(r__2))) * xk;
00304
00305 }
00306
00307 }
00308 } else {
00309 i__2 = *n;
00310 for (k = 1; k <= i__2; ++k) {
00311 i__5 = k + j * x_dim1;
00312 xk = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 = r_imag(&
00313 x[k + j * x_dim1]), dabs(r__2));
00314
00315 i__5 = 1, i__3 = k - *kd;
00316 i__4 = k - 1;
00317 for (i__ = max(i__5,i__3); i__ <= i__4; ++i__) {
00318 i__5 = *kd + 1 + i__ - k + k * ab_dim1;
00319 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
00320 r__2 = r_imag(&ab[*kd + 1 + i__ - k + k *
00321 ab_dim1]), dabs(r__2))) * xk;
00322
00323 }
00324 rwork[k] += xk;
00325
00326 }
00327 }
00328 } else {
00329 if (nounit) {
00330 i__2 = *n;
00331 for (k = 1; k <= i__2; ++k) {
00332 i__4 = k + j * x_dim1;
00333 xk = (r__1 = x[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00334 x[k + j * x_dim1]), dabs(r__2));
00335
00336 i__5 = *n, i__3 = k + *kd;
00337 i__4 = min(i__5,i__3);
00338 for (i__ = k; i__ <= i__4; ++i__) {
00339 i__5 = i__ + 1 - k + k * ab_dim1;
00340 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
00341 r__2 = r_imag(&ab[i__ + 1 - k + k *
00342 ab_dim1]), dabs(r__2))) * xk;
00343
00344 }
00345
00346 }
00347 } else {
00348 i__2 = *n;
00349 for (k = 1; k <= i__2; ++k) {
00350 i__4 = k + j * x_dim1;
00351 xk = (r__1 = x[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00352 x[k + j * x_dim1]), dabs(r__2));
00353
00354 i__5 = *n, i__3 = k + *kd;
00355 i__4 = min(i__5,i__3);
00356 for (i__ = k + 1; i__ <= i__4; ++i__) {
00357 i__5 = i__ + 1 - k + k * ab_dim1;
00358 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
00359 r__2 = r_imag(&ab[i__ + 1 - k + k *
00360 ab_dim1]), dabs(r__2))) * xk;
00361
00362 }
00363 rwork[k] += xk;
00364
00365 }
00366 }
00367 }
00368 } else {
00369
00370
00371
00372 if (upper) {
00373 if (nounit) {
00374 i__2 = *n;
00375 for (k = 1; k <= i__2; ++k) {
00376 s = 0.f;
00377
00378 i__4 = 1, i__5 = k - *kd;
00379 i__3 = k;
00380 for (i__ = max(i__4,i__5); i__ <= i__3; ++i__) {
00381 i__4 = *kd + 1 + i__ - k + k * ab_dim1;
00382 i__5 = i__ + j * x_dim1;
00383 s += ((r__1 = ab[i__4].r, dabs(r__1)) + (r__2 =
00384 r_imag(&ab[*kd + 1 + i__ - k + k *
00385 ab_dim1]), dabs(r__2))) * ((r__3 = x[i__5]
00386 .r, dabs(r__3)) + (r__4 = r_imag(&x[i__ +
00387 j * x_dim1]), dabs(r__4)));
00388
00389 }
00390 rwork[k] += s;
00391
00392 }
00393 } else {
00394 i__2 = *n;
00395 for (k = 1; k <= i__2; ++k) {
00396 i__3 = k + j * x_dim1;
00397 s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00398 x[k + j * x_dim1]), dabs(r__2));
00399
00400 i__3 = 1, i__4 = k - *kd;
00401 i__5 = k - 1;
00402 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00403 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
00404 i__4 = i__ + j * x_dim1;
00405 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
00406 r_imag(&ab[*kd + 1 + i__ - k + k *
00407 ab_dim1]), dabs(r__2))) * ((r__3 = x[i__4]
00408 .r, dabs(r__3)) + (r__4 = r_imag(&x[i__ +
00409 j * x_dim1]), dabs(r__4)));
00410
00411 }
00412 rwork[k] += s;
00413
00414 }
00415 }
00416 } else {
00417 if (nounit) {
00418 i__2 = *n;
00419 for (k = 1; k <= i__2; ++k) {
00420 s = 0.f;
00421
00422 i__3 = *n, i__4 = k + *kd;
00423 i__5 = min(i__3,i__4);
00424 for (i__ = k; i__ <= i__5; ++i__) {
00425 i__3 = i__ + 1 - k + k * ab_dim1;
00426 i__4 = i__ + j * x_dim1;
00427 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
00428 r_imag(&ab[i__ + 1 - k + k * ab_dim1]),
00429 dabs(r__2))) * ((r__3 = x[i__4].r, dabs(
00430 r__3)) + (r__4 = r_imag(&x[i__ + j *
00431 x_dim1]), dabs(r__4)));
00432
00433 }
00434 rwork[k] += s;
00435
00436 }
00437 } else {
00438 i__2 = *n;
00439 for (k = 1; k <= i__2; ++k) {
00440 i__5 = k + j * x_dim1;
00441 s = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 = r_imag(&
00442 x[k + j * x_dim1]), dabs(r__2));
00443
00444 i__3 = *n, i__4 = k + *kd;
00445 i__5 = min(i__3,i__4);
00446 for (i__ = k + 1; i__ <= i__5; ++i__) {
00447 i__3 = i__ + 1 - k + k * ab_dim1;
00448 i__4 = i__ + j * x_dim1;
00449 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
00450 r_imag(&ab[i__ + 1 - k + k * ab_dim1]),
00451 dabs(r__2))) * ((r__3 = x[i__4].r, dabs(
00452 r__3)) + (r__4 = r_imag(&x[i__ + j *
00453 x_dim1]), dabs(r__4)));
00454
00455 }
00456 rwork[k] += s;
00457
00458 }
00459 }
00460 }
00461 }
00462 s = 0.f;
00463 i__2 = *n;
00464 for (i__ = 1; i__ <= i__2; ++i__) {
00465 if (rwork[i__] > safe2) {
00466
00467 i__5 = i__;
00468 r__3 = s, r__4 = ((r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
00469 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00470 s = dmax(r__3,r__4);
00471 } else {
00472
00473 i__5 = i__;
00474 r__3 = s, r__4 = ((r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
00475 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00476 + safe1);
00477 s = dmax(r__3,r__4);
00478 }
00479
00480 }
00481 berr[j] = s;
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 i__2 = *n;
00506 for (i__ = 1; i__ <= i__2; ++i__) {
00507 if (rwork[i__] > safe2) {
00508 i__5 = i__;
00509 rwork[i__] = (r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
00510 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00511 i__];
00512 } else {
00513 i__5 = i__;
00514 rwork[i__] = (r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
00515 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00516 i__] + safe1;
00517 }
00518
00519 }
00520
00521 kase = 0;
00522 L210:
00523 clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00524 if (kase != 0) {
00525 if (kase == 1) {
00526
00527
00528
00529 ctbsv_(uplo, transt, diag, n, kd, &ab[ab_offset], ldab, &work[
00530 1], &c__1);
00531 i__2 = *n;
00532 for (i__ = 1; i__ <= i__2; ++i__) {
00533 i__5 = i__;
00534 i__3 = i__;
00535 i__4 = i__;
00536 q__1.r = rwork[i__3] * work[i__4].r, q__1.i = rwork[i__3]
00537 * work[i__4].i;
00538 work[i__5].r = q__1.r, work[i__5].i = q__1.i;
00539
00540 }
00541 } else {
00542
00543
00544
00545 i__2 = *n;
00546 for (i__ = 1; i__ <= i__2; ++i__) {
00547 i__5 = i__;
00548 i__3 = i__;
00549 i__4 = i__;
00550 q__1.r = rwork[i__3] * work[i__4].r, q__1.i = rwork[i__3]
00551 * work[i__4].i;
00552 work[i__5].r = q__1.r, work[i__5].i = q__1.i;
00553
00554 }
00555 ctbsv_(uplo, transn, diag, n, kd, &ab[ab_offset], ldab, &work[
00556 1], &c__1);
00557 }
00558 goto L210;
00559 }
00560
00561
00562
00563 lstres = 0.f;
00564 i__2 = *n;
00565 for (i__ = 1; i__ <= i__2; ++i__) {
00566
00567 i__5 = i__ + j * x_dim1;
00568 r__3 = lstres, r__4 = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 =
00569 r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00570 lstres = dmax(r__3,r__4);
00571
00572 }
00573 if (lstres != 0.f) {
00574 ferr[j] /= lstres;
00575 }
00576
00577
00578 }
00579
00580 return 0;
00581
00582
00583
00584 }