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_b18 = -1.;
00020 static doublereal c_b19 = 1.;
00021 static doublecomplex c_b26 = {1.,0.};
00022
00023 int zgtrfs_(char *trans, integer *n, integer *nrhs,
00024 doublecomplex *dl, doublecomplex *d__, doublecomplex *du,
00025 doublecomplex *dlf, doublecomplex *df, doublecomplex *duf,
00026 doublecomplex *du2, integer *ipiv, doublecomplex *b, integer *ldb,
00027 doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr,
00028 doublecomplex *work, doublereal *rwork, integer *info)
00029 {
00030
00031 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5,
00032 i__6, i__7, i__8, i__9;
00033 doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10,
00034 d__11, d__12, d__13, d__14;
00035 doublecomplex z__1;
00036
00037
00038 double d_imag(doublecomplex *);
00039
00040
00041 integer i__, j;
00042 doublereal s;
00043 integer nz;
00044 doublereal eps;
00045 integer kase;
00046 doublereal safe1, safe2;
00047 extern logical lsame_(char *, char *);
00048 integer isave[3], count;
00049 extern int zcopy_(integer *, doublecomplex *, integer *,
00050 doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *,
00051 doublecomplex *, integer *, doublecomplex *, integer *), zlacn2_(
00052 integer *, doublecomplex *, doublecomplex *, doublereal *,
00053 integer *, integer *);
00054 extern doublereal dlamch_(char *);
00055 doublereal safmin;
00056 extern int xerbla_(char *, integer *), zlagtm_(
00057 char *, integer *, integer *, doublereal *, doublecomplex *,
00058 doublecomplex *, doublecomplex *, doublecomplex *, integer *,
00059 doublereal *, doublecomplex *, integer *);
00060 logical notran;
00061 char transn[1], transt[1];
00062 doublereal lstres;
00063 extern int zgttrs_(char *, integer *, integer *,
00064 doublecomplex *, doublecomplex *, doublecomplex *, doublecomplex *
00065 , integer *, doublecomplex *, integer *, integer *);
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
00194
00195 --dl;
00196 --d__;
00197 --du;
00198 --dlf;
00199 --df;
00200 --duf;
00201 --du2;
00202 --ipiv;
00203 b_dim1 = *ldb;
00204 b_offset = 1 + b_dim1;
00205 b -= b_offset;
00206 x_dim1 = *ldx;
00207 x_offset = 1 + x_dim1;
00208 x -= x_offset;
00209 --ferr;
00210 --berr;
00211 --work;
00212 --rwork;
00213
00214
00215 *info = 0;
00216 notran = lsame_(trans, "N");
00217 if (! notran && ! lsame_(trans, "T") && ! lsame_(
00218 trans, "C")) {
00219 *info = -1;
00220 } else if (*n < 0) {
00221 *info = -2;
00222 } else if (*nrhs < 0) {
00223 *info = -3;
00224 } else if (*ldb < max(1,*n)) {
00225 *info = -13;
00226 } else if (*ldx < max(1,*n)) {
00227 *info = -15;
00228 }
00229 if (*info != 0) {
00230 i__1 = -(*info);
00231 xerbla_("ZGTRFS", &i__1);
00232 return 0;
00233 }
00234
00235
00236
00237 if (*n == 0 || *nrhs == 0) {
00238 i__1 = *nrhs;
00239 for (j = 1; j <= i__1; ++j) {
00240 ferr[j] = 0.;
00241 berr[j] = 0.;
00242
00243 }
00244 return 0;
00245 }
00246
00247 if (notran) {
00248 *(unsigned char *)transn = 'N';
00249 *(unsigned char *)transt = 'C';
00250 } else {
00251 *(unsigned char *)transn = 'C';
00252 *(unsigned char *)transt = 'N';
00253 }
00254
00255
00256
00257 nz = 4;
00258 eps = dlamch_("Epsilon");
00259 safmin = dlamch_("Safe minimum");
00260 safe1 = nz * safmin;
00261 safe2 = safe1 / eps;
00262
00263
00264
00265 i__1 = *nrhs;
00266 for (j = 1; j <= i__1; ++j) {
00267
00268 count = 1;
00269 lstres = 3.;
00270 L20:
00271
00272
00273
00274
00275
00276
00277 zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00278 zlagtm_(trans, n, &c__1, &c_b18, &dl[1], &d__[1], &du[1], &x[j *
00279 x_dim1 + 1], ldx, &c_b19, &work[1], n);
00280
00281
00282
00283
00284 if (notran) {
00285 if (*n == 1) {
00286 i__2 = j * b_dim1 + 1;
00287 i__3 = j * x_dim1 + 1;
00288 rwork[1] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00289 j * b_dim1 + 1]), abs(d__2)) + ((d__3 = d__[1].r, abs(
00290 d__3)) + (d__4 = d_imag(&d__[1]), abs(d__4))) * ((
00291 d__5 = x[i__3].r, abs(d__5)) + (d__6 = d_imag(&x[j *
00292 x_dim1 + 1]), abs(d__6)));
00293 } else {
00294 i__2 = j * b_dim1 + 1;
00295 i__3 = j * x_dim1 + 1;
00296 i__4 = j * x_dim1 + 2;
00297 rwork[1] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00298 j * b_dim1 + 1]), abs(d__2)) + ((d__3 = d__[1].r, abs(
00299 d__3)) + (d__4 = d_imag(&d__[1]), abs(d__4))) * ((
00300 d__5 = x[i__3].r, abs(d__5)) + (d__6 = d_imag(&x[j *
00301 x_dim1 + 1]), abs(d__6))) + ((d__7 = du[1].r, abs(
00302 d__7)) + (d__8 = d_imag(&du[1]), abs(d__8))) * ((d__9
00303 = x[i__4].r, abs(d__9)) + (d__10 = d_imag(&x[j *
00304 x_dim1 + 2]), abs(d__10)));
00305 i__2 = *n - 1;
00306 for (i__ = 2; i__ <= i__2; ++i__) {
00307 i__3 = i__ + j * b_dim1;
00308 i__4 = i__ - 1;
00309 i__5 = i__ - 1 + j * x_dim1;
00310 i__6 = i__;
00311 i__7 = i__ + j * x_dim1;
00312 i__8 = i__;
00313 i__9 = i__ + 1 + j * x_dim1;
00314 rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 =
00315 d_imag(&b[i__ + j * b_dim1]), abs(d__2)) + ((d__3
00316 = dl[i__4].r, abs(d__3)) + (d__4 = d_imag(&dl[i__
00317 - 1]), abs(d__4))) * ((d__5 = x[i__5].r, abs(d__5)
00318 ) + (d__6 = d_imag(&x[i__ - 1 + j * x_dim1]), abs(
00319 d__6))) + ((d__7 = d__[i__6].r, abs(d__7)) + (
00320 d__8 = d_imag(&d__[i__]), abs(d__8))) * ((d__9 =
00321 x[i__7].r, abs(d__9)) + (d__10 = d_imag(&x[i__ +
00322 j * x_dim1]), abs(d__10))) + ((d__11 = du[i__8].r,
00323 abs(d__11)) + (d__12 = d_imag(&du[i__]), abs(
00324 d__12))) * ((d__13 = x[i__9].r, abs(d__13)) + (
00325 d__14 = d_imag(&x[i__ + 1 + j * x_dim1]), abs(
00326 d__14)));
00327
00328 }
00329 i__2 = *n + j * b_dim1;
00330 i__3 = *n - 1;
00331 i__4 = *n - 1 + j * x_dim1;
00332 i__5 = *n;
00333 i__6 = *n + j * x_dim1;
00334 rwork[*n] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00335 *n + j * b_dim1]), abs(d__2)) + ((d__3 = dl[i__3].r,
00336 abs(d__3)) + (d__4 = d_imag(&dl[*n - 1]), abs(d__4)))
00337 * ((d__5 = x[i__4].r, abs(d__5)) + (d__6 = d_imag(&x[*
00338 n - 1 + j * x_dim1]), abs(d__6))) + ((d__7 = d__[i__5]
00339 .r, abs(d__7)) + (d__8 = d_imag(&d__[*n]), abs(d__8)))
00340 * ((d__9 = x[i__6].r, abs(d__9)) + (d__10 = d_imag(&
00341 x[*n + j * x_dim1]), abs(d__10)));
00342 }
00343 } else {
00344 if (*n == 1) {
00345 i__2 = j * b_dim1 + 1;
00346 i__3 = j * x_dim1 + 1;
00347 rwork[1] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00348 j * b_dim1 + 1]), abs(d__2)) + ((d__3 = d__[1].r, abs(
00349 d__3)) + (d__4 = d_imag(&d__[1]), abs(d__4))) * ((
00350 d__5 = x[i__3].r, abs(d__5)) + (d__6 = d_imag(&x[j *
00351 x_dim1 + 1]), abs(d__6)));
00352 } else {
00353 i__2 = j * b_dim1 + 1;
00354 i__3 = j * x_dim1 + 1;
00355 i__4 = j * x_dim1 + 2;
00356 rwork[1] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00357 j * b_dim1 + 1]), abs(d__2)) + ((d__3 = d__[1].r, abs(
00358 d__3)) + (d__4 = d_imag(&d__[1]), abs(d__4))) * ((
00359 d__5 = x[i__3].r, abs(d__5)) + (d__6 = d_imag(&x[j *
00360 x_dim1 + 1]), abs(d__6))) + ((d__7 = dl[1].r, abs(
00361 d__7)) + (d__8 = d_imag(&dl[1]), abs(d__8))) * ((d__9
00362 = x[i__4].r, abs(d__9)) + (d__10 = d_imag(&x[j *
00363 x_dim1 + 2]), abs(d__10)));
00364 i__2 = *n - 1;
00365 for (i__ = 2; i__ <= i__2; ++i__) {
00366 i__3 = i__ + j * b_dim1;
00367 i__4 = i__ - 1;
00368 i__5 = i__ - 1 + j * x_dim1;
00369 i__6 = i__;
00370 i__7 = i__ + j * x_dim1;
00371 i__8 = i__;
00372 i__9 = i__ + 1 + j * x_dim1;
00373 rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 =
00374 d_imag(&b[i__ + j * b_dim1]), abs(d__2)) + ((d__3
00375 = du[i__4].r, abs(d__3)) + (d__4 = d_imag(&du[i__
00376 - 1]), abs(d__4))) * ((d__5 = x[i__5].r, abs(d__5)
00377 ) + (d__6 = d_imag(&x[i__ - 1 + j * x_dim1]), abs(
00378 d__6))) + ((d__7 = d__[i__6].r, abs(d__7)) + (
00379 d__8 = d_imag(&d__[i__]), abs(d__8))) * ((d__9 =
00380 x[i__7].r, abs(d__9)) + (d__10 = d_imag(&x[i__ +
00381 j * x_dim1]), abs(d__10))) + ((d__11 = dl[i__8].r,
00382 abs(d__11)) + (d__12 = d_imag(&dl[i__]), abs(
00383 d__12))) * ((d__13 = x[i__9].r, abs(d__13)) + (
00384 d__14 = d_imag(&x[i__ + 1 + j * x_dim1]), abs(
00385 d__14)));
00386
00387 }
00388 i__2 = *n + j * b_dim1;
00389 i__3 = *n - 1;
00390 i__4 = *n - 1 + j * x_dim1;
00391 i__5 = *n;
00392 i__6 = *n + j * x_dim1;
00393 rwork[*n] = (d__1 = b[i__2].r, abs(d__1)) + (d__2 = d_imag(&b[
00394 *n + j * b_dim1]), abs(d__2)) + ((d__3 = du[i__3].r,
00395 abs(d__3)) + (d__4 = d_imag(&du[*n - 1]), abs(d__4)))
00396 * ((d__5 = x[i__4].r, abs(d__5)) + (d__6 = d_imag(&x[*
00397 n - 1 + j * x_dim1]), abs(d__6))) + ((d__7 = d__[i__5]
00398 .r, abs(d__7)) + (d__8 = d_imag(&d__[*n]), abs(d__8)))
00399 * ((d__9 = x[i__6].r, abs(d__9)) + (d__10 = d_imag(&
00400 x[*n + j * x_dim1]), abs(d__10)));
00401 }
00402 }
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 s = 0.;
00414 i__2 = *n;
00415 for (i__ = 1; i__ <= i__2; ++i__) {
00416 if (rwork[i__] > safe2) {
00417
00418 i__3 = i__;
00419 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 =
00420 d_imag(&work[i__]), abs(d__2))) / rwork[i__];
00421 s = max(d__3,d__4);
00422 } else {
00423
00424 i__3 = i__;
00425 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 =
00426 d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__]
00427 + safe1);
00428 s = max(d__3,d__4);
00429 }
00430
00431 }
00432 berr[j] = s;
00433
00434
00435
00436
00437
00438
00439
00440 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00441
00442
00443
00444 zgttrs_(trans, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[
00445 1], &work[1], n, info);
00446 zaxpy_(n, &c_b26, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00447 lstres = berr[j];
00448 ++count;
00449 goto L20;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 i__2 = *n;
00475 for (i__ = 1; i__ <= i__2; ++i__) {
00476 if (rwork[i__] > safe2) {
00477 i__3 = i__;
00478 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 =
00479 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00480 ;
00481 } else {
00482 i__3 = i__;
00483 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 =
00484 d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00485 + safe1;
00486 }
00487
00488 }
00489
00490 kase = 0;
00491 L70:
00492 zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00493 if (kase != 0) {
00494 if (kase == 1) {
00495
00496
00497
00498 zgttrs_(transt, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00499 ipiv[1], &work[1], n, info);
00500 i__2 = *n;
00501 for (i__ = 1; i__ <= i__2; ++i__) {
00502 i__3 = i__;
00503 i__4 = i__;
00504 i__5 = i__;
00505 z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4]
00506 * work[i__5].i;
00507 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00508
00509 }
00510 } else {
00511
00512
00513
00514 i__2 = *n;
00515 for (i__ = 1; i__ <= i__2; ++i__) {
00516 i__3 = i__;
00517 i__4 = i__;
00518 i__5 = i__;
00519 z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4]
00520 * work[i__5].i;
00521 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00522
00523 }
00524 zgttrs_(transn, n, &c__1, &dlf[1], &df[1], &duf[1], &du2[1], &
00525 ipiv[1], &work[1], n, info);
00526 }
00527 goto L70;
00528 }
00529
00530
00531
00532 lstres = 0.;
00533 i__2 = *n;
00534 for (i__ = 1; i__ <= i__2; ++i__) {
00535
00536 i__3 = i__ + j * x_dim1;
00537 d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
00538 d_imag(&x[i__ + j * x_dim1]), abs(d__2));
00539 lstres = max(d__3,d__4);
00540
00541 }
00542 if (lstres != 0.) {
00543 ferr[j] /= lstres;
00544 }
00545
00546
00547 }
00548
00549 return 0;
00550
00551
00552
00553 }