linspace_dp Function

private function linspace_dp(start_val, end_val, n_opt) result(vec)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: start_val
real(kind=dp), intent(in) :: end_val
integer, intent(in), optional :: n_opt

Return Value real(kind=dp), allocatable, (:)


Contents

Source Code


Source Code

    function linspace_dp(start_val, end_val, n_opt) result(vec)
        real(dp), intent(in) :: start_val, end_val
        integer, intent(in), optional :: n_opt
        real(dp), allocatable :: vec(:)

        integer :: n, i
        real(dp) :: dist

        ! set default
        if (present(n_opt)) then
            n = n_opt
        else
            n = 100
        end if

        dist = (end_val - start_val) / real(n - 1, dp)

        allocate(vec(n))

        vec = [ ( start_val + i * dist, i = 0,n-1)]

    end function linspace_dp