zgesc2.c
Go to the documentation of this file.
00001 /* zgesc2.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 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static doublecomplex c_b13 = {1.,0.};
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int zgesc2_(integer *n, doublecomplex *a, integer *lda, 
00023         doublecomplex *rhs, integer *ipiv, integer *jpiv, doublereal *scale)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00027     doublereal d__1;
00028     doublecomplex z__1, z__2, z__3;
00029 
00030     /* Builtin functions */
00031     double z_abs(doublecomplex *);
00032     void z_div(doublecomplex *, doublecomplex *, doublecomplex *);
00033 
00034     /* Local variables */
00035     integer i__, j;
00036     doublereal eps;
00037     doublecomplex temp;
00038     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
00039             doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
00040     extern doublereal dlamch_(char *);
00041     doublereal bignum;
00042     extern integer izamax_(integer *, doublecomplex *, integer *);
00043     doublereal smlnum;
00044     extern /* Subroutine */ int zlaswp_(integer *, doublecomplex *, integer *, 
00045              integer *, integer *, integer *, integer *);
00046 
00047 
00048 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00049 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00050 /*     November 2006 */
00051 
00052 /*     .. Scalar Arguments .. */
00053 /*     .. */
00054 /*     .. Array Arguments .. */
00055 /*     .. */
00056 
00057 /*  Purpose */
00058 /*  ======= */
00059 
00060 /*  ZGESC2 solves a system of linear equations */
00061 
00062 /*            A * X = scale* RHS */
00063 
00064 /*  with a general N-by-N matrix A using the LU factorization with */
00065 /*  complete pivoting computed by ZGETC2. */
00066 
00067 
00068 /*  Arguments */
00069 /*  ========= */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The number of columns of the matrix A. */
00073 
00074 /*  A       (input) COMPLEX*16 array, dimension (LDA, N) */
00075 /*          On entry, the  LU part of the factorization of the n-by-n */
00076 /*          matrix A computed by ZGETC2:  A = P * L * U * Q */
00077 
00078 /*  LDA     (input) INTEGER */
00079 /*          The leading dimension of the array A.  LDA >= max(1, N). */
00080 
00081 /*  RHS     (input/output) COMPLEX*16 array, dimension N. */
00082 /*          On entry, the right hand side vector b. */
00083 /*          On exit, the solution vector X. */
00084 
00085 /*  IPIV    (input) INTEGER array, dimension (N). */
00086 /*          The pivot indices; for 1 <= i <= N, row i of the */
00087 /*          matrix has been interchanged with row IPIV(i). */
00088 
00089 /*  JPIV    (input) INTEGER array, dimension (N). */
00090 /*          The pivot indices; for 1 <= j <= N, column j of the */
00091 /*          matrix has been interchanged with column JPIV(j). */
00092 
00093 /*  SCALE    (output) DOUBLE PRECISION */
00094 /*           On exit, SCALE contains the scale factor. SCALE is chosen */
00095 /*           0 <= SCALE <= 1 to prevent owerflow in the solution. */
00096 
00097 /*  Further Details */
00098 /*  =============== */
00099 
00100 /*  Based on contributions by */
00101 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00102 /*     Umea University, S-901 87 Umea, Sweden. */
00103 
00104 /*  ===================================================================== */
00105 
00106 /*     .. Parameters .. */
00107 /*     .. */
00108 /*     .. Local Scalars .. */
00109 /*     .. */
00110 /*     .. External Subroutines .. */
00111 /*     .. */
00112 /*     .. External Functions .. */
00113 /*     .. */
00114 /*     .. Intrinsic Functions .. */
00115 /*     .. */
00116 /*     .. Executable Statements .. */
00117 
00118 /*     Set constant to control overflow */
00119 
00120     /* Parameter adjustments */
00121     a_dim1 = *lda;
00122     a_offset = 1 + a_dim1;
00123     a -= a_offset;
00124     --rhs;
00125     --ipiv;
00126     --jpiv;
00127 
00128     /* Function Body */
00129     eps = dlamch_("P");
00130     smlnum = dlamch_("S") / eps;
00131     bignum = 1. / smlnum;
00132     dlabad_(&smlnum, &bignum);
00133 
00134 /*     Apply permutations IPIV to RHS */
00135 
00136     i__1 = *n - 1;
00137     zlaswp_(&c__1, &rhs[1], lda, &c__1, &i__1, &ipiv[1], &c__1);
00138 
00139 /*     Solve for L part */
00140 
00141     i__1 = *n - 1;
00142     for (i__ = 1; i__ <= i__1; ++i__) {
00143         i__2 = *n;
00144         for (j = i__ + 1; j <= i__2; ++j) {
00145             i__3 = j;
00146             i__4 = j;
00147             i__5 = j + i__ * a_dim1;
00148             i__6 = i__;
00149             z__2.r = a[i__5].r * rhs[i__6].r - a[i__5].i * rhs[i__6].i, 
00150                     z__2.i = a[i__5].r * rhs[i__6].i + a[i__5].i * rhs[i__6]
00151                     .r;
00152             z__1.r = rhs[i__4].r - z__2.r, z__1.i = rhs[i__4].i - z__2.i;
00153             rhs[i__3].r = z__1.r, rhs[i__3].i = z__1.i;
00154 /* L10: */
00155         }
00156 /* L20: */
00157     }
00158 
00159 /*     Solve for U part */
00160 
00161     *scale = 1.;
00162 
00163 /*     Check for scaling */
00164 
00165     i__ = izamax_(n, &rhs[1], &c__1);
00166     if (smlnum * 2. * z_abs(&rhs[i__]) > z_abs(&a[*n + *n * a_dim1])) {
00167         d__1 = z_abs(&rhs[i__]);
00168         z__1.r = .5 / d__1, z__1.i = 0. / d__1;
00169         temp.r = z__1.r, temp.i = z__1.i;
00170         zscal_(n, &temp, &rhs[1], &c__1);
00171         *scale *= temp.r;
00172     }
00173     for (i__ = *n; i__ >= 1; --i__) {
00174         z_div(&z__1, &c_b13, &a[i__ + i__ * a_dim1]);
00175         temp.r = z__1.r, temp.i = z__1.i;
00176         i__1 = i__;
00177         i__2 = i__;
00178         z__1.r = rhs[i__2].r * temp.r - rhs[i__2].i * temp.i, z__1.i = rhs[
00179                 i__2].r * temp.i + rhs[i__2].i * temp.r;
00180         rhs[i__1].r = z__1.r, rhs[i__1].i = z__1.i;
00181         i__1 = *n;
00182         for (j = i__ + 1; j <= i__1; ++j) {
00183             i__2 = i__;
00184             i__3 = i__;
00185             i__4 = j;
00186             i__5 = i__ + j * a_dim1;
00187             z__3.r = a[i__5].r * temp.r - a[i__5].i * temp.i, z__3.i = a[i__5]
00188                     .r * temp.i + a[i__5].i * temp.r;
00189             z__2.r = rhs[i__4].r * z__3.r - rhs[i__4].i * z__3.i, z__2.i = 
00190                     rhs[i__4].r * z__3.i + rhs[i__4].i * z__3.r;
00191             z__1.r = rhs[i__3].r - z__2.r, z__1.i = rhs[i__3].i - z__2.i;
00192             rhs[i__2].r = z__1.r, rhs[i__2].i = z__1.i;
00193 /* L30: */
00194         }
00195 /* L40: */
00196     }
00197 
00198 /*     Apply permutations JPIV to the solution (RHS) */
00199 
00200     i__1 = *n - 1;
00201     zlaswp_(&c__1, &rhs[1], lda, &c__1, &i__1, &jpiv[1], &c_n1);
00202     return 0;
00203 
00204 /*     End of ZGESC2 */
00205 
00206 } /* zgesc2_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:33