TECA
The Toolkit for Extreme Climate Analysis
teca_cf_interval_time_step_mapper.h
1 #ifndef teca_cf_interval_time_step_mapper_h
2 #define teca_cf_interval_time_step_mapper_h
3 
4 #include "teca_config.h"
5 #include "teca_metadata.h"
6 #include "teca_cf_layout_manager.h"
7 #include "teca_cf_time_step_mapper.h"
8 #include "teca_calendar_util.h"
9 #include "teca_mpi.h"
10 
11 #include <iostream>
12 #include <sstream>
13 #include <cstring>
14 #include <cerrno>
15 #include <string>
16 #include <unordered_map>
17 #include <vector>
18 #include <memory>
19 
21 using p_teca_cf_interval_time_step_mapper = std::shared_ptr<teca_cf_interval_time_step_mapper>;
22 
23 /// NetCDF CF2 files time step mapper.
25 {
26 public:
27 
28  /// allocate and return a new object
29  static p_teca_cf_interval_time_step_mapper New()
30  { return p_teca_cf_interval_time_step_mapper(new teca_cf_interval_time_step_mapper); }
31 
33 
34  /** initialize based on input metadata. this is a collective call creates
35  * communicator groups for each file and creates the file layout managers
36  * for the local rank. After this call one can access file managers to
37  * create, define and write local datasets to the NetCDF files in cf
38  * format.
39  */
40  int initialize(MPI_Comm comm, long first_step, long last_step,
41  const teca_calendar_util::p_interval_iterator &it,
42  const std::string &index_request_key);
43 
44  p_teca_cf_layout_manager get_layout_manager(long time_step) override;
46 
47  /// print a summary to the stream
48  int to_stream(std::ostream &os) override;
49 
50 protected:
51  teca_cf_interval_time_step_mapper() : file_steps()
52  {}
53 
54  // remove these for convenience
57  void operator=(const teca_cf_interval_time_step_mapper&) = delete;
58  void operator=(const teca_cf_interval_time_step_mapper&&) = delete;
59 
60  /// given a time step, get the corresponding file id
61  int get_file_id(long time_step, long &file_id);
62 
63 protected:
64  using step_bracket_t = std::pair<long, long>;
65  std::vector<step_bracket_t> file_steps;
66 };
67 
68 #endif
NetCDF CF2 files time step mapper.
Definition: teca_cf_interval_time_step_mapper.h:25
int initialize(MPI_Comm comm, long first_step, long last_step, const teca_calendar_util::p_interval_iterator &it, const std::string &index_request_key)
static p_teca_cf_interval_time_step_mapper New()
allocate and return a new object
Definition: teca_cf_interval_time_step_mapper.h:29
int to_stream(std::ostream &os) override
print a summary to the stream
int get_file_id(long time_step, long &file_id)
given a time step, get the corresponding file id
p_teca_cf_layout_manager get_layout_manager(long time_step) override
given a time step returns the associated layout manager
Defines the interface for mapping time steps to files.
Definition: teca_cf_time_step_mapper.h:23
virtual p_teca_cf_layout_manager get_layout_manager(long time_step)
given a time step returns the associated layout manager
Definition: teca_cf_time_step_mapper.h:40
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.