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