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