Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=8), | intent(in) | :: | a(:) | |||
real(kind=8), | intent(out) | :: | mean | |||
real(kind=8), | intent(out) | :: | median | |||
real(kind=8), | intent(out) | :: | stddev | |||
real(kind=8), | intent(out) | :: | lower_q | |||
real(kind=8), | intent(out) | :: | upper_q |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=8), | public | :: | b(size(a)) | ||||
integer, | public | :: | m | ||||
integer, | public | :: | n | ||||
real(kind=8), | public | :: | s | ||||
real(kind=8), | public | :: | s2 |
subroutine summary_stats(a, mean, median, stddev, lower_q, upper_q)
real(8), intent(in) :: a(:)
real(8), intent(out) :: mean, median, stddev, lower_q, upper_q
real(8) :: b(size(a))
real(8) :: s, s2
integer :: m, n
n = size(a)
b = a
s = sum(b)
s2 = sum(b**2)
mean = s/n
stddev = sqrt(s2/n - (s/n)**2)
call sort(b)
median = calc_median(b, m)
if (n < 3) then
lower_q = median
upper_q = median
else
lower_q = calc_median(b(1:m))
if (mod(n,2) == 0) then
upper_q = calc_median(b(m+1:n))
else
upper_q = calc_median(b(m:n))
end if
end if
end subroutine summary_stats