MeteoIODoc 2.11.0
FilterMaths.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2019 Avalanche Warning Service Tyrol LWD-TIROL */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef FILTERMATHS_H
21#define FILTERMATHS_H
22
24
25#include <meteoio/thirdParty/tinyexpr.h>
26#include <map>
27
28namespace mio {
29
218 public:
219 FilterMaths(const std::vector< std::pair<std::string, std::string> >& vecArgs,
220 const std::string& name, const Config& cfg);
221 virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
222 std::vector<MeteoData>& ovec);
223
224 private:
225 bool assertCondition(const double& condition_value, const double& condition_compare,
226 const std::string& condition_operator) const;
227 bool assertStringCondition(const std::string& line1, const std::string& line2, const std::string& op);
228 std::map<std::string, double> parseBracketExpression(std::string& line);
229 void buildSubstitutions();
230 void doSubstitutions(const std::vector<MeteoData>& ivec, const size_t& idx);
231 std::string doStringSubstitutions(const std::string& line_in, const MeteoData& ielem) const;
232 te_expr* compileExpression(const std::string& expression, const te_variable* te_vars, const size_t& sz) const;
233 void initExpressionVars(te_variable* vars);
234 void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
235 bool isNan(const double& xx) const;
236 void checkOperator(const std::string& op);
237
238 struct logic_eq {
239 std::string expression;
240 std::string op;
241 std::string compare;
242 logic_eq() : expression(""), op(""), compare("") {}
243 };
244 std::map<size_t, logic_eq> logic_equations; //collection of conditions the user supplies
245 std::map<std::string, double> substitutions; //fixed memory for substitutions
246
247 std::string formula; //calculation expression
248 std::string formula_else; //expression to use when evaluating to false
249 std::string connective; //AND or OR
250 std::string assign_param; //assign final value to this parameter
251
252 bool skip_nodata; //continue on nodata early on
253};
254
255} //namespace
256
257#endif // FILTERMATHS_H
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A filter that evaluates formulas dependent on conditions.
Definition: FilterMaths.h:217
virtual void process(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< MeteoData > &ovec)
The filtering routine as called by the processing toolchain.
Definition: FilterMaths.cc:43
FilterMaths(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: FilterMaths.cc:28
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:107
The base class for all filters that provides the interface and a few helper methods.
Definition: ProcessingBlock.h:67
Definition: Config.cc:31