! user_defined_points 1 INTEGER .FALSE.
! user_bernoulli 1 REAL .FALSE.

MODULE user_dist
  IMPLICIT NONE
  
CONTAINS
  SUBROUTINE user_bernoulli_freq(p, point, prob)
    IMPLICIT NONE
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(IN) :: p
    INTEGER, INTENT(IN) :: point
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(OUT) :: prob

    IF (point == 1) THEN 
       prob = p
    ELSE
       IF (point == 0) THEN
          prob = 1-p
       ELSE
          prob = 0
       END IF
    END IF
    
  END SUBROUTINE user_bernoulli_freq

  SUBROUTINE user_discrete_uniform_freq(left, right, value, prob)
    INTEGER, INTENT(IN) :: value, left, right
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(OUT) :: prob
    
    prob = REAL(1 /(( REAL(right) - REAL(left)) +1))

  END SUBROUTINE user_discrete_uniform_freq

  SUBROUTINE user_continuous_uniform_freq(left, right, value, prob)
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(IN) :: left, right
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(IN) :: value
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(OUT) :: prob
    
    prob = 1/(right - left)
    
  END SUBROUTINE user_continuous_uniform_freq


  SUBROUTINE user_defined_points_freq(param, point, prob)
    IMPLICIT NONE
    INTEGER, INTENT(IN) :: param
    INTEGER, INTENT(IN) :: point
    REAL (KIND=SELECTED_REAL_KIND(8, 0)), INTENT(OUT) :: prob

    ! P(obs = 0 | x = 0) = 0.8
    ! P(obs = 1 | x = 0) = 0.2
    ! P(obs = 0 | x = 1) = 0.4
    ! P(obs = 1 | x = 1) = 0.6
    
    IF (point == 0 .AND. param == 0) prob = 0.8
    IF (point == 1 .AND. param == 0) prob = 0.2
    IF (point == 0 .AND. param == 1) prob = 0.4
    IF (point == 1 .AND. param == 1) prob = 0.6
    
  END SUBROUTINE user_defined_points_freq




END MODULE user_dist
