stdlib_quadrature.fypp Source File


This file depends on

sourcefile~~stdlib_quadrature.fypp~~EfferentGraph sourcefile~stdlib_quadrature.fypp stdlib_quadrature.fypp sourcefile~stdlib_kinds.f90 stdlib_kinds.f90 sourcefile~stdlib_quadrature.fypp->sourcefile~stdlib_kinds.f90

Files dependent on this one

sourcefile~~stdlib_quadrature.fypp~~AfferentGraph sourcefile~stdlib_quadrature.fypp stdlib_quadrature.fypp sourcefile~stdlib_quadrature_simps.fypp stdlib_quadrature_simps.fypp sourcefile~stdlib_quadrature_simps.fypp->sourcefile~stdlib_quadrature.fypp sourcefile~stdlib_quadrature_trapz.fypp stdlib_quadrature_trapz.fypp sourcefile~stdlib_quadrature_trapz.fypp->sourcefile~stdlib_quadrature.fypp

Contents


Source Code

#:include "common.fypp"
module stdlib_quadrature
    !! ([Specification](../page/specs/stdlib_quadrature.html#description))
    use stdlib_kinds, only: sp, dp, qp

    implicit none

    private

    ! array integration
    public :: trapz
    public :: trapz_weights
    public :: simps
    public :: simps_weights


    interface trapz
        !! version: experimental
        !!
        !! Integrates sampled values using trapezoidal rule
        !! ([Specification](../page/specs/stdlib_quadrature.html#description))
        #:for k1, t1 in REAL_KINDS_TYPES
        pure module function trapz_dx_${k1}$(y, dx) result(integral)
          ${t1}$, dimension(:), intent(in) :: y
          ${t1}$, intent(in) :: dx
          ${t1}$ :: integral
        end function trapz_dx_${k1}$
        #:endfor
        #:for k1, t1 in REAL_KINDS_TYPES
        module function trapz_x_${k1}$(y, x) result(integral)
            ${t1}$, dimension(:), intent(in) :: y
            ${t1}$, dimension(:), intent(in) :: x
            ${t1}$ :: integral
        end function trapz_x_${k1}$
        #:endfor
    end interface trapz


    interface trapz_weights
        !! version: experimental
        !!
        !! Integrates sampled values using trapezoidal rule weights for given abscissas
        !! ([Specification](../page/specs/stdlib_quadrature.html#description_1))
        #:for k1, t1 in REAL_KINDS_TYPES
        pure module function trapz_weights_${k1}$(x) result(w)
            ${t1}$, dimension(:), intent(in) :: x
            ${t1}$, dimension(size(x)) :: w
        end function trapz_weights_${k1}$
        #:endfor
    end interface trapz_weights


    interface simps
        !! version: experimental
        !!
        !! Integrates sampled values using Simpson's rule
        !! ([Specification](../page/specs/stdlib_quadrature.html#description_3))
        ! "recursive" is an implementation detail
        #:for k1, t1 in REAL_KINDS_TYPES
        pure recursive module function simps_dx_${k1}$(y, dx, even) result(integral)
            ${t1}$, dimension(:), intent(in) :: y
            ${t1}$, intent(in) :: dx
            integer, intent(in), optional :: even
            ${t1}$ :: integral
        end function simps_dx_${k1}$
        #:endfor
        #:for k1, t1 in REAL_KINDS_TYPES
        recursive module function simps_x_${k1}$(y, x, even) result(integral)
            ${t1}$, dimension(:), intent(in) :: y
            ${t1}$, dimension(:), intent(in) :: x
            integer, intent(in), optional :: even
            ${t1}$ :: integral
        end function simps_x_${k1}$
        #:endfor
    end interface simps


    interface simps_weights
        !! version: experimental
        !!
        !! Integrates sampled values using trapezoidal rule weights for given abscissas
        !! ([Specification](../page/specs/stdlib_quadrature.html#description_3))
        #:for k1, t1 in REAL_KINDS_TYPES
        pure recursive module function simps_weights_${k1}$(x, even) result(w)
            ${t1}$, dimension(:), intent(in) :: x
            integer, intent(in), optional :: even
            ${t1}$, dimension(size(x)) :: w
        end function simps_weights_${k1}$
        #:endfor
    end interface simps_weights


    ! Interface for a simple f(x)-style integrand function.
    ! Could become fancier as we learn about the performance
    ! ramifications of different ways to do callbacks.
    abstract interface
        #:for k1, t1 in REAL_KINDS_TYPES
        pure function integrand_${k1}$(x) result(f)
            import :: ${k1}$
            ${t1}$, intent(in) :: x
            ${t1}$ :: f
        end function integrand_${k1}$
        #:endfor
    end interface

end module stdlib_quadrature