TECA
The Toolkit for Extreme Climate Analysis
teca_table_sort.h
1 #ifndef teca_table_sort_h
2 #define teca_table_sort_h
3 
4 #include "teca_config.h"
5 #include "teca_shared_object.h"
6 #include "teca_algorithm.h"
7 #include "teca_metadata.h"
8 
9 #include <string>
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_table_sort)
13 
14 /** @breif An algorithm that sorts the rows of a table using the values in a
15  * specified column.
16  * @details The sort can be done in ascending or descending order and a stable
17  * algorithm (i.e. one which does not change the order of equivalent elements)
18  * can be used. The table sort is especially useful when TECA's threaded
19  * algorithms, such as ::teca_table_reduce, produce in tables with a
20  * non-deterministic order.
21  */
23 {
24 public:
25  TECA_ALGORITHM_STATIC_NEW(teca_table_sort)
26  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_table_sort)
27  TECA_ALGORITHM_CLASS_NAME(teca_table_sort)
28  ~teca_table_sort();
29 
30  // report/initialize to/from Boost program options
31  // objects.
32  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
33  TECA_SET_ALGORITHM_PROPERTIES()
34 
35  /** @name index_column
36  * Set the name of the column to sort by.
37  */
38  ///@{
39  TECA_ALGORITHM_PROPERTY(std::string, index_column)
40  ///@}
41 
42  /** @name index_column_id
43  * Set the number of the column to sort by.
44  */
45  ///@{
46  TECA_ALGORITHM_PROPERTY(int, index_column_id)
47  ///@}
48 
49  /** @name stable_sort
50  * Enable or disable stable sort. The default is disabled.
51  */
52  ///@{
53  TECA_ALGORITHM_PROPERTY(int, stable_sort)
54 
55  /// Enables stable sort.
56  void enable_stable_sort(){ set_stable_sort(1); }
57 
58  /// Disable stable sort
59  void disable_stable_sort(){ set_stable_sort(0); }
60  ///@}
61 
62  /** @name ascending_order
63  * Set the sort order to ascending. the default is descending.
64  */
65  ///@{
66  TECA_ALGORITHM_PROPERTY(int, ascending_order)
67  ///@}
68 
69 
70 protected:
72 
73 private:
74  const_p_teca_dataset execute(
75  unsigned int port,
76  const std::vector<const_p_teca_dataset> &input_data,
77  const teca_metadata &request) override;
78 
79 private:
80  std::string index_column;
81  int index_column_id;
82  int stable_sort;
83  int ascending_order;
84 };
85 
86 #endif
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:244
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
Definition: teca_table_sort.h:23
void disable_stable_sort()
Disable stable sort.
Definition: teca_table_sort.h:59
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.