cgttrf.c
Go to the documentation of this file.
00001 /* cgttrf.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 cgttrf_(integer *n, complex *dl, complex *d__, complex *
00017         du, complex *du2, integer *ipiv, integer *info)
00018 {
00019     /* System generated locals */
00020     integer i__1, i__2, i__3, i__4;
00021     real r__1, r__2, r__3, r__4;
00022     complex q__1, q__2;
00023 
00024     /* Builtin functions */
00025     double r_imag(complex *);
00026     void c_div(complex *, complex *, complex *);
00027 
00028     /* Local variables */
00029     integer i__;
00030     complex fact, temp;
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 /*  CGTTRF computes an LU factorization of a complex tridiagonal matrix A */
00047 /*  using elimination with partial pivoting and row interchanges. */
00048 
00049 /*  The factorization has the form */
00050 /*     A = L * U */
00051 /*  where L is a product of permutation and unit lower bidiagonal */
00052 /*  matrices and U is upper triangular with nonzeros in only the main */
00053 /*  diagonal and first two superdiagonals. */
00054 
00055 /*  Arguments */
00056 /*  ========= */
00057 
00058 /*  N       (input) INTEGER */
00059 /*          The order of the matrix A. */
00060 
00061 /*  DL      (input/output) COMPLEX array, dimension (N-1) */
00062 /*          On entry, DL must contain the (n-1) sub-diagonal elements of */
00063 /*          A. */
00064 
00065 /*          On exit, DL is overwritten by the (n-1) multipliers that */
00066 /*          define the matrix L from the LU factorization of A. */
00067 
00068 /*  D       (input/output) COMPLEX array, dimension (N) */
00069 /*          On entry, D must contain the diagonal elements of A. */
00070 
00071 /*          On exit, D is overwritten by the n diagonal elements of the */
00072 /*          upper triangular matrix U from the LU factorization of A. */
00073 
00074 /*  DU      (input/output) COMPLEX array, dimension (N-1) */
00075 /*          On entry, DU must contain the (n-1) super-diagonal elements */
00076 /*          of A. */
00077 
00078 /*          On exit, DU is overwritten by the (n-1) elements of the first */
00079 /*          super-diagonal of U. */
00080 
00081 /*  DU2     (output) COMPLEX array, dimension (N-2) */
00082 /*          On exit, DU2 is overwritten by the (n-2) elements of the */
00083 /*          second super-diagonal of U. */
00084 
00085 /*  IPIV    (output) INTEGER array, dimension (N) */
00086 /*          The pivot indices; for 1 <= i <= n, row i of the matrix was */
00087 /*          interchanged with row IPIV(i).  IPIV(i) will always be either */
00088 /*          i or i+1; IPIV(i) = i indicates a row interchange was not */
00089 /*          required. */
00090 
00091 /*  INFO    (output) INTEGER */
00092 /*          = 0:  successful exit */
00093 /*          < 0:  if INFO = -k, the k-th argument had an illegal value */
00094 /*          > 0:  if INFO = k, U(k,k) is exactly zero. The factorization */
00095 /*                has been completed, but the factor U is exactly */
00096 /*                singular, and division by zero will occur if it is used */
00097 /*                to solve a system of equations. */
00098 
00099 /*  ===================================================================== */
00100 
00101 /*     .. Parameters .. */
00102 /*     .. */
00103 /*     .. Local Scalars .. */
00104 /*     .. */
00105 /*     .. External Subroutines .. */
00106 /*     .. */
00107 /*     .. Intrinsic Functions .. */
00108 /*     .. */
00109 /*     .. Statement Functions .. */
00110 /*     .. */
00111 /*     .. Statement Function definitions .. */
00112 /*     .. */
00113 /*     .. Executable Statements .. */
00114 
00115     /* Parameter adjustments */
00116     --ipiv;
00117     --du2;
00118     --du;
00119     --d__;
00120     --dl;
00121 
00122     /* Function Body */
00123     *info = 0;
00124     if (*n < 0) {
00125         *info = -1;
00126         i__1 = -(*info);
00127         xerbla_("CGTTRF", &i__1);
00128         return 0;
00129     }
00130 
00131 /*     Quick return if possible */
00132 
00133     if (*n == 0) {
00134         return 0;
00135     }
00136 
00137 /*     Initialize IPIV(i) = i and DU2(i) = 0 */
00138 
00139     i__1 = *n;
00140     for (i__ = 1; i__ <= i__1; ++i__) {
00141         ipiv[i__] = i__;
00142 /* L10: */
00143     }
00144     i__1 = *n - 2;
00145     for (i__ = 1; i__ <= i__1; ++i__) {
00146         i__2 = i__;
00147         du2[i__2].r = 0.f, du2[i__2].i = 0.f;
00148 /* L20: */
00149     }
00150 
00151     i__1 = *n - 2;
00152     for (i__ = 1; i__ <= i__1; ++i__) {
00153         i__2 = i__;
00154         i__3 = i__;
00155         if ((r__1 = d__[i__2].r, dabs(r__1)) + (r__2 = r_imag(&d__[i__]), 
00156                 dabs(r__2)) >= (r__3 = dl[i__3].r, dabs(r__3)) + (r__4 = 
00157                 r_imag(&dl[i__]), dabs(r__4))) {
00158 
00159 /*           No row interchange required, eliminate DL(I) */
00160 
00161             i__2 = i__;
00162             if ((r__1 = d__[i__2].r, dabs(r__1)) + (r__2 = r_imag(&d__[i__]), 
00163                     dabs(r__2)) != 0.f) {
00164                 c_div(&q__1, &dl[i__], &d__[i__]);
00165                 fact.r = q__1.r, fact.i = q__1.i;
00166                 i__2 = i__;
00167                 dl[i__2].r = fact.r, dl[i__2].i = fact.i;
00168                 i__2 = i__ + 1;
00169                 i__3 = i__ + 1;
00170                 i__4 = i__;
00171                 q__2.r = fact.r * du[i__4].r - fact.i * du[i__4].i, q__2.i = 
00172                         fact.r * du[i__4].i + fact.i * du[i__4].r;
00173                 q__1.r = d__[i__3].r - q__2.r, q__1.i = d__[i__3].i - q__2.i;
00174                 d__[i__2].r = q__1.r, d__[i__2].i = q__1.i;
00175             }
00176         } else {
00177 
00178 /*           Interchange rows I and I+1, eliminate DL(I) */
00179 
00180             c_div(&q__1, &d__[i__], &dl[i__]);
00181             fact.r = q__1.r, fact.i = q__1.i;
00182             i__2 = i__;
00183             i__3 = i__;
00184             d__[i__2].r = dl[i__3].r, d__[i__2].i = dl[i__3].i;
00185             i__2 = i__;
00186             dl[i__2].r = fact.r, dl[i__2].i = fact.i;
00187             i__2 = i__;
00188             temp.r = du[i__2].r, temp.i = du[i__2].i;
00189             i__2 = i__;
00190             i__3 = i__ + 1;
00191             du[i__2].r = d__[i__3].r, du[i__2].i = d__[i__3].i;
00192             i__2 = i__ + 1;
00193             i__3 = i__ + 1;
00194             q__2.r = fact.r * d__[i__3].r - fact.i * d__[i__3].i, q__2.i = 
00195                     fact.r * d__[i__3].i + fact.i * d__[i__3].r;
00196             q__1.r = temp.r - q__2.r, q__1.i = temp.i - q__2.i;
00197             d__[i__2].r = q__1.r, d__[i__2].i = q__1.i;
00198             i__2 = i__;
00199             i__3 = i__ + 1;
00200             du2[i__2].r = du[i__3].r, du2[i__2].i = du[i__3].i;
00201             i__2 = i__ + 1;
00202             q__2.r = -fact.r, q__2.i = -fact.i;
00203             i__3 = i__ + 1;
00204             q__1.r = q__2.r * du[i__3].r - q__2.i * du[i__3].i, q__1.i = 
00205                     q__2.r * du[i__3].i + q__2.i * du[i__3].r;
00206             du[i__2].r = q__1.r, du[i__2].i = q__1.i;
00207             ipiv[i__] = i__ + 1;
00208         }
00209 /* L30: */
00210     }
00211     if (*n > 1) {
00212         i__ = *n - 1;
00213         i__1 = i__;
00214         i__2 = i__;
00215         if ((r__1 = d__[i__1].r, dabs(r__1)) + (r__2 = r_imag(&d__[i__]), 
00216                 dabs(r__2)) >= (r__3 = dl[i__2].r, dabs(r__3)) + (r__4 = 
00217                 r_imag(&dl[i__]), dabs(r__4))) {
00218             i__1 = i__;
00219             if ((r__1 = d__[i__1].r, dabs(r__1)) + (r__2 = r_imag(&d__[i__]), 
00220                     dabs(r__2)) != 0.f) {
00221                 c_div(&q__1, &dl[i__], &d__[i__]);
00222                 fact.r = q__1.r, fact.i = q__1.i;
00223                 i__1 = i__;
00224                 dl[i__1].r = fact.r, dl[i__1].i = fact.i;
00225                 i__1 = i__ + 1;
00226                 i__2 = i__ + 1;
00227                 i__3 = i__;
00228                 q__2.r = fact.r * du[i__3].r - fact.i * du[i__3].i, q__2.i = 
00229                         fact.r * du[i__3].i + fact.i * du[i__3].r;
00230                 q__1.r = d__[i__2].r - q__2.r, q__1.i = d__[i__2].i - q__2.i;
00231                 d__[i__1].r = q__1.r, d__[i__1].i = q__1.i;
00232             }
00233         } else {
00234             c_div(&q__1, &d__[i__], &dl[i__]);
00235             fact.r = q__1.r, fact.i = q__1.i;
00236             i__1 = i__;
00237             i__2 = i__;
00238             d__[i__1].r = dl[i__2].r, d__[i__1].i = dl[i__2].i;
00239             i__1 = i__;
00240             dl[i__1].r = fact.r, dl[i__1].i = fact.i;
00241             i__1 = i__;
00242             temp.r = du[i__1].r, temp.i = du[i__1].i;
00243             i__1 = i__;
00244             i__2 = i__ + 1;
00245             du[i__1].r = d__[i__2].r, du[i__1].i = d__[i__2].i;
00246             i__1 = i__ + 1;
00247             i__2 = i__ + 1;
00248             q__2.r = fact.r * d__[i__2].r - fact.i * d__[i__2].i, q__2.i = 
00249                     fact.r * d__[i__2].i + fact.i * d__[i__2].r;
00250             q__1.r = temp.r - q__2.r, q__1.i = temp.i - q__2.i;
00251             d__[i__1].r = q__1.r, d__[i__1].i = q__1.i;
00252             ipiv[i__] = i__ + 1;
00253         }
00254     }
00255 
00256 /*     Check for a zero on the diagonal of U. */
00257 
00258     i__1 = *n;
00259     for (i__ = 1; i__ <= i__1; ++i__) {
00260         i__2 = i__;
00261         if ((r__1 = d__[i__2].r, dabs(r__1)) + (r__2 = r_imag(&d__[i__]), 
00262                 dabs(r__2)) == 0.f) {
00263             *info = i__;
00264             goto L50;
00265         }
00266 /* L40: */
00267     }
00268 L50:
00269 
00270     return 0;
00271 
00272 /*     End of CGTTRF */
00273 
00274 } /* cgttrf_ */


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