TECA
teca_derived_quantity.h
1 #ifndef teca_derived_quantity_h
2 #define teca_derived_quantity_h
3 
4 #include "teca_programmable_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_dataset_fwd.h"
7 #include "teca_shared_object.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_derived_quantity)
13 
14 
26 {
27 public:
28  TECA_ALGORITHM_STATIC_NEW(teca_derived_quantity)
29  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_derived_quantity)
31 
32  //using teca_programmable_algorithm::get_class_name;
33 
34  // report/initialize to/from Boost program options
35  // objects.
36  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
37  TECA_SET_ALGORITHM_PROPERTIES()
38 
39  // set/get the list of arrays that are needed to produce
40  // the derived quantity
41  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, dependent_variable)
42 
43  // set/get the array that is produced
44  TECA_ALGORITHM_PROPERTY(std::string, derived_variable)
45 
46  // set/get the contextual name that differentiates this
47  // instance from others in the same pipeline.
48  void set_operation_name(const std::string &v);
49 
50  const std::string &get_operation_name() const
51  { return this->operation_name; }
52 
53  std::string &get_operation_name()
54  { return this->operation_name; }
55 
56  // set the callable that implements to derived quantity
57  // computation
58  using teca_programmable_algorithm::set_execute_callback;
59  using teca_programmable_algorithm::get_execute_callback;
60 
61 protected:
63 
64 private:
65  // specialized report and request implementations that
66  // process the input and output array lists in a standardized
67  // manner.
68  teca_metadata get_output_metadata(unsigned int port,
69  const std::vector<teca_metadata> &input_md) override;
70 
71  std::vector<teca_metadata> get_upstream_request(
72  unsigned int port, const std::vector<teca_metadata> &input_md,
73  const teca_metadata &request) override;
74 
75  // hide the programmable algorithm report request callbacks
76  using teca_programmable_algorithm::set_report_callback;
77  using teca_programmable_algorithm::get_report_callback;
78 
79  using teca_programmable_algorithm::set_request_callback;
80  using teca_programmable_algorithm::get_request_callback;
81 
82  // extracts variable from incoming request if the property
83  // is not set
84  std::string get_derived_variable(const teca_metadata &request);
85 
86  // extracts dependent variables from the incoming request
87  // if the coresponding property is not set
88  void get_dependent_variables(const teca_metadata &request,
89  std::vector<std::string> &dep_vars);
90 
91  // set the name used in log files.
92  int set_name(const std::string &name) override;
93 
94 private:
95  std::string operation_name;
96  std::vector<std::string> dependent_variables;
97  std::string derived_variable;
98 };
99 
100 #endif
teca_derived_quantity
a programmable algorithm specialized for simple array based computations
Definition: teca_derived_quantity.h:26
teca_metadata
Definition: teca_metadata.h:17
teca_programmable_algorithm
an algorithm implemented with user provided callbacks
Definition: teca_programmable_algorithm.h:57