clarnd.c
Go to the documentation of this file.
00001 /* clarnd.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 /* Complex */ VOID clarnd_(complex * ret_val, integer *idist, integer *iseed)
00017 {
00018     /* System generated locals */
00019     real r__1, r__2;
00020     complex q__1, q__2, q__3;
00021 
00022     /* Builtin functions */
00023     double log(doublereal), sqrt(doublereal);
00024     void c_exp(complex *, complex *);
00025 
00026     /* Local variables */
00027     real t1, t2;
00028     extern doublereal slaran_(integer *);
00029 
00030 
00031 /*  -- LAPACK auxiliary routine (version 3.1) -- */
00032 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00033 /*     November 2006 */
00034 
00035 /*     .. Scalar Arguments .. */
00036 /*     .. */
00037 /*     .. Array Arguments .. */
00038 /*     .. */
00039 
00040 /*  Purpose */
00041 /*  ======= */
00042 
00043 /*  CLARND returns a random complex number from a uniform or normal */
00044 /*  distribution. */
00045 
00046 /*  Arguments */
00047 /*  ========= */
00048 
00049 /*  IDIST   (input) INTEGER */
00050 /*          Specifies the distribution of the random numbers: */
00051 /*          = 1:  real and imaginary parts each uniform (0,1) */
00052 /*          = 2:  real and imaginary parts each uniform (-1,1) */
00053 /*          = 3:  real and imaginary parts each normal (0,1) */
00054 /*          = 4:  uniformly distributed on the disc abs(z) <= 1 */
00055 /*          = 5:  uniformly distributed on the circle abs(z) = 1 */
00056 
00057 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00058 /*          On entry, the seed of the random number generator; the array */
00059 /*          elements must be between 0 and 4095, and ISEED(4) must be */
00060 /*          odd. */
00061 /*          On exit, the seed is updated. */
00062 
00063 /*  Further Details */
00064 /*  =============== */
00065 
00066 /*  This routine calls the auxiliary routine SLARAN to generate a random */
00067 /*  real number from a uniform (0,1) distribution. The Box-Muller method */
00068 /*  is used to transform numbers from a uniform to a normal distribution. */
00069 
00070 /*  ===================================================================== */
00071 
00072 /*     .. Parameters .. */
00073 /*     .. */
00074 /*     .. Local Scalars .. */
00075 /*     .. */
00076 /*     .. External Functions .. */
00077 /*     .. */
00078 /*     .. Intrinsic Functions .. */
00079 /*     .. */
00080 /*     .. Executable Statements .. */
00081 
00082 /*     Generate a pair of real random numbers from a uniform (0,1) */
00083 /*     distribution */
00084 
00085     /* Parameter adjustments */
00086     --iseed;
00087 
00088     /* Function Body */
00089     t1 = slaran_(&iseed[1]);
00090     t2 = slaran_(&iseed[1]);
00091 
00092     if (*idist == 1) {
00093 
00094 /*        real and imaginary parts each uniform (0,1) */
00095 
00096         q__1.r = t1, q__1.i = t2;
00097          ret_val->r = q__1.r,  ret_val->i = q__1.i;
00098     } else if (*idist == 2) {
00099 
00100 /*        real and imaginary parts each uniform (-1,1) */
00101 
00102         r__1 = t1 * 2.f - 1.f;
00103         r__2 = t2 * 2.f - 1.f;
00104         q__1.r = r__1, q__1.i = r__2;
00105          ret_val->r = q__1.r,  ret_val->i = q__1.i;
00106     } else if (*idist == 3) {
00107 
00108 /*        real and imaginary parts each normal (0,1) */
00109 
00110         r__1 = sqrt(log(t1) * -2.f);
00111         r__2 = t2 * 6.2831853071795864769252867663f;
00112         q__3.r = 0.f, q__3.i = r__2;
00113         c_exp(&q__2, &q__3);
00114         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00115          ret_val->r = q__1.r,  ret_val->i = q__1.i;
00116     } else if (*idist == 4) {
00117 
00118 /*        uniform distribution on the unit disc abs(z) <= 1 */
00119 
00120         r__1 = sqrt(t1);
00121         r__2 = t2 * 6.2831853071795864769252867663f;
00122         q__3.r = 0.f, q__3.i = r__2;
00123         c_exp(&q__2, &q__3);
00124         q__1.r = r__1 * q__2.r, q__1.i = r__1 * q__2.i;
00125          ret_val->r = q__1.r,  ret_val->i = q__1.i;
00126     } else if (*idist == 5) {
00127 
00128 /*        uniform distribution on the unit circle abs(z) = 1 */
00129 
00130         r__1 = t2 * 6.2831853071795864769252867663f;
00131         q__2.r = 0.f, q__2.i = r__1;
00132         c_exp(&q__1, &q__2);
00133          ret_val->r = q__1.r,  ret_val->i = q__1.i;
00134     }
00135     return ;
00136 
00137 /*     End of CLARND */
00138 
00139 } /* clarnd_ */


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