Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=8), | intent(in) | :: | a(:) | |||
integer, | intent(out), | optional | :: | mid |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | m | ||||
integer, | public | :: | n |
function calc_median(a, mid) result(r)
real(8), intent(in) :: a(:)
integer, intent(out), optional :: mid
real(8) :: r
integer :: m, n
n = size(a)
m = n/2
if (mod(n,2) == 0) then
r = (a(m) + a(m+1))/2.0d0
else
m = m + 1
r = a(m)
end if
if (present(mid)) then
mid = m
end if
end function calc_median