cgtsv.c
Go to the documentation of this file.
00001 /* cgtsv.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Subroutine */ int cgtsv_(integer *n, integer *nrhs, complex *dl, complex *
00017         d__, complex *du, complex *b, integer *ldb, integer *info)
00018 {
00019     /* System generated locals */
00020     integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7;
00021     real r__1, r__2, r__3, r__4;
00022     complex q__1, q__2, q__3, q__4, q__5;
00023 
00024     /* Builtin functions */
00025     double r_imag(complex *);
00026     void c_div(complex *, complex *, complex *);
00027 
00028     /* Local variables */
00029     integer j, k;
00030     complex temp, mult;
00031     extern /* Subroutine */ int xerbla_(char *, integer *);
00032 
00033 
00034 /*  -- LAPACK routine (version 3.2) -- */
00035 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00036 /*     November 2006 */
00037 
00038 /*     .. Scalar Arguments .. */
00039 /*     .. */
00040 /*     .. Array Arguments .. */
00041 /*     .. */
00042 
00043 /*  Purpose */
00044 /*  ======= */
00045 
00046 /*  CGTSV  solves the equation */
00047 
00048 /*     A*X = B, */
00049 
00050 /*  where A is an N-by-N tridiagonal matrix, by Gaussian elimination with */
00051 /*  partial pivoting. */
00052 
00053 /*  Note that the equation  A'*X = B  may be solved by interchanging the */
00054 /*  order of the arguments DU and DL. */
00055 
00056 /*  Arguments */
00057 /*  ========= */
00058 
00059 /*  N       (input) INTEGER */
00060 /*          The order of the matrix A.  N >= 0. */
00061 
00062 /*  NRHS    (input) INTEGER */
00063 /*          The number of right hand sides, i.e., the number of columns */
00064 /*          of the matrix B.  NRHS >= 0. */
00065 
00066 /*  DL      (input/output) COMPLEX array, dimension (N-1) */
00067 /*          On entry, DL must contain the (n-1) subdiagonal elements of */
00068 /*          A. */
00069 /*          On exit, DL is overwritten by the (n-2) elements of the */
00070 /*          second superdiagonal of the upper triangular matrix U from */
00071 /*          the LU factorization of A, in DL(1), ..., DL(n-2). */
00072 
00073 /*  D       (input/output) COMPLEX array, dimension (N) */
00074 /*          On entry, D must contain the diagonal elements of A. */
00075 /*          On exit, D is overwritten by the n diagonal elements of U. */
00076 
00077 /*  DU      (input/output) COMPLEX array, dimension (N-1) */
00078 /*          On entry, DU must contain the (n-1) superdiagonal elements */
00079 /*          of A. */
00080 /*          On exit, DU is overwritten by the (n-1) elements of the first */
00081 /*          superdiagonal of U. */
00082 
00083 /*  B       (input/output) COMPLEX array, dimension (LDB,NRHS) */
00084 /*          On entry, the N-by-NRHS right hand side matrix B. */
00085 /*          On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
00086 
00087 /*  LDB     (input) INTEGER */
00088 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00089 
00090 /*  INFO    (output) INTEGER */
00091 /*          = 0:  successful exit */
00092 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00093 /*          > 0:  if INFO = i, U(i,i) is exactly zero, and the solution */
00094 /*                has not been computed.  The factorization has not been */
00095 /*                completed unless i = N. */
00096 
00097 /*  ===================================================================== */
00098 
00099 /*     .. Parameters .. */
00100 /*     .. */
00101 /*     .. Local Scalars .. */
00102 /*     .. */
00103 /*     .. Intrinsic Functions .. */
00104 /*     .. */
00105 /*     .. External Subroutines .. */
00106 /*     .. */
00107 /*     .. Statement Functions .. */
00108 /*     .. */
00109 /*     .. Statement Function definitions .. */
00110 /*     .. */
00111 /*     .. Executable Statements .. */
00112 
00113     /* Parameter adjustments */
00114     --dl;
00115     --d__;
00116     --du;
00117     b_dim1 = *ldb;
00118     b_offset = 1 + b_dim1;
00119     b -= b_offset;
00120 
00121     /* Function Body */
00122     *info = 0;
00123     if (*n < 0) {
00124         *info = -1;
00125     } else if (*nrhs < 0) {
00126         *info = -2;
00127     } else if (*ldb < max(1,*n)) {
00128         *info = -7;
00129     }
00130     if (*info != 0) {
00131         i__1 = -(*info);
00132         xerbla_("CGTSV ", &i__1);
00133         return 0;
00134     }
00135 
00136     if (*n == 0) {
00137         return 0;
00138     }
00139 
00140     i__1 = *n - 1;
00141     for (k = 1; k <= i__1; ++k) {
00142         i__2 = k;
00143         if (dl[i__2].r == 0.f && dl[i__2].i == 0.f) {
00144 
00145 /*           Subdiagonal is zero, no elimination is required. */
00146 
00147             i__2 = k;
00148             if (d__[i__2].r == 0.f && d__[i__2].i == 0.f) {
00149 
00150 /*              Diagonal is zero: set INFO = K and return; a unique */
00151 /*              solution can not be found. */
00152 
00153                 *info = k;
00154                 return 0;
00155             }
00156         } else /* if(complicated condition) */ {
00157             i__2 = k;
00158             i__3 = k;
00159             if ((r__1 = d__[i__2].r, dabs(r__1)) + (r__2 = r_imag(&d__[k]), 
00160                     dabs(r__2)) >= (r__3 = dl[i__3].r, dabs(r__3)) + (r__4 = 
00161                     r_imag(&dl[k]), dabs(r__4))) {
00162 
00163 /*           No row interchange required */
00164 
00165                 c_div(&q__1, &dl[k], &d__[k]);
00166                 mult.r = q__1.r, mult.i = q__1.i;
00167                 i__2 = k + 1;
00168                 i__3 = k + 1;
00169                 i__4 = k;
00170                 q__2.r = mult.r * du[i__4].r - mult.i * du[i__4].i, q__2.i = 
00171                         mult.r * du[i__4].i + mult.i * du[i__4].r;
00172                 q__1.r = d__[i__3].r - q__2.r, q__1.i = d__[i__3].i - q__2.i;
00173                 d__[i__2].r = q__1.r, d__[i__2].i = q__1.i;
00174                 i__2 = *nrhs;
00175                 for (j = 1; j <= i__2; ++j) {
00176                     i__3 = k + 1 + j * b_dim1;
00177                     i__4 = k + 1 + j * b_dim1;
00178                     i__5 = k + j * b_dim1;
00179                     q__2.r = mult.r * b[i__5].r - mult.i * b[i__5].i, q__2.i =
00180                              mult.r * b[i__5].i + mult.i * b[i__5].r;
00181                     q__1.r = b[i__4].r - q__2.r, q__1.i = b[i__4].i - q__2.i;
00182                     b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00183 /* L10: */
00184                 }
00185                 if (k < *n - 1) {
00186                     i__2 = k;
00187                     dl[i__2].r = 0.f, dl[i__2].i = 0.f;
00188                 }
00189             } else {
00190 
00191 /*           Interchange rows K and K+1 */
00192 
00193                 c_div(&q__1, &d__[k], &dl[k]);
00194                 mult.r = q__1.r, mult.i = q__1.i;
00195                 i__2 = k;
00196                 i__3 = k;
00197                 d__[i__2].r = dl[i__3].r, d__[i__2].i = dl[i__3].i;
00198                 i__2 = k + 1;
00199                 temp.r = d__[i__2].r, temp.i = d__[i__2].i;
00200                 i__2 = k + 1;
00201                 i__3 = k;
00202                 q__2.r = mult.r * temp.r - mult.i * temp.i, q__2.i = mult.r * 
00203                         temp.i + mult.i * temp.r;
00204                 q__1.r = du[i__3].r - q__2.r, q__1.i = du[i__3].i - q__2.i;
00205                 d__[i__2].r = q__1.r, d__[i__2].i = q__1.i;
00206                 if (k < *n - 1) {
00207                     i__2 = k;
00208                     i__3 = k + 1;
00209                     dl[i__2].r = du[i__3].r, dl[i__2].i = du[i__3].i;
00210                     i__2 = k + 1;
00211                     q__2.r = -mult.r, q__2.i = -mult.i;
00212                     i__3 = k;
00213                     q__1.r = q__2.r * dl[i__3].r - q__2.i * dl[i__3].i, 
00214                             q__1.i = q__2.r * dl[i__3].i + q__2.i * dl[i__3]
00215                             .r;
00216                     du[i__2].r = q__1.r, du[i__2].i = q__1.i;
00217                 }
00218                 i__2 = k;
00219                 du[i__2].r = temp.r, du[i__2].i = temp.i;
00220                 i__2 = *nrhs;
00221                 for (j = 1; j <= i__2; ++j) {
00222                     i__3 = k + j * b_dim1;
00223                     temp.r = b[i__3].r, temp.i = b[i__3].i;
00224                     i__3 = k + j * b_dim1;
00225                     i__4 = k + 1 + j * b_dim1;
00226                     b[i__3].r = b[i__4].r, b[i__3].i = b[i__4].i;
00227                     i__3 = k + 1 + j * b_dim1;
00228                     i__4 = k + 1 + j * b_dim1;
00229                     q__2.r = mult.r * b[i__4].r - mult.i * b[i__4].i, q__2.i =
00230                              mult.r * b[i__4].i + mult.i * b[i__4].r;
00231                     q__1.r = temp.r - q__2.r, q__1.i = temp.i - q__2.i;
00232                     b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00233 /* L20: */
00234                 }
00235             }
00236         }
00237 /* L30: */
00238     }
00239     i__1 = *n;
00240     if (d__[i__1].r == 0.f && d__[i__1].i == 0.f) {
00241         *info = *n;
00242         return 0;
00243     }
00244 
00245 /*     Back solve with the matrix U from the factorization. */
00246 
00247     i__1 = *nrhs;
00248     for (j = 1; j <= i__1; ++j) {
00249         i__2 = *n + j * b_dim1;
00250         c_div(&q__1, &b[*n + j * b_dim1], &d__[*n]);
00251         b[i__2].r = q__1.r, b[i__2].i = q__1.i;
00252         if (*n > 1) {
00253             i__2 = *n - 1 + j * b_dim1;
00254             i__3 = *n - 1 + j * b_dim1;
00255             i__4 = *n - 1;
00256             i__5 = *n + j * b_dim1;
00257             q__3.r = du[i__4].r * b[i__5].r - du[i__4].i * b[i__5].i, q__3.i =
00258                      du[i__4].r * b[i__5].i + du[i__4].i * b[i__5].r;
00259             q__2.r = b[i__3].r - q__3.r, q__2.i = b[i__3].i - q__3.i;
00260             c_div(&q__1, &q__2, &d__[*n - 1]);
00261             b[i__2].r = q__1.r, b[i__2].i = q__1.i;
00262         }
00263         for (k = *n - 2; k >= 1; --k) {
00264             i__2 = k + j * b_dim1;
00265             i__3 = k + j * b_dim1;
00266             i__4 = k;
00267             i__5 = k + 1 + j * b_dim1;
00268             q__4.r = du[i__4].r * b[i__5].r - du[i__4].i * b[i__5].i, q__4.i =
00269                      du[i__4].r * b[i__5].i + du[i__4].i * b[i__5].r;
00270             q__3.r = b[i__3].r - q__4.r, q__3.i = b[i__3].i - q__4.i;
00271             i__6 = k;
00272             i__7 = k + 2 + j * b_dim1;
00273             q__5.r = dl[i__6].r * b[i__7].r - dl[i__6].i * b[i__7].i, q__5.i =
00274                      dl[i__6].r * b[i__7].i + dl[i__6].i * b[i__7].r;
00275             q__2.r = q__3.r - q__5.r, q__2.i = q__3.i - q__5.i;
00276             c_div(&q__1, &q__2, &d__[k]);
00277             b[i__2].r = q__1.r, b[i__2].i = q__1.i;
00278 /* L40: */
00279         }
00280 /* L50: */
00281     }
00282 
00283     return 0;
00284 
00285 /*     End of CGTSV */
00286 
00287 } /* cgtsv_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:28