00001 /* slarfg.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 slarfg_(integer *n, real *alpha, real *x, integer *incx, 00017 real *tau) 00018 { 00019 /* System generated locals */ 00020 integer i__1; 00021 real r__1; 00022 00023 /* Builtin functions */ 00024 double r_sign(real *, real *); 00025 00026 /* Local variables */ 00027 integer j, knt; 00028 real beta; 00029 extern doublereal snrm2_(integer *, real *, integer *); 00030 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); 00031 real xnorm; 00032 extern doublereal slapy2_(real *, real *), slamch_(char *); 00033 real safmin, rsafmn; 00034 00035 00036 /* -- LAPACK auxiliary routine (version 3.2) -- */ 00037 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00038 /* November 2006 */ 00039 00040 /* .. Scalar Arguments .. */ 00041 /* .. */ 00042 /* .. Array Arguments .. */ 00043 /* .. */ 00044 00045 /* Purpose */ 00046 /* ======= */ 00047 00048 /* SLARFG generates a real elementary reflector H of order n, such */ 00049 /* that */ 00050 00051 /* H * ( alpha ) = ( beta ), H' * H = I. */ 00052 /* ( x ) ( 0 ) */ 00053 00054 /* where alpha and beta are scalars, and x is an (n-1)-element real */ 00055 /* vector. H is represented in the form */ 00056 00057 /* H = I - tau * ( 1 ) * ( 1 v' ) , */ 00058 /* ( v ) */ 00059 00060 /* where tau is a real scalar and v is a real (n-1)-element */ 00061 /* vector. */ 00062 00063 /* If the elements of x are all zero, then tau = 0 and H is taken to be */ 00064 /* the unit matrix. */ 00065 00066 /* Otherwise 1 <= tau <= 2. */ 00067 00068 /* Arguments */ 00069 /* ========= */ 00070 00071 /* N (input) INTEGER */ 00072 /* The order of the elementary reflector. */ 00073 00074 /* ALPHA (input/output) REAL */ 00075 /* On entry, the value alpha. */ 00076 /* On exit, it is overwritten with the value beta. */ 00077 00078 /* X (input/output) REAL array, dimension */ 00079 /* (1+(N-2)*abs(INCX)) */ 00080 /* On entry, the vector x. */ 00081 /* On exit, it is overwritten with the vector v. */ 00082 00083 /* INCX (input) INTEGER */ 00084 /* The increment between elements of X. INCX > 0. */ 00085 00086 /* TAU (output) REAL */ 00087 /* The value tau. */ 00088 00089 /* ===================================================================== */ 00090 00091 /* .. Parameters .. */ 00092 /* .. */ 00093 /* .. Local Scalars .. */ 00094 /* .. */ 00095 /* .. External Functions .. */ 00096 /* .. */ 00097 /* .. Intrinsic Functions .. */ 00098 /* .. */ 00099 /* .. External Subroutines .. */ 00100 /* .. */ 00101 /* .. Executable Statements .. */ 00102 00103 /* Parameter adjustments */ 00104 --x; 00105 00106 /* Function Body */ 00107 if (*n <= 1) { 00108 *tau = 0.f; 00109 return 0; 00110 } 00111 00112 i__1 = *n - 1; 00113 xnorm = snrm2_(&i__1, &x[1], incx); 00114 00115 if (xnorm == 0.f) { 00116 00117 /* H = I */ 00118 00119 *tau = 0.f; 00120 } else { 00121 00122 /* general case */ 00123 00124 r__1 = slapy2_(alpha, &xnorm); 00125 beta = -r_sign(&r__1, alpha); 00126 safmin = slamch_("S") / slamch_("E"); 00127 knt = 0; 00128 if (dabs(beta) < safmin) { 00129 00130 /* XNORM, BETA may be inaccurate; scale X and recompute them */ 00131 00132 rsafmn = 1.f / safmin; 00133 L10: 00134 ++knt; 00135 i__1 = *n - 1; 00136 sscal_(&i__1, &rsafmn, &x[1], incx); 00137 beta *= rsafmn; 00138 *alpha *= rsafmn; 00139 if (dabs(beta) < safmin) { 00140 goto L10; 00141 } 00142 00143 /* New BETA is at most 1, at least SAFMIN */ 00144 00145 i__1 = *n - 1; 00146 xnorm = snrm2_(&i__1, &x[1], incx); 00147 r__1 = slapy2_(alpha, &xnorm); 00148 beta = -r_sign(&r__1, alpha); 00149 } 00150 *tau = (beta - *alpha) / beta; 00151 i__1 = *n - 1; 00152 r__1 = 1.f / (*alpha - beta); 00153 sscal_(&i__1, &r__1, &x[1], incx); 00154 00155 /* If ALPHA is subnormal, it may lose relative accuracy */ 00156 00157 i__1 = knt; 00158 for (j = 1; j <= i__1; ++j) { 00159 beta *= safmin; 00160 /* L20: */ 00161 } 00162 *alpha = beta; 00163 } 00164 00165 return 0; 00166 00167 /* End of SLARFG */ 00168 00169 } /* slarfg_ */