clarnv.c
Go to the documentation of this file.
00001 /* clarnv.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 clarnv_(integer *idist, integer *iseed, integer *n, 
00017         complex *x)
00018 {
00019     /* System generated locals */
00020     integer i__1, i__2, i__3, i__4, i__5;
00021     real r__1, r__2;
00022     complex q__1, q__2, q__3;
00023 
00024     /* Builtin functions */
00025     double log(doublereal), sqrt(doublereal);
00026     void c_exp(complex *, complex *);
00027 
00028     /* Local variables */
00029     integer i__;
00030     real u[128];
00031     integer il, iv;
00032     extern /* Subroutine */ int slaruv_(integer *, integer *, real *);
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 /*  CLARNV 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 array, dimension (N) */
00071 /*          The generated random numbers. */
00072 
00073 /*  Further Details */
00074 /*  =============== */
00075 
00076 /*  This routine calls the auxiliary routine SLARUV 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 SLARUV to generate 2*IL real numbers from a uniform (0,1) */
00107 /*        distribution (2*IL <= LV) */
00108 
00109         i__2 = il << 1;
00110         slaruv_(&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                 q__1.r = u[i__4], q__1.i = u[i__5];
00122                 x[i__3].r = q__1.r, x[i__3].i = q__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                 r__1 = u[(i__ << 1) - 2] * 2.f - 1.f;
00133                 r__2 = u[(i__ << 1) - 1] * 2.f - 1.f;
00134                 q__1.r = r__1, q__1.i = r__2;
00135                 x[i__3].r = q__1.r, x[i__3].i = q__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                 r__1 = sqrt(log(u[(i__ << 1) - 2]) * -2.f);
00146                 r__2 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663f;
00147                 q__3.r = 0.f, q__3.i = r__2;
00148                 c_exp(&q__2, &q__3);
00149                 q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00150                 x[i__3].r = q__1.r, x[i__3].i = q__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                 r__1 = sqrt(u[(i__ << 1) - 2]);
00162                 r__2 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663f;
00163                 q__3.r = 0.f, q__3.i = r__2;
00164                 c_exp(&q__2, &q__3);
00165                 q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00166                 x[i__3].r = q__1.r, x[i__3].i = q__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                 r__1 = u[(i__ << 1) - 1] * 6.2831853071795864769252867663f;
00178                 q__2.r = 0.f, q__2.i = r__1;
00179                 c_exp(&q__1, &q__2);
00180                 x[i__3].r = q__1.r, x[i__3].i = q__1.i;
00181 /* L50: */
00182             }
00183         }
00184 /* L60: */
00185     }
00186     return 0;
00187 
00188 /*     End of CLARNV */
00189 
00190 } /* clarnv_ */


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