Calculate cumulative sum
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=Float64), | intent(in), | dimension(:) | :: | x | Array to sum |
|
real(kind=Float64), | intent(out), | dimension(:) | :: | cs | Cumulative sum of |
subroutine cumsum(x, cs)
!+ Calculate cumulative sum
real(Float64), dimension(:), intent(in) :: x
!+ Array to sum
real(Float64), dimension(:), intent(out) :: cs
!+ Cumulative sum of `x`
integer :: i, n
real(Float64) :: cdf_val, t
n = size(x)
t = 0.d0
do i=1, n
cs(i) = t + x(i)
t = cs(i)
enddo
end subroutine cumsum