MODULE proposal
IMPLICIT NONE
PRIVATE
  INTERFACE generate
     MODULE procedure generate_int, generate_real
  END INTERFACE

PUBLIC :: generate 

CONTAINS
  ! These subroutines generate samples from the proposal strategy
  ! into a buffer so that we don't need a function call every time
  ! we need a new value to propose.
  SUBROUTINE generate_int(name, buffer)
    
    ! Note: We assume that the random number generator has
    ! been initialized.
    IMPLICIT NONE
    
    CHARACTER(LEN=*), INTENT(IN) :: name
    INTEGER, DIMENSION(:), INTENT(INOUT) :: buffer
    INTEGER :: i


    INTEGER G05DYF
    EXTERNAL G05DYF

    SELECT CASE (name)

    CASE ('x') 
       DO i=1, SIZE(buffer)
          buffer(i) = G05DYF(0, 1)
       END DO

    CASE DEFAULT
    END SELECT
    
  END SUBROUTINE generate_int
  
  SUBROUTINE generate_real(name, buffer)
    IMPLICIT NONE

    CHARACTER(LEN=*), INTENT(IN) :: name
    REAL(KIND=SELECTED_REAL_KIND(8, 0)), DIMENSION(:), INTENT(INOUT) :: buffer
    INTEGER :: i

    INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(8, 0)
    
    REAL G05DAF
    EXTERNAL G05DAF

    SELECT CASE (name)
    CASE ('alpha') 
       DO i=1, SIZE(buffer)
          buffer(i) = G05DAF(-1.0_dp, 1.0_dp)
       END DO
    END SELECT
    
  END SUBROUTINE generate_real
  
END MODULE proposal
