TECA
teca_cf_writer.h
1 #ifndef teca_cf_writer_h
2 #define teca_cf_writer_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_threaded_algorithm.h"
6 #include "teca_metadata.h"
7 
8 #include <vector>
9 #include <string>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cf_writer)
12 
13 
14 // A writer for Cartesian meshes in NetCDF CF2 format.
57 {
58 public:
59  TECA_ALGORITHM_STATIC_NEW(teca_cf_writer)
60  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_cf_writer)
61  TECA_ALGORITHM_CLASS_NAME(teca_cf_writer)
62  ~teca_cf_writer();
63 
64  // report/initialize to/from Boost program options
65  // objects.
66  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
67  TECA_SET_ALGORITHM_PROPERTIES()
68 
69  // set the output filename. for time series the substring %t% is replaced
70  // with the current time step or date. See comments on date_format below
71  // for info about date formatting.
72  TECA_ALGORITHM_PROPERTY(std::string, file_name)
73 
74  // set the format for the date to write in the filename. this requires the
75  // input dataset to have unit/calendar information if none are available,
76  // the time index is used instead. (%F-%HZ)
77  TECA_ALGORITHM_PROPERTY(std::string, date_format)
78 
79  // set the range of time step to process.
80  TECA_ALGORITHM_PROPERTY(long, first_step)
81  TECA_ALGORITHM_PROPERTY(long, last_step)
82 
83  // set how many time steps are written to each file. Note that upstream is
84  // parallelized over files rather than time steps. this has the affect of
85  // reducing the available oportunity for MPI parallelization by this
86  // factor. For example if there are 16 timee steps and steps_per_file is 8,
87  // 2 MPI ranks each running 8 or more threads would be optimal. One
88  // should make such calculations when planning large runs if optimal
89  // performance is desired. time steps are gathered before the file is
90  // written, thus available memory per MPI rank is the limiting factor in
91  // how many steps can be stored in a single file (1).
92  TECA_ALGORITHM_PROPERTY(unsigned int, steps_per_file)
93 
94  // sets the flags passed to NetCDF during file creation. (NC_CLOBBER)
95  TECA_ALGORITHM_PROPERTY(int, mode_flags)
96 
97  // if set the slowest varying dimension is specified to be NC_UNLIMITED.
98  // This has a negative impact on performance when reading the values in a
99  // single pass. However, unlimited dimensions are used ubiquitously thus
100  // by default it is set. For data being consumed by TECA performance will
101  // be better when using fixed dimensions. (1) This feature requires
102  // collective writes and is incompatible with out of order execution,
103  // and hence currently not suppoorted.
104  TECA_ALGORITHM_PROPERTY(int, use_unlimited_dim)
105 
106  // sets the compression level used for each variable compression is not
107  // used if the value is less than or equal to 0. This feature requires
108  // collective writes and is incompatible with out of order execution,
109  // and hence currently not suppoorted.
110  TECA_ALGORITHM_PROPERTY(int, compression_level)
111 
112  // flush files before closing them, this may be necessary if accessing data
113  // immediately.
114  TECA_ALGORITHM_PROPERTY(int, flush_files);
115 
116  // specify the arrays to write. a data array is only written to disk if
117  // it is included in this list. it is an error to not specify at least
118  // one point centered array to write
119  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, point_array)
120  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, information_array)
121 
122 protected:
123  teca_cf_writer();
124 
125 private:
126  const_p_teca_dataset execute(unsigned int port,
127  const std::vector<const_p_teca_dataset> &input_data,
128  const teca_metadata &request, int streaming) override;
129 
130  teca_metadata get_output_metadata(unsigned int port,
131  const std::vector<teca_metadata> &input_md) override;
132 
133  std::vector<teca_metadata> get_upstream_request(unsigned int port,
134  const std::vector<teca_metadata> &input_md,
135  const teca_metadata &request) override;
136 
137  // flush data to disk. this may be necessary if accessing data
138  // immediately.
139  int flush();
140 
141 private:
142  std::string file_name;
143  std::string date_format;
144  long first_step;
145  long last_step;
146  unsigned int steps_per_file;
147  int mode_flags;
148  int use_unlimited_dim;
149  int compression_level;
150  int flush_files;
151 
152  std::vector<std::string> point_arrays;
153  std::vector<std::string> information_arrays;
154 
155  class internals_t;
156  internals_t *internals;
157 };
158 
159 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_cf_writer
Definition: teca_cf_writer.h:57
teca_cf_writer::internals_t
Definition: teca_cf_writer.cxx:28
teca_threaded_algorithm
Definition: teca_threaded_algorithm.h:34