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