median Interface

public interface median

Calculates the median value. This function does not work with quadruple precision numbers because of the ordering subroutine written in C++.

Syntax

y = median(x)

Where:

  • x = vector of rank 1 with real numbers. See this example to use an array of rank larger than 1.
  • y = real number of the same kind as x with the median of x.

Example

The following program calculates the median of a vector:

 PROGRAM medianExample
    USE FU_Statistics, ONLY: median
    IMPLICIT NONE
    REAL, DIMENSION(5) :: x = [1., 2., 3., 4., 5.]
    WRITE(*,*) median(x)
 END PROGRAM medianExample

Contents


Module Procedures

private function median_sp(x) result(res)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(in), DIMENSION(:) :: x

Vector of real numbers to calculate the median. It can have any size and it must have one dimension.

Return Value real(kind=sp)

Real number with the median

private function median_dp(x) result(res)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), DIMENSION(:) :: x

Vector of real numbers to calculate the median. It can have any size and it must have one dimension.

Return Value real(kind=dp)

Real number with the median