Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | start_val | |||
real(kind=sp), | intent(in) | :: | end_val | |||
integer, | intent(in), | optional | :: | n_opt |
function linspace_sp(start_val, end_val, n_opt) result(vec)
real(sp), intent(in) :: start_val, end_val
integer, intent(in), optional :: n_opt
real(sp), allocatable :: vec(:)
integer :: n, i
real(sp) :: dist
! set default
if (present(n_opt)) then
n = n_opt
else
n = 100
end if
dist = (end_val - start_val) / real(n - 1, sp)
allocate(vec(n))
vec = [ ( start_val + i * dist, i = 0,n-1)]
end function linspace_sp