zlarnv.c
Go to the documentation of this file.
00001 /* zlarnv.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 zlarnv_(integer *idist, integer *iseed, integer *n, 
00017         doublecomplex *x)
00018 {
00019     /* System generated locals */
00020     integer i__1, i__2, i__3, i__4, i__5;
00021     doublereal d__1, d__2;
00022     doublecomplex z__1, z__2, z__3;
00023 
00024     /* Builtin functions */
00025     double log(doublereal), sqrt(doublereal);
00026     void z_exp(doublecomplex *, doublecomplex *);
00027 
00028     /* Local variables */
00029     integer i__;
00030     doublereal u[128];
00031     integer il, iv;
00032     extern /* Subroutine */ int dlaruv_(integer *, integer *, doublereal *);
00033 
00034 
00035 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00036 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00037 /*     November 2006 */
00038 
00039 /*     .. Scalar Arguments .. */
00040 /*     .. */
00041 /*     .. Array Arguments .. */
00042 /*     .. */
00043 
00044 /*  Purpose */
00045 /*  ======= */
00046 
00047 /*  ZLARNV returns a vector of n random complex numbers from a uniform or */
00048 /*  normal distribution. */
00049 
00050 /*  Arguments */
00051 /*  ========= */
00052 
00053 /*  IDIST   (input) INTEGER */
00054 /*          Specifies the distribution of the random numbers: */
00055 /*          = 1:  real and imaginary parts each uniform (0,1) */
00056 /*          = 2:  real and imaginary parts each uniform (-1,1) */
00057 /*          = 3:  real and imaginary parts each normal (0,1) */
00058 /*          = 4:  uniformly distributed on the disc abs(z) < 1 */
00059 /*          = 5:  uniformly distributed on the circle abs(z) = 1 */
00060 
00061 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00062 /*          On entry, the seed of the random number generator; the array */
00063 /*          elements must be between 0 and 4095, and ISEED(4) must be */
00064 /*          odd. */
00065 /*          On exit, the seed is updated. */
00066 
00067 /*  N       (input) INTEGER */
00068 /*          The number of random numbers to be generated. */
00069 
00070 /*  X       (output) COMPLEX*16 array, dimension (N) */
00071 /*          The generated random numbers. */
00072 
00073 /*  Further Details */
00074 /*  =============== */
00075 
00076 /*  This routine calls the auxiliary routine DLARUV to generate random */
00077 /*  real numbers from a uniform (0,1) distribution, in batches of up to */
00078 /*  128 using vectorisable code. The Box-Muller method is used to */
00079 /*  transform numbers from a uniform to a normal distribution. */
00080 
00081 /*  ===================================================================== */
00082 
00083 /*     .. Parameters .. */
00084 /*     .. */
00085 /*     .. Local Scalars .. */
00086 /*     .. */
00087 /*     .. Local Arrays .. */
00088 /*     .. */
00089 /*     .. Intrinsic Functions .. */
00090 /*     .. */
00091 /*     .. External Subroutines .. */
00092 /*     .. */
00093 /*     .. Executable Statements .. */
00094 
00095     /* Parameter adjustments */
00096     --x;
00097     --iseed;
00098 
00099     /* Function Body */
00100     i__1 = *n;
00101     for (iv = 1; iv <= i__1; iv += 64) {
00102 /* Computing MIN */
00103         i__2 = 64, i__3 = *n - iv + 1;
00104         il = min(i__2,i__3);
00105 
00106 /*        Call DLARUV to generate 2*IL real numbers from a uniform (0,1) */
00107 /*        distribution (2*IL <= LV) */
00108 
00109         i__2 = il << 1;
00110         dlaruv_(&iseed[1], &i__2, u);
00111 
00112         if (*idist == 1) {
00113 
00114 /*           Copy generated numbers */
00115 
00116             i__2 = il;
00117             for (i__ = 1; i__ <= i__2; ++i__) {
00118                 i__3 = iv + i__ - 1;
00119                 i__4 = (i__ << 1) - 2;
00120                 i__5 = (i__ << 1) - 1;
00121                 z__1.r = u[i__4], z__1.i = u[i__5];
00122                 x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00123 /* L10: */
00124             }
00125         } else if (*idist == 2) {
00126 
00127 /*           Convert generated numbers to uniform (-1,1) distribution */
00128 
00129             i__2 = il;
00130             for (i__ = 1; i__ <= i__2; ++i__) {
00131                 i__3 = iv + i__ - 1;
00132                 d__1 = u[(i__ << 1) - 2] * 2. - 1.;
00133                 d__2 = u[(i__ << 1) - 1] * 2. - 1.;
00134                 z__1.r = d__1, z__1.i = d__2;
00135                 x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00136 /* L20: */
00137             }
00138         } else if (*idist == 3) {
00139 
00140 /*           Convert generated numbers to normal (0,1) distribution */
00141 
00142             i__2 = il;
00143             for (i__ = 1; i__ <= i__2; ++i__) {
00144                 i__3 = iv + i__ - 1;
00145                 d__1 = sqrt(log(u[(i__ << 1) - 2]) * -2.);
00146                 d__2 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663;
00147                 z__3.r = 0., z__3.i = d__2;
00148                 z_exp(&z__2, &z__3);
00149                 z__1.r = d__1 * z__2.r, z__1.i = d__1 * z__2.i;
00150                 x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00151 /* L30: */
00152             }
00153         } else if (*idist == 4) {
00154 
00155 /*           Convert generated numbers to complex numbers uniformly */
00156 /*           distributed on the unit disk */
00157 
00158             i__2 = il;
00159             for (i__ = 1; i__ <= i__2; ++i__) {
00160                 i__3 = iv + i__ - 1;
00161                 d__1 = sqrt(u[(i__ << 1) - 2]);
00162                 d__2 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663;
00163                 z__3.r = 0., z__3.i = d__2;
00164                 z_exp(&z__2, &z__3);
00165                 z__1.r = d__1 * z__2.r, z__1.i = d__1 * z__2.i;
00166                 x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00167 /* L40: */
00168             }
00169         } else if (*idist == 5) {
00170 
00171 /*           Convert generated numbers to complex numbers uniformly */
00172 /*           distributed on the unit circle */
00173 
00174             i__2 = il;
00175             for (i__ = 1; i__ <= i__2; ++i__) {
00176                 i__3 = iv + i__ - 1;
00177                 d__1 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663;
00178                 z__2.r = 0., z__2.i = d__1;
00179                 z_exp(&z__1, &z__2);
00180                 x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00181 /* L50: */
00182             }
00183         }
00184 /* L60: */
00185     }
00186     return 0;
00187 
00188 /*     End of ZLARNV */
00189 
00190 } /* zlarnv_ */


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