LAPACK 3.3.1
Linear Algebra PACKage

clarnv.f

Go to the documentation of this file.
00001       SUBROUTINE CLARNV( IDIST, ISEED, N, X )
00002 *
00003 *  -- LAPACK auxiliary routine (version 3.2) --
00004 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00005 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       INTEGER            IDIST, N
00010 *     ..
00011 *     .. Array Arguments ..
00012       INTEGER            ISEED( 4 )
00013       COMPLEX            X( * )
00014 *     ..
00015 *
00016 *  Purpose
00017 *  =======
00018 *
00019 *  CLARNV returns a vector of n random complex numbers from a uniform or
00020 *  normal distribution.
00021 *
00022 *  Arguments
00023 *  =========
00024 *
00025 *  IDIST   (input) INTEGER
00026 *          Specifies the distribution of the random numbers:
00027 *          = 1:  real and imaginary parts each uniform (0,1)
00028 *          = 2:  real and imaginary parts each uniform (-1,1)
00029 *          = 3:  real and imaginary parts each normal (0,1)
00030 *          = 4:  uniformly distributed on the disc abs(z) < 1
00031 *          = 5:  uniformly distributed on the circle abs(z) = 1
00032 *
00033 *  ISEED   (input/output) INTEGER array, dimension (4)
00034 *          On entry, the seed of the random number generator; the array
00035 *          elements must be between 0 and 4095, and ISEED(4) must be
00036 *          odd.
00037 *          On exit, the seed is updated.
00038 *
00039 *  N       (input) INTEGER
00040 *          The number of random numbers to be generated.
00041 *
00042 *  X       (output) COMPLEX array, dimension (N)
00043 *          The generated random numbers.
00044 *
00045 *  Further Details
00046 *  ===============
00047 *
00048 *  This routine calls the auxiliary routine SLARUV to generate random
00049 *  real numbers from a uniform (0,1) distribution, in batches of up to
00050 *  128 using vectorisable code. The Box-Muller method is used to
00051 *  transform numbers from a uniform to a normal distribution.
00052 *
00053 *  =====================================================================
00054 *
00055 *     .. Parameters ..
00056       REAL               ZERO, ONE, TWO
00057       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
00058       INTEGER            LV
00059       PARAMETER          ( LV = 128 )
00060       REAL               TWOPI
00061       PARAMETER          ( TWOPI = 6.2831853071795864769252867663E+0 )
00062 *     ..
00063 *     .. Local Scalars ..
00064       INTEGER            I, IL, IV
00065 *     ..
00066 *     .. Local Arrays ..
00067       REAL               U( LV )
00068 *     ..
00069 *     .. Intrinsic Functions ..
00070       INTRINSIC          CMPLX, EXP, LOG, MIN, SQRT
00071 *     ..
00072 *     .. External Subroutines ..
00073       EXTERNAL           SLARUV
00074 *     ..
00075 *     .. Executable Statements ..
00076 *
00077       DO 60 IV = 1, N, LV / 2
00078          IL = MIN( LV / 2, N-IV+1 )
00079 *
00080 *        Call SLARUV to generate 2*IL real numbers from a uniform (0,1)
00081 *        distribution (2*IL <= LV)
00082 *
00083          CALL SLARUV( ISEED, 2*IL, U )
00084 *
00085          IF( IDIST.EQ.1 ) THEN
00086 *
00087 *           Copy generated numbers
00088 *
00089             DO 10 I = 1, IL
00090                X( IV+I-1 ) = CMPLX( U( 2*I-1 ), U( 2*I ) )
00091    10       CONTINUE
00092          ELSE IF( IDIST.EQ.2 ) THEN
00093 *
00094 *           Convert generated numbers to uniform (-1,1) distribution
00095 *
00096             DO 20 I = 1, IL
00097                X( IV+I-1 ) = CMPLX( TWO*U( 2*I-1 )-ONE,
00098      $                       TWO*U( 2*I )-ONE )
00099    20       CONTINUE
00100          ELSE IF( IDIST.EQ.3 ) THEN
00101 *
00102 *           Convert generated numbers to normal (0,1) distribution
00103 *
00104             DO 30 I = 1, IL
00105                X( IV+I-1 ) = SQRT( -TWO*LOG( U( 2*I-1 ) ) )*
00106      $                       EXP( CMPLX( ZERO, TWOPI*U( 2*I ) ) )
00107    30       CONTINUE
00108          ELSE IF( IDIST.EQ.4 ) THEN
00109 *
00110 *           Convert generated numbers to complex numbers uniformly
00111 *           distributed on the unit disk
00112 *
00113             DO 40 I = 1, IL
00114                X( IV+I-1 ) = SQRT( U( 2*I-1 ) )*
00115      $                       EXP( CMPLX( ZERO, TWOPI*U( 2*I ) ) )
00116    40       CONTINUE
00117          ELSE IF( IDIST.EQ.5 ) THEN
00118 *
00119 *           Convert generated numbers to complex numbers uniformly
00120 *           distributed on the unit circle
00121 *
00122             DO 50 I = 1, IL
00123                X( IV+I-1 ) = EXP( CMPLX( ZERO, TWOPI*U( 2*I ) ) )
00124    50       CONTINUE
00125          END IF
00126    60 CONTINUE
00127       RETURN
00128 *
00129 *     End of CLARNV
00130 *
00131       END
 All Files Functions