MODULE quadratures IMPLICIT none integer(kind=8) :: subintervals = 100 INTERFACE FUNCTION integrate(ibeg, iend, myfun, p) result(val) IMPLICIT none ! beginning of integration interval real(kind=8), intent(in) :: ibeg ! ending of integration interval real(kind=8), intent(in) :: iend ! function to be integrated procedure(funint) :: myfun ! polynomial order integer(kind=4), intent(in) :: p ! result of integration real(kind=8) :: val END FUNCTION integrate END INTERFACE INTERFACE FUNCTION funint(x) result(y) IMPLICIT none real(kind=8), intent(in) :: x real(kind=8) :: y END FUNCTION funint END INTERFACE CONTAINS FUNCTION newton_cotes(ibeg, iend, fun, p) result(val) IMPLICIT none real(kind=8), intent(in) :: ibeg real(kind=8), intent(in) :: iend procedure(funint) :: fun integer(kind=4), intent(in) :: p real(kind=8) :: val SELECT CASE (p) CASE (:-1) STOP "negative interpolationg polynomial order passed" CASE (0) val = 0 ! rectangle(ibeg, iend, fun) CASE (1) val = 0 ! trapeze(ibeg, iend, fun) CASE (2) val = 0 ! simpson_1_third(ibeg, iend, fun) CASE default STOP "Newton-Cotes quadratures only implemented for order < 3" END SELECT END FUNCTION newton_cotes END MODULE quadratures