TECA
The Toolkit for Extreme Climate Analysis
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 /** @brief
14  * An algorithm that writes tabular data in a binary or CSV (comma separated
15  * value) format that is easily ingested by most spreadsheet apps. Each page
16  * of a database is written to a file.
17  *
18  * @details
19  * The binary format is internal to TECA, and provides the best performance.
20  *
21  * The CSV format is intended for use getting data into other tools such as MS
22  * Excel and or Python based codes.
23  *
24  * See TECA CSV format specification in teca_table_reader for more
25  * information.
26  */
28 {
29 public:
30  TECA_ALGORITHM_STATIC_NEW(teca_table_writer)
31  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_table_writer)
32  TECA_ALGORITHM_CLASS_NAME(teca_table_writer)
34 
35  // set the output filename. for time series the substring
36  // %t% is replaced with the current time step. the substring
37  // %e% is replaced with .bin in binary mode, .csv in csv mode, .nc in
38  // netcdf mode, and xlsx in MS Excel mode.
39  // %s% is replaced with the table name (workbooks only).
40  TECA_ALGORITHM_PROPERTY(std::string, file_name)
41 
42  // sets the name of the row variable in the netCDF file
43  TECA_ALGORITHM_PROPERTY(std::string, row_dim_name)
44 
45  // report/initialize to/from Boost program options
46  // objects.
47  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
48  TECA_SET_ALGORITHM_PROPERTIES()
49 
50  // Select the output file format.
51  //
52  // 0 : auto, 1 : csv, 2 : bin, 3 : xlsx, 4 : netcdf
53  //
54  // in the auto format mode, the format is selected using the file
55  // name extention. the default is auto.
56  enum {format_auto, format_csv, format_bin, format_xlsx, format_netcdf};
57  TECA_ALGORITHM_PROPERTY(int, output_format)
58  void set_output_format_auto(){ this->set_output_format(format_auto); }
59  void set_output_format_csv(){ this->set_output_format(format_csv); }
60  void set_output_format_bin(){ this->set_output_format(format_bin); }
61  void set_output_format_xlsx(){ this->set_output_format(format_xlsx); }
62  void set_output_format_netcdf(){ this->set_output_format(format_netcdf); }
63 
64 protected:
66 
67 private:
68  const_p_teca_dataset execute(
69  unsigned int port,
70  const std::vector<const_p_teca_dataset> &input_data,
71  const teca_metadata &request) override;
72 
73  teca_metadata get_output_metadata(unsigned int port,
74  const std::vector<teca_metadata> &input_md) override;
75 
76 private:
77  std::string index_request_key;
78  std::string file_name;
79  std::string row_dim_name;
80  int output_format;
81 };
82 
83 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_table_writer
An algorithm that writes tabular data in a binary or CSV (comma separated value) format that is easil...
Definition: teca_table_writer.h:27
teca_shared_object.h
teca_algorithm
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237