TECA
teca_evaluate_expression.h
1 #ifndef teca_evaluate_expression_h
2 #define teca_evaluate_expression_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <string>
9 #include <vector>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_evaluate_expression)
12 
13 
31 {
32 public:
33  TECA_ALGORITHM_STATIC_NEW(teca_evaluate_expression)
34  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_evaluate_expression)
35  TECA_ALGORITHM_CLASS_NAME(teca_evaluate_expression)
37 
38  // report/initialize to/from Boost program options
39  // objects.
40  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
41  TECA_SET_ALGORITHM_PROPERTIES()
42 
43  // set/get the expression to evaluate
44  void set_expression(const std::string &expr);
45 
46  std::string get_expression()
47  { return this->expression; }
48 
49  // set the name of the variable to store the result in
50  TECA_ALGORITHM_PROPERTY(std::string, result_variable);
51 
52  // when set columns used in the calculation are removed
53  // from the output. deault off.
54  TECA_ALGORITHM_PROPERTY(int, remove_dependent_variables)
55 
56 protected:
58 
59 private:
60  teca_metadata get_output_metadata(unsigned int port,
61  const std::vector<teca_metadata> &input_md) override;
62 
63  std::vector<teca_metadata> get_upstream_request(
64  unsigned int port, const std::vector<teca_metadata> &input_md,
65  const teca_metadata &request) override;
66 
67  const_p_teca_dataset execute(unsigned int port,
68  const std::vector<const_p_teca_dataset> &input_data,
69  const teca_metadata &request) override;
70 
71 private:
72  std::string expression;
73  std::string result_variable;
74  std::string postfix_expression;
75  std::set<std::string> dependent_variables;
76  int remove_dependent_variables;
77 };
78 
79 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_evaluate_expression
Definition: teca_evaluate_expression.h:31
teca_algorithm
Definition: teca_algorithm.h:25