cgetc2.c
Go to the documentation of this file.
00001 /* cgetc2.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 complex c_b10 = {-1.f,-0.f};
00020 
00021 /* Subroutine */ int cgetc2_(integer *n, complex *a, integer *lda, integer *
00022         ipiv, integer *jpiv, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     real r__1;
00027     complex q__1;
00028 
00029     /* Builtin functions */
00030     double c_abs(complex *);
00031     void c_div(complex *, complex *, complex *);
00032 
00033     /* Local variables */
00034     integer i__, j, ip, jp;
00035     real eps;
00036     integer ipv, jpv;
00037     real smin, xmax;
00038     extern /* Subroutine */ int cgeru_(integer *, integer *, complex *, 
00039             complex *, integer *, complex *, integer *, complex *, integer *),
00040              cswap_(integer *, complex *, integer *, complex *, integer *), 
00041             slabad_(real *, real *);
00042     extern doublereal slamch_(char *);
00043     real bignum, smlnum;
00044 
00045 
00046 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00047 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00048 /*     November 2006 */
00049 
00050 /*     .. Scalar Arguments .. */
00051 /*     .. */
00052 /*     .. Array Arguments .. */
00053 /*     .. */
00054 
00055 /*  Purpose */
00056 /*  ======= */
00057 
00058 /*  CGETC2 computes an LU factorization, using complete pivoting, of the */
00059 /*  n-by-n matrix A. The factorization has the form A = P * L * U * Q, */
00060 /*  where P and Q are permutation matrices, L is lower triangular with */
00061 /*  unit diagonal elements and U is upper triangular. */
00062 
00063 /*  This is a level 1 BLAS version of the algorithm. */
00064 
00065 /*  Arguments */
00066 /*  ========= */
00067 
00068 /*  N       (input) INTEGER */
00069 /*          The order of the matrix A. N >= 0. */
00070 
00071 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00072 /*          On entry, the n-by-n matrix to be factored. */
00073 /*          On exit, the factors L and U from the factorization */
00074 /*          A = P*L*U*Q; the unit diagonal elements of L are not stored. */
00075 /*          If U(k, k) appears to be less than SMIN, U(k, k) is given the */
00076 /*          value of SMIN, giving a nonsingular perturbed system. */
00077 
00078 /*  LDA     (input) INTEGER */
00079 /*          The leading dimension of the array A.  LDA >= max(1, N). */
00080 
00081 /*  IPIV    (output) INTEGER array, dimension (N). */
00082 /*          The pivot indices; for 1 <= i <= N, row i of the */
00083 /*          matrix has been interchanged with row IPIV(i). */
00084 
00085 /*  JPIV    (output) INTEGER array, dimension (N). */
00086 /*          The pivot indices; for 1 <= j <= N, column j of the */
00087 /*          matrix has been interchanged with column JPIV(j). */
00088 
00089 /*  INFO    (output) INTEGER */
00090 /*           = 0: successful exit */
00091 /*           > 0: if INFO = k, U(k, k) is likely to produce overflow if */
00092 /*                one tries to solve for x in Ax = b. So U is perturbed */
00093 /*                to avoid the overflow. */
00094 
00095 /*  Further Details */
00096 /*  =============== */
00097 
00098 /*  Based on contributions by */
00099 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00100 /*     Umea University, S-901 87 Umea, Sweden. */
00101 
00102 /*  ===================================================================== */
00103 
00104 /*     .. Parameters .. */
00105 /*     .. */
00106 /*     .. Local Scalars .. */
00107 /*     .. */
00108 /*     .. External Subroutines .. */
00109 /*     .. */
00110 /*     .. External Functions .. */
00111 /*     .. */
00112 /*     .. Intrinsic Functions .. */
00113 /*     .. */
00114 /*     .. Executable Statements .. */
00115 
00116 /*     Set constants to control overflow */
00117 
00118     /* Parameter adjustments */
00119     a_dim1 = *lda;
00120     a_offset = 1 + a_dim1;
00121     a -= a_offset;
00122     --ipiv;
00123     --jpiv;
00124 
00125     /* Function Body */
00126     *info = 0;
00127     eps = slamch_("P");
00128     smlnum = slamch_("S") / eps;
00129     bignum = 1.f / smlnum;
00130     slabad_(&smlnum, &bignum);
00131 
00132 /*     Factorize A using complete pivoting. */
00133 /*     Set pivots less than SMIN to SMIN */
00134 
00135     i__1 = *n - 1;
00136     for (i__ = 1; i__ <= i__1; ++i__) {
00137 
00138 /*        Find max element in matrix A */
00139 
00140         xmax = 0.f;
00141         i__2 = *n;
00142         for (ip = i__; ip <= i__2; ++ip) {
00143             i__3 = *n;
00144             for (jp = i__; jp <= i__3; ++jp) {
00145                 if (c_abs(&a[ip + jp * a_dim1]) >= xmax) {
00146                     xmax = c_abs(&a[ip + jp * a_dim1]);
00147                     ipv = ip;
00148                     jpv = jp;
00149                 }
00150 /* L10: */
00151             }
00152 /* L20: */
00153         }
00154         if (i__ == 1) {
00155 /* Computing MAX */
00156             r__1 = eps * xmax;
00157             smin = dmax(r__1,smlnum);
00158         }
00159 
00160 /*        Swap rows */
00161 
00162         if (ipv != i__) {
00163             cswap_(n, &a[ipv + a_dim1], lda, &a[i__ + a_dim1], lda);
00164         }
00165         ipiv[i__] = ipv;
00166 
00167 /*        Swap columns */
00168 
00169         if (jpv != i__) {
00170             cswap_(n, &a[jpv * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
00171                     c__1);
00172         }
00173         jpiv[i__] = jpv;
00174 
00175 /*        Check for singularity */
00176 
00177         if (c_abs(&a[i__ + i__ * a_dim1]) < smin) {
00178             *info = i__;
00179             i__2 = i__ + i__ * a_dim1;
00180             q__1.r = smin, q__1.i = 0.f;
00181             a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00182         }
00183         i__2 = *n;
00184         for (j = i__ + 1; j <= i__2; ++j) {
00185             i__3 = j + i__ * a_dim1;
00186             c_div(&q__1, &a[j + i__ * a_dim1], &a[i__ + i__ * a_dim1]);
00187             a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00188 /* L30: */
00189         }
00190         i__2 = *n - i__;
00191         i__3 = *n - i__;
00192         cgeru_(&i__2, &i__3, &c_b10, &a[i__ + 1 + i__ * a_dim1], &c__1, &a[
00193                 i__ + (i__ + 1) * a_dim1], lda, &a[i__ + 1 + (i__ + 1) * 
00194                 a_dim1], lda);
00195 /* L40: */
00196     }
00197 
00198     if (c_abs(&a[*n + *n * a_dim1]) < smin) {
00199         *info = *n;
00200         i__1 = *n + *n * a_dim1;
00201         q__1.r = smin, q__1.i = 0.f;
00202         a[i__1].r = q__1.r, a[i__1].i = q__1.i;
00203     }
00204     return 0;
00205 
00206 /*     End of CGETC2 */
00207 
00208 } /* cgetc2_ */


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