zlargv.c
Go to the documentation of this file.
00001 /* zlargv.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 zlargv_(integer *n, doublecomplex *x, integer *incx, 
00017         doublecomplex *y, integer *incy, doublereal *c__, integer *incc)
00018 {
00019     /* System generated locals */
00020     integer i__1, i__2;
00021     doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10;
00022     doublecomplex z__1, z__2, z__3;
00023 
00024     /* Builtin functions */
00025     double log(doublereal), pow_di(doublereal *, integer *), d_imag(
00026             doublecomplex *), sqrt(doublereal);
00027     void d_cnjg(doublecomplex *, doublecomplex *);
00028 
00029     /* Local variables */
00030     doublereal d__;
00031     doublecomplex f, g;
00032     integer i__, j;
00033     doublecomplex r__;
00034     doublereal f2, g2;
00035     integer ic;
00036     doublereal di;
00037     doublecomplex ff;
00038     doublereal cs, dr;
00039     doublecomplex fs, gs;
00040     integer ix, iy;
00041     doublecomplex sn;
00042     doublereal f2s, g2s, eps, scale;
00043     integer count;
00044     doublereal safmn2;
00045     extern doublereal dlapy2_(doublereal *, doublereal *);
00046     doublereal safmx2;
00047     extern doublereal dlamch_(char *);
00048     doublereal safmin;
00049 
00050 
00051 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00052 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00053 /*     November 2006 */
00054 
00055 /*     .. Scalar Arguments .. */
00056 /*     .. */
00057 /*     .. Array Arguments .. */
00058 /*     .. */
00059 
00060 /*  Purpose */
00061 /*  ======= */
00062 
00063 /*  ZLARGV generates a vector of complex plane rotations with real */
00064 /*  cosines, determined by elements of the complex vectors x and y. */
00065 /*  For i = 1,2,...,n */
00066 
00067 /*     (        c(i)   s(i) ) ( x(i) ) = ( r(i) ) */
00068 /*     ( -conjg(s(i))  c(i) ) ( y(i) ) = (   0  ) */
00069 
00070 /*     where c(i)**2 + ABS(s(i))**2 = 1 */
00071 
00072 /*  The following conventions are used (these are the same as in ZLARTG, */
00073 /*  but differ from the BLAS1 routine ZROTG): */
00074 /*     If y(i)=0, then c(i)=1 and s(i)=0. */
00075 /*     If x(i)=0, then c(i)=0 and s(i) is chosen so that r(i) is real. */
00076 
00077 /*  Arguments */
00078 /*  ========= */
00079 
00080 /*  N       (input) INTEGER */
00081 /*          The number of plane rotations to be generated. */
00082 
00083 /*  X       (input/output) COMPLEX*16 array, dimension (1+(N-1)*INCX) */
00084 /*          On entry, the vector x. */
00085 /*          On exit, x(i) is overwritten by r(i), for i = 1,...,n. */
00086 
00087 /*  INCX    (input) INTEGER */
00088 /*          The increment between elements of X. INCX > 0. */
00089 
00090 /*  Y       (input/output) COMPLEX*16 array, dimension (1+(N-1)*INCY) */
00091 /*          On entry, the vector y. */
00092 /*          On exit, the sines of the plane rotations. */
00093 
00094 /*  INCY    (input) INTEGER */
00095 /*          The increment between elements of Y. INCY > 0. */
00096 
00097 /*  C       (output) DOUBLE PRECISION array, dimension (1+(N-1)*INCC) */
00098 /*          The cosines of the plane rotations. */
00099 
00100 /*  INCC    (input) INTEGER */
00101 /*          The increment between elements of C. INCC > 0. */
00102 
00103 /*  Further Details */
00104 /*  ======= ======= */
00105 
00106 /*  6-6-96 - Modified with a new algorithm by W. Kahan and J. Demmel */
00107 
00108 /*  This version has a few statements commented out for thread safety */
00109 /*  (machine parameters are computed on each entry). 10 feb 03, SJH. */
00110 
00111 /*  ===================================================================== */
00112 
00113 /*     .. Parameters .. */
00114 /*     .. */
00115 /*     .. Local Scalars .. */
00116 /*     LOGICAL            FIRST */
00117 /*     .. */
00118 /*     .. External Functions .. */
00119 /*     .. */
00120 /*     .. Intrinsic Functions .. */
00121 /*     .. */
00122 /*     .. Statement Functions .. */
00123 /*     .. */
00124 /*     .. Save statement .. */
00125 /*     SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2 */
00126 /*     .. */
00127 /*     .. Data statements .. */
00128 /*     DATA               FIRST / .TRUE. / */
00129 /*     .. */
00130 /*     .. Statement Function definitions .. */
00131 /*     .. */
00132 /*     .. Executable Statements .. */
00133 
00134 /*     IF( FIRST ) THEN */
00135 /*        FIRST = .FALSE. */
00136     /* Parameter adjustments */
00137     --c__;
00138     --y;
00139     --x;
00140 
00141     /* Function Body */
00142     safmin = dlamch_("S");
00143     eps = dlamch_("E");
00144     d__1 = dlamch_("B");
00145     i__1 = (integer) (log(safmin / eps) / log(dlamch_("B")) / 2.);
00146     safmn2 = pow_di(&d__1, &i__1);
00147     safmx2 = 1. / safmn2;
00148 /*     END IF */
00149     ix = 1;
00150     iy = 1;
00151     ic = 1;
00152     i__1 = *n;
00153     for (i__ = 1; i__ <= i__1; ++i__) {
00154         i__2 = ix;
00155         f.r = x[i__2].r, f.i = x[i__2].i;
00156         i__2 = iy;
00157         g.r = y[i__2].r, g.i = y[i__2].i;
00158 
00159 /*        Use identical algorithm as in ZLARTG */
00160 
00161 /* Computing MAX */
00162 /* Computing MAX */
00163         d__7 = (d__1 = f.r, abs(d__1)), d__8 = (d__2 = d_imag(&f), abs(d__2));
00164 /* Computing MAX */
00165         d__9 = (d__3 = g.r, abs(d__3)), d__10 = (d__4 = d_imag(&g), abs(d__4))
00166                 ;
00167         d__5 = max(d__7,d__8), d__6 = max(d__9,d__10);
00168         scale = max(d__5,d__6);
00169         fs.r = f.r, fs.i = f.i;
00170         gs.r = g.r, gs.i = g.i;
00171         count = 0;
00172         if (scale >= safmx2) {
00173 L10:
00174             ++count;
00175             z__1.r = safmn2 * fs.r, z__1.i = safmn2 * fs.i;
00176             fs.r = z__1.r, fs.i = z__1.i;
00177             z__1.r = safmn2 * gs.r, z__1.i = safmn2 * gs.i;
00178             gs.r = z__1.r, gs.i = z__1.i;
00179             scale *= safmn2;
00180             if (scale >= safmx2) {
00181                 goto L10;
00182             }
00183         } else if (scale <= safmn2) {
00184             if (g.r == 0. && g.i == 0.) {
00185                 cs = 1.;
00186                 sn.r = 0., sn.i = 0.;
00187                 r__.r = f.r, r__.i = f.i;
00188                 goto L50;
00189             }
00190 L20:
00191             --count;
00192             z__1.r = safmx2 * fs.r, z__1.i = safmx2 * fs.i;
00193             fs.r = z__1.r, fs.i = z__1.i;
00194             z__1.r = safmx2 * gs.r, z__1.i = safmx2 * gs.i;
00195             gs.r = z__1.r, gs.i = z__1.i;
00196             scale *= safmx2;
00197             if (scale <= safmn2) {
00198                 goto L20;
00199             }
00200         }
00201 /* Computing 2nd power */
00202         d__1 = fs.r;
00203 /* Computing 2nd power */
00204         d__2 = d_imag(&fs);
00205         f2 = d__1 * d__1 + d__2 * d__2;
00206 /* Computing 2nd power */
00207         d__1 = gs.r;
00208 /* Computing 2nd power */
00209         d__2 = d_imag(&gs);
00210         g2 = d__1 * d__1 + d__2 * d__2;
00211         if (f2 <= max(g2,1.) * safmin) {
00212 
00213 /*           This is a rare case: F is very small. */
00214 
00215             if (f.r == 0. && f.i == 0.) {
00216                 cs = 0.;
00217                 d__2 = g.r;
00218                 d__3 = d_imag(&g);
00219                 d__1 = dlapy2_(&d__2, &d__3);
00220                 r__.r = d__1, r__.i = 0.;
00221 /*              Do complex/real division explicitly with two real */
00222 /*              divisions */
00223                 d__1 = gs.r;
00224                 d__2 = d_imag(&gs);
00225                 d__ = dlapy2_(&d__1, &d__2);
00226                 d__1 = gs.r / d__;
00227                 d__2 = -d_imag(&gs) / d__;
00228                 z__1.r = d__1, z__1.i = d__2;
00229                 sn.r = z__1.r, sn.i = z__1.i;
00230                 goto L50;
00231             }
00232             d__1 = fs.r;
00233             d__2 = d_imag(&fs);
00234             f2s = dlapy2_(&d__1, &d__2);
00235 /*           G2 and G2S are accurate */
00236 /*           G2 is at least SAFMIN, and G2S is at least SAFMN2 */
00237             g2s = sqrt(g2);
00238 /*           Error in CS from underflow in F2S is at most */
00239 /*           UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS */
00240 /*           If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN, */
00241 /*           and so CS .lt. sqrt(SAFMIN) */
00242 /*           If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN */
00243 /*           and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS) */
00244 /*           Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S */
00245             cs = f2s / g2s;
00246 /*           Make sure abs(FF) = 1 */
00247 /*           Do complex/real division explicitly with 2 real divisions */
00248 /* Computing MAX */
00249             d__3 = (d__1 = f.r, abs(d__1)), d__4 = (d__2 = d_imag(&f), abs(
00250                     d__2));
00251             if (max(d__3,d__4) > 1.) {
00252                 d__1 = f.r;
00253                 d__2 = d_imag(&f);
00254                 d__ = dlapy2_(&d__1, &d__2);
00255                 d__1 = f.r / d__;
00256                 d__2 = d_imag(&f) / d__;
00257                 z__1.r = d__1, z__1.i = d__2;
00258                 ff.r = z__1.r, ff.i = z__1.i;
00259             } else {
00260                 dr = safmx2 * f.r;
00261                 di = safmx2 * d_imag(&f);
00262                 d__ = dlapy2_(&dr, &di);
00263                 d__1 = dr / d__;
00264                 d__2 = di / d__;
00265                 z__1.r = d__1, z__1.i = d__2;
00266                 ff.r = z__1.r, ff.i = z__1.i;
00267             }
00268             d__1 = gs.r / g2s;
00269             d__2 = -d_imag(&gs) / g2s;
00270             z__2.r = d__1, z__2.i = d__2;
00271             z__1.r = ff.r * z__2.r - ff.i * z__2.i, z__1.i = ff.r * z__2.i + 
00272                     ff.i * z__2.r;
00273             sn.r = z__1.r, sn.i = z__1.i;
00274             z__2.r = cs * f.r, z__2.i = cs * f.i;
00275             z__3.r = sn.r * g.r - sn.i * g.i, z__3.i = sn.r * g.i + sn.i * 
00276                     g.r;
00277             z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
00278             r__.r = z__1.r, r__.i = z__1.i;
00279         } else {
00280 
00281 /*           This is the most common case. */
00282 /*           Neither F2 nor F2/G2 are less than SAFMIN */
00283 /*           F2S cannot overflow, and it is accurate */
00284 
00285             f2s = sqrt(g2 / f2 + 1.);
00286 /*           Do the F2S(real)*FS(complex) multiply with two real */
00287 /*           multiplies */
00288             d__1 = f2s * fs.r;
00289             d__2 = f2s * d_imag(&fs);
00290             z__1.r = d__1, z__1.i = d__2;
00291             r__.r = z__1.r, r__.i = z__1.i;
00292             cs = 1. / f2s;
00293             d__ = f2 + g2;
00294 /*           Do complex/real division explicitly with two real divisions */
00295             d__1 = r__.r / d__;
00296             d__2 = d_imag(&r__) / d__;
00297             z__1.r = d__1, z__1.i = d__2;
00298             sn.r = z__1.r, sn.i = z__1.i;
00299             d_cnjg(&z__2, &gs);
00300             z__1.r = sn.r * z__2.r - sn.i * z__2.i, z__1.i = sn.r * z__2.i + 
00301                     sn.i * z__2.r;
00302             sn.r = z__1.r, sn.i = z__1.i;
00303             if (count != 0) {
00304                 if (count > 0) {
00305                     i__2 = count;
00306                     for (j = 1; j <= i__2; ++j) {
00307                         z__1.r = safmx2 * r__.r, z__1.i = safmx2 * r__.i;
00308                         r__.r = z__1.r, r__.i = z__1.i;
00309 /* L30: */
00310                     }
00311                 } else {
00312                     i__2 = -count;
00313                     for (j = 1; j <= i__2; ++j) {
00314                         z__1.r = safmn2 * r__.r, z__1.i = safmn2 * r__.i;
00315                         r__.r = z__1.r, r__.i = z__1.i;
00316 /* L40: */
00317                     }
00318                 }
00319             }
00320         }
00321 L50:
00322         c__[ic] = cs;
00323         i__2 = iy;
00324         y[i__2].r = sn.r, y[i__2].i = sn.i;
00325         i__2 = ix;
00326         x[i__2].r = r__.r, x[i__2].i = r__.i;
00327         ic += *incc;
00328         iy += *incy;
00329         ix += *incx;
00330 /* L60: */
00331     }
00332     return 0;
00333 
00334 /*     End of ZLARGV */
00335 
00336 } /* zlargv_ */


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