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


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