Skip to content

Commit

Permalink
Add difference calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopherson committed Mar 11, 2024
1 parent 065928c commit 5584179
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/statistics_implementation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,46 @@ module function trimmed_mean_real32(x, p) result(rst)
rst = mean(x(i1:i2))
end function

! ------------------------------------------------------------------------------
pure module function difference_real64(x) result(rst)
!! Computes the difference between elements in an array.
real(real64), intent(in), dimension(:) :: x
!! The N-element array on which to operate.
real(real64), allocatable, dimension(:) :: rst
!! The (N-1)-element array containing the differences between adjacent
!! elements.

! Local Variables
integer(int32) :: i, n

! Process
n = size(x)
allocate(rst(n-1))
do i = 1, n - 1
rst(i) = x(i+1) - x(i)
end do
end function

! --------------------
pure module function difference_real32(x) result(rst)
!! Computes the difference between elements in an array.
real(real32), intent(in), dimension(:) :: x
!! The N-element array on which to operate.
real(real32), allocatable, dimension(:) :: rst
!! The (N-1)-element array containing the differences between adjacent
!! elements.

! Local Variables
integer(int32) :: i, n

! Process
n = size(x)
allocate(rst(n-1))
do i = 1, n - 1
rst(i) = x(i+1) - x(i)
end do
end function

! ******************************************************************************
! PRIVATE ROUTINES
! ------------------------------------------------------------------------------
Expand Down

0 comments on commit 5584179

Please sign in to comment.