clarfg.c
Go to the documentation of this file.
00001 /* clarfg.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 complex c_b5 = {1.f,0.f};
00019 
00020 /* Subroutine */ int clarfg_(integer *n, complex *alpha, complex *x, integer *
00021         incx, complex *tau)
00022 {
00023     /* System generated locals */
00024     integer i__1;
00025     real r__1, r__2;
00026     complex q__1, q__2;
00027 
00028     /* Builtin functions */
00029     double r_imag(complex *), r_sign(real *, real *);
00030 
00031     /* Local variables */
00032     integer j, knt;
00033     real beta;
00034     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00035             integer *);
00036     real alphi, alphr, xnorm;
00037     extern doublereal scnrm2_(integer *, complex *, integer *), slapy3_(real *
00038 , real *, real *);
00039     extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
00040     extern doublereal slamch_(char *);
00041     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00042             *);
00043     real safmin, rsafmn;
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 /*  CLARFG generates a complex elementary reflector H of order n, such */
00059 /*  that */
00060 
00061 /*        H' * ( alpha ) = ( beta ),   H' * H = I. */
00062 /*             (   x   )   (   0  ) */
00063 
00064 /*  where alpha and beta are scalars, with beta real, and x is an */
00065 /*  (n-1)-element complex vector. H is represented in the form */
00066 
00067 /*        H = I - tau * ( 1 ) * ( 1 v' ) , */
00068 /*                      ( v ) */
00069 
00070 /*  where tau is a complex scalar and v is a complex (n-1)-element */
00071 /*  vector. Note that H is not hermitian. */
00072 
00073 /*  If the elements of x are all zero and alpha is real, then tau = 0 */
00074 /*  and H is taken to be the unit matrix. */
00075 
00076 /*  Otherwise  1 <= real(tau) <= 2  and  abs(tau-1) <= 1 . */
00077 
00078 /*  Arguments */
00079 /*  ========= */
00080 
00081 /*  N       (input) INTEGER */
00082 /*          The order of the elementary reflector. */
00083 
00084 /*  ALPHA   (input/output) COMPLEX */
00085 /*          On entry, the value alpha. */
00086 /*          On exit, it is overwritten with the value beta. */
00087 
00088 /*  X       (input/output) COMPLEX array, dimension */
00089 /*                         (1+(N-2)*abs(INCX)) */
00090 /*          On entry, the vector x. */
00091 /*          On exit, it is overwritten with the vector v. */
00092 
00093 /*  INCX    (input) INTEGER */
00094 /*          The increment between elements of X. INCX > 0. */
00095 
00096 /*  TAU     (output) COMPLEX */
00097 /*          The value tau. */
00098 
00099 /*  ===================================================================== */
00100 
00101 /*     .. Parameters .. */
00102 /*     .. */
00103 /*     .. Local Scalars .. */
00104 /*     .. */
00105 /*     .. External Functions .. */
00106 /*     .. */
00107 /*     .. Intrinsic Functions .. */
00108 /*     .. */
00109 /*     .. External Subroutines .. */
00110 /*     .. */
00111 /*     .. Executable Statements .. */
00112 
00113     /* Parameter adjustments */
00114     --x;
00115 
00116     /* Function Body */
00117     if (*n <= 0) {
00118         tau->r = 0.f, tau->i = 0.f;
00119         return 0;
00120     }
00121 
00122     i__1 = *n - 1;
00123     xnorm = scnrm2_(&i__1, &x[1], incx);
00124     alphr = alpha->r;
00125     alphi = r_imag(alpha);
00126 
00127     if (xnorm == 0.f && alphi == 0.f) {
00128 
00129 /*        H  =  I */
00130 
00131         tau->r = 0.f, tau->i = 0.f;
00132     } else {
00133 
00134 /*        general case */
00135 
00136         r__1 = slapy3_(&alphr, &alphi, &xnorm);
00137         beta = -r_sign(&r__1, &alphr);
00138         safmin = slamch_("S") / slamch_("E");
00139         rsafmn = 1.f / safmin;
00140 
00141         knt = 0;
00142         if (dabs(beta) < safmin) {
00143 
00144 /*           XNORM, BETA may be inaccurate; scale X and recompute them */
00145 
00146 L10:
00147             ++knt;
00148             i__1 = *n - 1;
00149             csscal_(&i__1, &rsafmn, &x[1], incx);
00150             beta *= rsafmn;
00151             alphi *= rsafmn;
00152             alphr *= rsafmn;
00153             if (dabs(beta) < safmin) {
00154                 goto L10;
00155             }
00156 
00157 /*           New BETA is at most 1, at least SAFMIN */
00158 
00159             i__1 = *n - 1;
00160             xnorm = scnrm2_(&i__1, &x[1], incx);
00161             q__1.r = alphr, q__1.i = alphi;
00162             alpha->r = q__1.r, alpha->i = q__1.i;
00163             r__1 = slapy3_(&alphr, &alphi, &xnorm);
00164             beta = -r_sign(&r__1, &alphr);
00165         }
00166         r__1 = (beta - alphr) / beta;
00167         r__2 = -alphi / beta;
00168         q__1.r = r__1, q__1.i = r__2;
00169         tau->r = q__1.r, tau->i = q__1.i;
00170         q__2.r = alpha->r - beta, q__2.i = alpha->i;
00171         cladiv_(&q__1, &c_b5, &q__2);
00172         alpha->r = q__1.r, alpha->i = q__1.i;
00173         i__1 = *n - 1;
00174         cscal_(&i__1, alpha, &x[1], incx);
00175 
00176 /*        If ALPHA is subnormal, it may lose relative accuracy */
00177 
00178         i__1 = knt;
00179         for (j = 1; j <= i__1; ++j) {
00180             beta *= safmin;
00181 /* L20: */
00182         }
00183         alpha->r = beta, alpha->i = 0.f;
00184     }
00185 
00186     return 0;
00187 
00188 /*     End of CLARFG */
00189 
00190 } /* clarfg_ */


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