Histogram.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "Histogram.H"
00028 #include "ListOps.H"
00029
00030
00031
00032
00033 template<class List>
00034 void Foam::Histogram<List>::count(const List& bins, const List& l)
00035 {
00036 if (bins.size() < 2)
00037 {
00038 FatalErrorIn("Histogram<List>::count(const List&, const List&)")
00039 << "Should have at least two values in bins. Now:" << bins
00040 << exit(FatalError);
00041 }
00042
00043 counts_.setSize(bins.size()-1);
00044 counts_ = 0;
00045
00046 nLow_ = 0;
00047 nHigh_ = 0;
00048
00049 forAll(l, i)
00050 {
00051 label index = findLower(bins, l[i]);
00052
00053 if (index == -1)
00054 {
00055 nLow_++;
00056 }
00057 else if (index == bins.size()-1)
00058 {
00059 nHigh_++;
00060 }
00061 else
00062 {
00063 counts_[index]++;
00064 }
00065 }
00066 }
00067
00068
00069
00070
00071 template<class List>
00072 Foam::Histogram<List>::Histogram(const List& bins, const List& l)
00073 {
00074 count(bins, l);
00075 }
00076
00077
00078 template<class List>
00079 Foam::Histogram<List>::Histogram
00080 (
00081 const typename List::const_reference min,
00082 const typename List::const_reference max,
00083 const label nBins,
00084 const List& l
00085 )
00086 {
00087 List bins(nBins+1);
00088
00089 typename List::value_type span = (max-min) / nBins;
00090
00091 bins[0] = min;
00092
00093 for (label i = 1; i < nBins; i++)
00094 {
00095 bins[i] = bins[i-1] + span;
00096 }
00097
00098
00099 bins[nBins] = max;
00100
00101 count(bins, l);
00102 }
00103
00104
00105
Copyright © 2000-2009 OpenCFD Ltd