WEIRAN Subroutine

public subroutine WEIRAN(N, Gamma, Iseed, X)

NAME

weiran(3f) - [M_datapac:RANDOM] generate Weibull random numbers

SYNOPSIS

   SUBROUTINE WEIRAN(N,Gamma,Iseed,X)

    INTEGER       :: N
    REAL(kind=wp) :: Gamma
    INTEGER       :: Iseed
    REAL(kind=wp) :: X(:)

DESCRIPTION

WEIRAN(3f) generates a random sample of size N from the Weibull
distribution with tail length parameter value = GAMMA.

The prototype Weibull distribution used herein is defined for all
positive X, and has the probability density function

    f(X) = GAMMA * (X**(GAMMA-1)) * exp(-(X**GAMMA)).

INPUT ARGUMENTS

N      The desired integer number of random numbers to be generated.
GAMMA  The value of the tail length parameter. gamma should
       be positive.
ISEED  An integer iseed value. Should be set to a non-negative value
       to start a new sequence of values. Will be set to -1 on return
       to indicate the next call should continue the current random
       sequence walk.

OUTPUT ARGUMENTS

X      A vector (of dimension at least N) into which the generated
       random sample will be placed.

EXAMPLES

Sample program:

program demo_weiran
use M_datapac, only : weiran
implicit none
! call weiran(x,y)
end program demo_weiran

Results:

AUTHOR

The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.

MAINTAINER

John Urban, 2022.05.31

LICENSE

CC0-1.0

REFERENCES

  • Tocher, the Art of Simulation, 1963, pages 14-15.
  • Hammersley and Handscomb, Monte Carlo Methods, 1964, page 36.
  • Johnson and Kotz, Continuous Univariate Distributions–1, 1970, pages 250-271.
  • Hastings and Peacock, Statistical Distributions–A Handbook for Students and Practitioners, 1975, page 128.

Arguments

Type IntentOptional Attributes Name
integer :: N
real(kind=wp) :: Gamma
integer :: Iseed
real(kind=wp) :: X(:)

Source Code

SUBROUTINE WEIRAN(N,Gamma,Iseed,X)
INTEGER       :: N
REAL(kind=wp) :: Gamma
INTEGER       :: Iseed
REAL(kind=wp) :: X(:)

INTEGER       :: i

!
!     CHECK THE INPUT ARGUMENTS FOR ERRORS
!
      IF ( N<1 ) THEN
         WRITE (G_IO,99001)
         99001    FORMAT (' ***** FATAL ERROR--THE FIRST  INPUT ARGUMENT TO WEIRAN(3f) IS NON-POSITIVE *****')
         WRITE (G_IO,99002) N
         99002    FORMAT (' ','***** THE VALUE OF THE ARGUMENT IS ',I0,' *****')
         RETURN
      ELSEIF ( Gamma<=0.0_wp ) THEN
         WRITE (G_IO,99003)
         99003    FORMAT (' ***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO WEIRAN(3f) IS NON-POSITIVE *****')
         WRITE (G_IO,99004) Gamma
         99004    FORMAT (' ','***** THE VALUE OF THE ARGUMENT IS ',E15.8,' *****')
         RETURN
      ELSE
         !
         !     GENERATE N UNIFORM (0,1) RANDOM NUMBERS;
         !
         CALL UNIRAN(N,Iseed,X)
         !
         !     GENERATE N WEIBULL DISTRIBUTION RANDOM NUMBERS
         !     USING THE PERCENT POINT FUNCTION TRANSFORMATION METHOD.
         !
         DO i = 1 , N
            X(i) = (-LOG(1.0_wp-X(i)))**(1.0_wp/Gamma)
         ENDDO
      ENDIF
!
END SUBROUTINE WEIRAN