NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
histograms Module Reference

The module histograms provides infrastructure for the calculation of histograms. i.e: a count of frequency. More...

Data Types

type  histog
 type histogram holds the data from an histogram More...
 

Functions/Subroutines

type(histog) function, public histogram (a, nbins, bins, range, weights, density)
 Computes the histogram of an array of data.
 

Detailed Description

The module histograms provides infrastructure for the calculation of histograms. i.e: a count of frequency.

Function/Subroutine Documentation

◆ histogram()

type(histog) function, public histogram ( real(dp), dimension(:), intent(in), target a,
integer, intent(in), optional nbins,
real(dp), dimension(:), intent(in), optional bins,
real(dp), dimension(2), intent(in), optional range,
real(dp), dimension(size(a)), intent(in), optional weights,
logical, intent(in), optional density )

Computes the histogram of an array of data.

Note
It counts the number of occurrences in the interval [bins(i), bins(i+1) ) which is closed on the left and open on the right (does not include the upper limit) except for the last one which includes both limits
When neither bins nor Nbins are present the routine will calculate automatically the number of bins from the input data.

Examples:

h = histogram(linspace(0.5_dp, 5.5_dp, 6), nbins=5)
print "(A, 6(1x,g0.2))", 'Bin Edges:', h%bin_edges
print "(A, 5(1x,g0.2))", 'Histogram:', h%hist
! produces:
! Bin Edges: 0.50 1.5 2.5 3.5 4.5 5.5
! Histogram: 1.0 1.0 1.0 1.0 1.0
!
! and the fragment:
!
h = histogram([1._dp, 2._dp, 1._dp], bins=[0._dp, 1._dp, 2._dp, 3._dp])
print "(A, 4(1x,g0.2))", 'Bin Edges:', h%bin_edges
print "(A, 3(1x,g0.2))", 'Histogram:', h%hist
! produces:
!
! Bin Edges: 0.0 1.0 2.0 3.0
! Histogram: 0.0 2.0 1.0
!
Returns
The histogram construct of type histog.
Parameters
[in]aInput data
[in]nbinsNumber of equal-width bins to use
[in]binsA monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths.
[in]rangeThe lower and upper range of the bins. If not provided uses min and max
[in]weightsArray of weights, of the same size as a. Each value in a only contributes its associated weight towards the bin count (instead of 1)
[in]densityIf True, the result is the probability density function at the bin, normalized such that the integral over the range is 1.

References grids::linspace(), array_utils::mean(), basic::print_msg(), basic::small, array_utils::std(), and basic::zero.

Referenced by histog::clean().

Here is the call graph for this function:
Here is the caller graph for this function: