You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

clarnd.f 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. *> \brief \b CLARND
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * COMPLEX FUNCTION CLARND( IDIST, ISEED )
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER IDIST
  15. * ..
  16. * .. Array Arguments ..
  17. * INTEGER ISEED( 4 )
  18. * ..
  19. *
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> CLARND returns a random complex number from a uniform or normal
  27. *> distribution.
  28. *> \endverbatim
  29. *
  30. * Arguments:
  31. * ==========
  32. *
  33. *> \param[in] IDIST
  34. *> \verbatim
  35. *> IDIST is INTEGER
  36. *> Specifies the distribution of the random numbers:
  37. *> = 1: real and imaginary parts each uniform (0,1)
  38. *> = 2: real and imaginary parts each uniform (-1,1)
  39. *> = 3: real and imaginary parts each normal (0,1)
  40. *> = 4: uniformly distributed on the disc abs(z) <= 1
  41. *> = 5: uniformly distributed on the circle abs(z) = 1
  42. *> \endverbatim
  43. *>
  44. *> \param[in,out] ISEED
  45. *> \verbatim
  46. *> ISEED is INTEGER array, dimension (4)
  47. *> On entry, the seed of the random number generator; the array
  48. *> elements must be between 0 and 4095, and ISEED(4) must be
  49. *> odd.
  50. *> On exit, the seed is updated.
  51. *> \endverbatim
  52. *
  53. * Authors:
  54. * ========
  55. *
  56. *> \author Univ. of Tennessee
  57. *> \author Univ. of California Berkeley
  58. *> \author Univ. of Colorado Denver
  59. *> \author NAG Ltd.
  60. *
  61. *> \ingroup complex_matgen
  62. *
  63. *> \par Further Details:
  64. * =====================
  65. *>
  66. *> \verbatim
  67. *>
  68. *> This routine calls the auxiliary routine SLARAN to generate a random
  69. *> real number from a uniform (0,1) distribution. The Box-Muller method
  70. *> is used to transform numbers from a uniform to a normal distribution.
  71. *> \endverbatim
  72. *>
  73. * =====================================================================
  74. COMPLEX FUNCTION CLARND( IDIST, ISEED )
  75. *
  76. * -- LAPACK auxiliary routine --
  77. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  78. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  79. *
  80. * .. Scalar Arguments ..
  81. INTEGER IDIST
  82. * ..
  83. * .. Array Arguments ..
  84. INTEGER ISEED( 4 )
  85. * ..
  86. *
  87. * =====================================================================
  88. *
  89. * .. Parameters ..
  90. REAL ZERO, ONE, TWO
  91. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
  92. REAL TWOPI
  93. PARAMETER ( TWOPI = 6.28318530717958647692528676655900576839E+0 )
  94. * ..
  95. * .. Local Scalars ..
  96. REAL T1, T2
  97. * ..
  98. * .. External Functions ..
  99. REAL SLARAN
  100. EXTERNAL SLARAN
  101. * ..
  102. * .. Intrinsic Functions ..
  103. INTRINSIC CMPLX, EXP, LOG, SQRT
  104. * ..
  105. * .. Executable Statements ..
  106. *
  107. * Generate a pair of real random numbers from a uniform (0,1)
  108. * distribution
  109. *
  110. T1 = SLARAN( ISEED )
  111. T2 = SLARAN( ISEED )
  112. *
  113. IF( IDIST.EQ.1 ) THEN
  114. *
  115. * real and imaginary parts each uniform (0,1)
  116. *
  117. CLARND = CMPLX( T1, T2 )
  118. ELSE IF( IDIST.EQ.2 ) THEN
  119. *
  120. * real and imaginary parts each uniform (-1,1)
  121. *
  122. CLARND = CMPLX( TWO*T1-ONE, TWO*T2-ONE )
  123. ELSE IF( IDIST.EQ.3 ) THEN
  124. *
  125. * real and imaginary parts each normal (0,1)
  126. *
  127. CLARND = SQRT( -TWO*LOG( T1 ) )*EXP( CMPLX( ZERO, TWOPI*T2 ) )
  128. ELSE IF( IDIST.EQ.4 ) THEN
  129. *
  130. * uniform distribution on the unit disc abs(z) <= 1
  131. *
  132. CLARND = SQRT( T1 )*EXP( CMPLX( ZERO, TWOPI*T2 ) )
  133. ELSE IF( IDIST.EQ.5 ) THEN
  134. *
  135. * uniform distribution on the unit circle abs(z) = 1
  136. *
  137. CLARND = EXP( CMPLX( ZERO, TWOPI*T2 ) )
  138. END IF
  139. RETURN
  140. *
  141. * End of CLARND
  142. *
  143. END