sgbequ.c
Go to the documentation of this file.
00001 /* sgbequ.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 sgbequ_(integer *m, integer *n, integer *kl, integer *ku, 
00017          real *ab, integer *ldab, real *r__, real *c__, real *rowcnd, real *
00018         colcnd, real *amax, integer *info)
00019 {
00020     /* System generated locals */
00021     integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
00022     real r__1, r__2, r__3;
00023 
00024     /* Local variables */
00025     integer i__, j, kd;
00026     real rcmin, rcmax;
00027     extern doublereal slamch_(char *);
00028     extern /* Subroutine */ int xerbla_(char *, integer *);
00029     real bignum, smlnum;
00030 
00031 
00032 /*  -- LAPACK routine (version 3.2) -- */
00033 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00034 /*     November 2006 */
00035 
00036 /*     .. Scalar Arguments .. */
00037 /*     .. */
00038 /*     .. Array Arguments .. */
00039 /*     .. */
00040 
00041 /*  Purpose */
00042 /*  ======= */
00043 
00044 /*  SGBEQU computes row and column scalings intended to equilibrate an */
00045 /*  M-by-N band matrix A and reduce its condition number.  R returns the */
00046 /*  row scale factors and C the column scale factors, chosen to try to */
00047 /*  make the largest element in each row and column of the matrix B with */
00048 /*  elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1. */
00049 
00050 /*  R(i) and C(j) are restricted to be between SMLNUM = smallest safe */
00051 /*  number and BIGNUM = largest safe number.  Use of these scaling */
00052 /*  factors is not guaranteed to reduce the condition number of A but */
00053 /*  works well in practice. */
00054 
00055 /*  Arguments */
00056 /*  ========= */
00057 
00058 /*  M       (input) INTEGER */
00059 /*          The number of rows of the matrix A.  M >= 0. */
00060 
00061 /*  N       (input) INTEGER */
00062 /*          The number of columns of the matrix A.  N >= 0. */
00063 
00064 /*  KL      (input) INTEGER */
00065 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00066 
00067 /*  KU      (input) INTEGER */
00068 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00069 
00070 /*  AB      (input) REAL array, dimension (LDAB,N) */
00071 /*          The band matrix A, stored in rows 1 to KL+KU+1.  The j-th */
00072 /*          column of A is stored in the j-th column of the array AB as */
00073 /*          follows: */
00074 /*          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl). */
00075 
00076 /*  LDAB    (input) INTEGER */
00077 /*          The leading dimension of the array AB.  LDAB >= KL+KU+1. */
00078 
00079 /*  R       (output) REAL array, dimension (M) */
00080 /*          If INFO = 0, or INFO > M, R contains the row scale factors */
00081 /*          for A. */
00082 
00083 /*  C       (output) REAL array, dimension (N) */
00084 /*          If INFO = 0, C contains the column scale factors for A. */
00085 
00086 /*  ROWCND  (output) REAL */
00087 /*          If INFO = 0 or INFO > M, ROWCND contains the ratio of the */
00088 /*          smallest R(i) to the largest R(i).  If ROWCND >= 0.1 and */
00089 /*          AMAX is neither too large nor too small, it is not worth */
00090 /*          scaling by R. */
00091 
00092 /*  COLCND  (output) REAL */
00093 /*          If INFO = 0, COLCND contains the ratio of the smallest */
00094 /*          C(i) to the largest C(i).  If COLCND >= 0.1, it is not */
00095 /*          worth scaling by C. */
00096 
00097 /*  AMAX    (output) REAL */
00098 /*          Absolute value of largest matrix element.  If AMAX is very */
00099 /*          close to overflow or very close to underflow, the matrix */
00100 /*          should be scaled. */
00101 
00102 /*  INFO    (output) INTEGER */
00103 /*          = 0:  successful exit */
00104 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00105 /*          > 0:  if INFO = i, and i is */
00106 /*                <= M:  the i-th row of A is exactly zero */
00107 /*                >  M:  the (i-M)-th column of A is exactly zero */
00108 
00109 /*  ===================================================================== */
00110 
00111 /*     .. Parameters .. */
00112 /*     .. */
00113 /*     .. Local Scalars .. */
00114 /*     .. */
00115 /*     .. External Functions .. */
00116 /*     .. */
00117 /*     .. External Subroutines .. */
00118 /*     .. */
00119 /*     .. Intrinsic Functions .. */
00120 /*     .. */
00121 /*     .. Executable Statements .. */
00122 
00123 /*     Test the input parameters */
00124 
00125     /* Parameter adjustments */
00126     ab_dim1 = *ldab;
00127     ab_offset = 1 + ab_dim1;
00128     ab -= ab_offset;
00129     --r__;
00130     --c__;
00131 
00132     /* Function Body */
00133     *info = 0;
00134     if (*m < 0) {
00135         *info = -1;
00136     } else if (*n < 0) {
00137         *info = -2;
00138     } else if (*kl < 0) {
00139         *info = -3;
00140     } else if (*ku < 0) {
00141         *info = -4;
00142     } else if (*ldab < *kl + *ku + 1) {
00143         *info = -6;
00144     }
00145     if (*info != 0) {
00146         i__1 = -(*info);
00147         xerbla_("SGBEQU", &i__1);
00148         return 0;
00149     }
00150 
00151 /*     Quick return if possible */
00152 
00153     if (*m == 0 || *n == 0) {
00154         *rowcnd = 1.f;
00155         *colcnd = 1.f;
00156         *amax = 0.f;
00157         return 0;
00158     }
00159 
00160 /*     Get machine constants. */
00161 
00162     smlnum = slamch_("S");
00163     bignum = 1.f / smlnum;
00164 
00165 /*     Compute row scale factors. */
00166 
00167     i__1 = *m;
00168     for (i__ = 1; i__ <= i__1; ++i__) {
00169         r__[i__] = 0.f;
00170 /* L10: */
00171     }
00172 
00173 /*     Find the maximum element in each row. */
00174 
00175     kd = *ku + 1;
00176     i__1 = *n;
00177     for (j = 1; j <= i__1; ++j) {
00178 /* Computing MAX */
00179         i__2 = j - *ku;
00180 /* Computing MIN */
00181         i__4 = j + *kl;
00182         i__3 = min(i__4,*m);
00183         for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
00184 /* Computing MAX */
00185             r__2 = r__[i__], r__3 = (r__1 = ab[kd + i__ - j + j * ab_dim1], 
00186                     dabs(r__1));
00187             r__[i__] = dmax(r__2,r__3);
00188 /* L20: */
00189         }
00190 /* L30: */
00191     }
00192 
00193 /*     Find the maximum and minimum scale factors. */
00194 
00195     rcmin = bignum;
00196     rcmax = 0.f;
00197     i__1 = *m;
00198     for (i__ = 1; i__ <= i__1; ++i__) {
00199 /* Computing MAX */
00200         r__1 = rcmax, r__2 = r__[i__];
00201         rcmax = dmax(r__1,r__2);
00202 /* Computing MIN */
00203         r__1 = rcmin, r__2 = r__[i__];
00204         rcmin = dmin(r__1,r__2);
00205 /* L40: */
00206     }
00207     *amax = rcmax;
00208 
00209     if (rcmin == 0.f) {
00210 
00211 /*        Find the first zero scale factor and return an error code. */
00212 
00213         i__1 = *m;
00214         for (i__ = 1; i__ <= i__1; ++i__) {
00215             if (r__[i__] == 0.f) {
00216                 *info = i__;
00217                 return 0;
00218             }
00219 /* L50: */
00220         }
00221     } else {
00222 
00223 /*        Invert the scale factors. */
00224 
00225         i__1 = *m;
00226         for (i__ = 1; i__ <= i__1; ++i__) {
00227 /* Computing MIN */
00228 /* Computing MAX */
00229             r__2 = r__[i__];
00230             r__1 = dmax(r__2,smlnum);
00231             r__[i__] = 1.f / dmin(r__1,bignum);
00232 /* L60: */
00233         }
00234 
00235 /*        Compute ROWCND = min(R(I)) / max(R(I)) */
00236 
00237         *rowcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum);
00238     }
00239 
00240 /*     Compute column scale factors */
00241 
00242     i__1 = *n;
00243     for (j = 1; j <= i__1; ++j) {
00244         c__[j] = 0.f;
00245 /* L70: */
00246     }
00247 
00248 /*     Find the maximum element in each column, */
00249 /*     assuming the row scaling computed above. */
00250 
00251     kd = *ku + 1;
00252     i__1 = *n;
00253     for (j = 1; j <= i__1; ++j) {
00254 /* Computing MAX */
00255         i__3 = j - *ku;
00256 /* Computing MIN */
00257         i__4 = j + *kl;
00258         i__2 = min(i__4,*m);
00259         for (i__ = max(i__3,1); i__ <= i__2; ++i__) {
00260 /* Computing MAX */
00261             r__2 = c__[j], r__3 = (r__1 = ab[kd + i__ - j + j * ab_dim1], 
00262                     dabs(r__1)) * r__[i__];
00263             c__[j] = dmax(r__2,r__3);
00264 /* L80: */
00265         }
00266 /* L90: */
00267     }
00268 
00269 /*     Find the maximum and minimum scale factors. */
00270 
00271     rcmin = bignum;
00272     rcmax = 0.f;
00273     i__1 = *n;
00274     for (j = 1; j <= i__1; ++j) {
00275 /* Computing MIN */
00276         r__1 = rcmin, r__2 = c__[j];
00277         rcmin = dmin(r__1,r__2);
00278 /* Computing MAX */
00279         r__1 = rcmax, r__2 = c__[j];
00280         rcmax = dmax(r__1,r__2);
00281 /* L100: */
00282     }
00283 
00284     if (rcmin == 0.f) {
00285 
00286 /*        Find the first zero scale factor and return an error code. */
00287 
00288         i__1 = *n;
00289         for (j = 1; j <= i__1; ++j) {
00290             if (c__[j] == 0.f) {
00291                 *info = *m + j;
00292                 return 0;
00293             }
00294 /* L110: */
00295         }
00296     } else {
00297 
00298 /*        Invert the scale factors. */
00299 
00300         i__1 = *n;
00301         for (j = 1; j <= i__1; ++j) {
00302 /* Computing MIN */
00303 /* Computing MAX */
00304             r__2 = c__[j];
00305             r__1 = dmax(r__2,smlnum);
00306             c__[j] = 1.f / dmin(r__1,bignum);
00307 /* L120: */
00308         }
00309 
00310 /*        Compute COLCND = min(C(J)) / max(C(J)) */
00311 
00312         *colcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum);
00313     }
00314 
00315     return 0;
00316 
00317 /*     End of SGBEQU */
00318 
00319 } /* sgbequ_ */


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