kusano 7d535a
#include "f2c.h"
kusano 7d535a
kusano 7d535a
/* Subroutine */ int dlarnv_(integer *idist, integer *iseed, integer *n, 
kusano 7d535a
	doublereal *x)
kusano 7d535a
{
kusano 7d535a
/*  -- LAPACK auxiliary routine (version 2.0) --   
kusano 7d535a
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
kusano 7d535a
       Courant Institute, Argonne National Lab, and Rice University   
kusano 7d535a
       September 30, 1994   
kusano 7d535a
kusano 7d535a
kusano 7d535a
    Purpose   
kusano 7d535a
    =======   
kusano 7d535a
kusano 7d535a
    DLARNV returns a vector of n random real numbers from a uniform or   
kusano 7d535a
    normal distribution.   
kusano 7d535a
kusano 7d535a
    Arguments   
kusano 7d535a
    =========   
kusano 7d535a
kusano 7d535a
    IDIST   (input) INTEGER   
kusano 7d535a
            Specifies the distribution of the random numbers:   
kusano 7d535a
            = 1:  uniform (0,1)   
kusano 7d535a
            = 2:  uniform (-1,1)   
kusano 7d535a
            = 3:  normal (0,1)   
kusano 7d535a
kusano 7d535a
    ISEED   (input/output) INTEGER array, dimension (4)   
kusano 7d535a
            On entry, the seed of the random number generator; the array 
kusano 7d535a
  
kusano 7d535a
            elements must be between 0 and 4095, and ISEED(4) must be   
kusano 7d535a
            odd.   
kusano 7d535a
            On exit, the seed is updated.   
kusano 7d535a
kusano 7d535a
    N       (input) INTEGER   
kusano 7d535a
            The number of random numbers to be generated.   
kusano 7d535a
kusano 7d535a
    X       (output) DOUBLE PRECISION array, dimension (N)   
kusano 7d535a
            The generated random numbers.   
kusano 7d535a
kusano 7d535a
    Further Details   
kusano 7d535a
    ===============   
kusano 7d535a
kusano 7d535a
    This routine calls the auxiliary routine DLARUV to generate random   
kusano 7d535a
    real numbers from a uniform (0,1) distribution, in batches of up to   
kusano 7d535a
    128 using vectorisable code. The Box-Muller method is used to   
kusano 7d535a
    transform numbers from a uniform to a normal distribution.   
kusano 7d535a
kusano 7d535a
    ===================================================================== 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
kusano 7d535a
    
kusano 7d535a
   Parameter adjustments   
kusano 7d535a
       Function Body */
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    integer i__1, i__2, i__3;
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double log(doublereal), sqrt(doublereal), cos(doublereal);
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static integer i;
kusano 7d535a
    static doublereal u[128];
kusano 7d535a
    static integer il, iv;
kusano 7d535a
    extern /* Subroutine */ int dlaruv_(integer *, integer *, doublereal *);
kusano 7d535a
    static integer il2;
kusano 7d535a
kusano 7d535a
kusano 7d535a
#define U(I) u[(I)]
kusano 7d535a
#define X(I) x[(I)-1]
kusano 7d535a
#define ISEED(I) iseed[(I)-1]
kusano 7d535a
kusano 7d535a
kusano 7d535a
    i__1 = *n;
kusano 7d535a
    for (iv = 1; iv <= *n; iv += 64) {
kusano 7d535a
/* Computing MIN */
kusano 7d535a
	i__2 = 64, i__3 = *n - iv + 1;
kusano 7d535a
	il = min(i__2,i__3);
kusano 7d535a
	if (*idist == 3) {
kusano 7d535a
	    il2 = il << 1;
kusano 7d535a
	} else {
kusano 7d535a
	    il2 = il;
kusano 7d535a
	}
kusano 7d535a
kusano 7d535a
/*        Call DLARUV to generate IL2 numbers from a uniform (0,1)   
kusano 7d535a
          distribution (IL2 <= LV) */
kusano 7d535a
kusano 7d535a
	dlaruv_(&ISEED(1), &il2, u);
kusano 7d535a
kusano 7d535a
	if (*idist == 1) {
kusano 7d535a
kusano 7d535a
/*           Copy generated numbers */
kusano 7d535a
kusano 7d535a
	    i__2 = il;
kusano 7d535a
	    for (i = 1; i <= il; ++i) {
kusano 7d535a
		X(iv + i - 1) = U(i - 1);
kusano 7d535a
/* L10: */
kusano 7d535a
	    }
kusano 7d535a
	} else if (*idist == 2) {
kusano 7d535a
kusano 7d535a
/*           Convert generated numbers to uniform (-1,1) distribut
kusano 7d535a
ion */
kusano 7d535a
kusano 7d535a
	    i__2 = il;
kusano 7d535a
	    for (i = 1; i <= il; ++i) {
kusano 7d535a
		X(iv + i - 1) = U(i - 1) * 2. - 1.;
kusano 7d535a
/* L20: */
kusano 7d535a
	    }
kusano 7d535a
	} else if (*idist == 3) {
kusano 7d535a
kusano 7d535a
/*           Convert generated numbers to normal (0,1) distributio
kusano 7d535a
n */
kusano 7d535a
kusano 7d535a
	    i__2 = il;
kusano 7d535a
	    for (i = 1; i <= il; ++i) {
kusano 7d535a
		X(iv + i - 1) = sqrt(log(U((i << 1) - 2)) * -2.) * cos(U((i <<
kusano 7d535a
			 1) - 1) * 6.2831853071795864769252867663);
kusano 7d535a
/* L30: */
kusano 7d535a
	    }
kusano 7d535a
	}
kusano 7d535a
/* L40: */
kusano 7d535a
    }
kusano 7d535a
    return 0;
kusano 7d535a
kusano 7d535a
/*     End of DLARNV */
kusano 7d535a
kusano 7d535a
} /* dlarnv_ */
kusano 7d535a