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


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