TECA
teca_table_writer.h
1 #ifndef teca_table_writer_h
2 #define teca_table_writer_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <vector>
9 #include <string>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_table_writer)
12 
13 
27 {
28 public:
29  TECA_ALGORITHM_STATIC_NEW(teca_table_writer)
30  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_table_writer)
31  TECA_ALGORITHM_CLASS_NAME(teca_table_writer)
33 
34  // set the output filename. for time series the substring
35  // %t% is replaced with the current time step. the substring
36  // %e% is replaced with .bin in binary mode, .csv in csv mode, .nc in
37  // netcdf mode, and xlsx in MS Excel mode.
38  // %s% is replaced with the table name (workbooks only).
39  TECA_ALGORITHM_PROPERTY(std::string, file_name)
40 
41  // sets the name of the row variable in the netCDF file
42  TECA_ALGORITHM_PROPERTY(std::string, row_dim_name)
43 
44  // report/initialize to/from Boost program options
45  // objects.
46  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
47  TECA_SET_ALGORITHM_PROPERTIES()
48 
49  // Select the output file format.
50  //
51  // 0 : auto, 1 : csv, 2 : bin, 3 : xlsx, 4 : netcdf
52  //
53  // in the auto format mode, the format is selected using the file
54  // name extention. the default is auto.
55  enum {format_auto, format_csv, format_bin, format_xlsx, format_netcdf};
56  TECA_ALGORITHM_PROPERTY(int, output_format)
57  void set_output_format_auto(){ this->set_output_format(format_auto); }
58  void set_output_format_csv(){ this->set_output_format(format_csv); }
59  void set_output_format_bin(){ this->set_output_format(format_bin); }
60  void set_output_format_xlsx(){ this->set_output_format(format_xlsx); }
61  void set_output_format_netcdf(){ this->set_output_format(format_netcdf); }
62 
63 protected:
65 
66 private:
67  const_p_teca_dataset execute(
68  unsigned int port,
69  const std::vector<const_p_teca_dataset> &input_data,
70  const teca_metadata &request) override;
71 
72  teca_metadata get_output_metadata(unsigned int port,
73  const std::vector<teca_metadata> &input_md) override;
74 
75 private:
76  std::string index_request_key;
77  std::string file_name;
78  std::string row_dim_name;
79  int output_format;
80 };
81 
82 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_table_writer
teca_table_writer - writes tabular datasets in CSV format.
Definition: teca_table_writer.h:27
teca_algorithm
Definition: teca_algorithm.h:25