calc_median Function

function calc_median(a, mid) result(r)

Arguments

Type IntentOptional Attributes Name
real(kind=8), intent(in) :: a(:)
integer, intent(out), optional :: mid

Return Value real(kind=8)


Contents

Source Code


Variables

Type Visibility Attributes Name Initial
integer, public :: m
integer, public :: n

Source Code

    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