Loading...
Searching...
No Matches
file-hist.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32//#include <exception>
33#include <fstream>
34#include <iostream>
35
36
37
38#include <drain/util/Histogram.h>
39#include <drain/prog/Command.h>
40
41
42//#include "fileio.h"
43#include "resources.h"
44//#include "fileio-read.h"
45
46namespace rack {
47
49
50 inline
51 HistEntry() : drain::BeanLike(__FUNCTION__), index(0), count(0){
52 getParameters().link("index", index);
53 getParameters().link("range", binRange.tuple());
54 getParameters().link("range.min", binRange.min);
55 getParameters().link("range.max", binRange.min);
56 //getParameters().link("max", binRange.max);
57 getParameters().link("count", count);
58 getParameters().link("label", label);
59 };
60
61 drain::Histogram::vect_t::size_type index;
62 drain::Range<double> binRange;
63 drain::Histogram::count_t count;
64 std::string label;
65
66};
67
68
71
72public:
73
74 int count = 0;
75
77
78 std::string attribute;
79 std::string filename;
80
81 // CmdHistogram() : drain::SimpleCommand<int>(__FUNCTION__, "Histogram","slots", 256, "") {
82 CmdHistogram() : drain::BasicCommand(__FUNCTION__, std::string("Histogram. Optionally --format using keys ") + histEntryHelper.getParameters().getKeys()) {
83 getParameters().link("count", count = 0); // = 256
84 getParameters().link("range", range.tuple());
85 //getParameters().link("max", maxValue = +std::numeric_limits<double>::max());
86 getParameters().link("filename", filename="", "<filename>.txt|-");
87 getParameters().link("attribute", attribute="histogram", "<attribute_key>");
88 getParameters().link("commentChar", commentChar, "Prefix for header and postfix for labels");
89 };
90
91 CmdHistogram(const CmdHistogram & cmd): drain::BasicCommand(cmd), count(0) {
92 getParameters().copyStruct(cmd.getParameters(), cmd, *this);
93 };
94 // virtual inline const std::string & getDescription() const { return description; };
95
96 typedef std::map<int, std::string> legend;
97
98
99 void exec() const;
100
101 // OutputPrefix ? included or not?
102 // Consider static, called by CmdOutputFile with default hist params?
103 void writeHistogram(const drain::Histogram & histogram, const std::string & filename, const legend &leg = legend()) const;
104
105 std::string commentChar = "#";
106
107private:
108
109 // Try to set "nodata" and "undetect"
110 void setSpecialEntry(legend & leg, double value, const std::string & label) const;
111
112 static
113 const HistEntry histEntryHelper;
114
115};
116
117
118
119
120
121} // namespace rack
Simple implementation of Command: adds name , description and parameters .
Definition Command.h:424
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:60
Class for computing a histogram and some statistics: average, min, max, mean, std....
Definition Histogram.h:61
Definition Range.h:52
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:399
TODO: generalize to array outfile.
Definition file-hist.h:70
void exec() const
Run the command with current parameter values.
Definition file-hist.cpp:55
Definition DataSelector.cpp:44
Definition file-hist.h:48