TECA
teca_multi_cf_reader.h
1 #ifndef teca_multi_cf_reader_h
2 #define teca_multi_cf_reader_h
3 
4 #include "teca_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_shared_object.h"
7 
8 #include <set>
9 #include <vector>
10 #include <string>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_multi_cf_reader)
13 
15 using p_teca_multi_cf_reader_internals = std::shared_ptr<teca_multi_cf_reader_internals>;
16 
18 
66 {
67 public:
68  TECA_ALGORITHM_STATIC_NEW(teca_multi_cf_reader)
69  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_multi_cf_reader)
70  TECA_ALGORITHM_CLASS_NAME(teca_multi_cf_reader)
72 
73  // report/initialize to/from Boost program options
74  // objects.
75  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
76  TECA_SET_ALGORITHM_PROPERTIES()
77 
78  // set the file name describing the dataset to read
79  int set_input_file(const std::string &input_file);
80 
81  // adds a reader to the collection and at the same time specifies
82  // how it will be used.
83  int add_reader(const std::string &key,
84  const std::string &files_regex,
85  int provides_time, int provides_geometry,
86  const std::vector<std::string> &variables);
87 
88  // sets the reader that provides the time axis
89  int set_time_reader(const std::string &key);
90 
91  // sets the reader that provides the mesh geometry
92  int set_geometry_reader(const std::string &key);
93 
94  // adds to the list of variables that a reader will provide
95  int add_variable_reader(const std::string &key,
96  const std::string &variable);
97 
98  // sets the list of variable that a reader will provide.
99  int set_variable_reader(const std::string &key,
100  const std::vector<std::string> &variable);
101 
102  // get the list of variables that the reader will serve up
103  void get_variables(std::vector<std::string> &vars);
104 
105  // set if the dataset has periodic boundary conditions
106  TECA_ALGORITHM_PROPERTY(int, periodic_in_x)
107  TECA_ALGORITHM_PROPERTY(int, periodic_in_y)
108  TECA_ALGORITHM_PROPERTY(int, periodic_in_z)
109 
110  // set the variable to use for the coordinate axes.
111  // the defaults are: x => lon, y => lat, z = "",
112  // t => "time". leaving z empty will result in a 2D
113  // mesh.
114  TECA_ALGORITHM_PROPERTY(std::string, x_axis_variable)
115  TECA_ALGORITHM_PROPERTY(std::string, y_axis_variable)
116  TECA_ALGORITHM_PROPERTY(std::string, z_axis_variable)
117  TECA_ALGORITHM_PROPERTY(std::string, t_axis_variable)
118 
119  // time calendar and time unit if the user wants to
120  // specify them
121  TECA_ALGORITHM_PROPERTY(std::string, t_calendar)
122  TECA_ALGORITHM_PROPERTY(std::string, t_units)
123 
124  // a way to infer time from the filename if the time axis is not
125  // stored in the file itself. strftime format codes are used.
126  // For example for the files:
127  //
128  // my_file_20170516_00.nc
129  // my_file_20170516_03.nc
130  // ...
131  //
132  // the template would be
133  //
134  // my_file_%Y%m%d_%H.nc
135  TECA_ALGORITHM_PROPERTY(std::string, filename_time_template)
136 
137  // time values to use instead if time variable doesn't
138  // exist.
139  TECA_ALGORITHM_VECTOR_PROPERTY(double, t_value)
140 
141  // set/get the number of ranks used to read the time axis.
142  // the default value of 1024 ranks works well on NERSC
143  // Cori scratch file system and may not be optimal on
144  // other systems.
145  TECA_ALGORITHM_PROPERTY(int, max_metadata_ranks)
146 
147 protected:
149 
150 private:
151  void clear_cached_metadata();
152 
153  teca_metadata get_output_metadata(unsigned int port,
154  const std::vector<teca_metadata> &input_md) override;
155 
156  const_p_teca_dataset execute(unsigned int port,
157  const std::vector<const_p_teca_dataset> &input_data,
158  const teca_metadata &request) override;
159 
160  void set_modified() override;
161 
162 private:
163  std::string x_axis_variable;
164  std::string y_axis_variable;
165  std::string z_axis_variable;
166  std::string t_axis_variable;
167  std::string t_calendar;
168  std::string t_units;
169  std::string filename_time_template;
170  std::vector<double> t_values;
171  int periodic_in_x;
172  int periodic_in_y;
173  int periodic_in_z;
174  int max_metadata_ranks;
175 
176  p_teca_multi_cf_reader_internals internals;
177 };
178 
179 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_multi_cf_reader
a reader for data stored in NetCDF CF format in multiple files
Definition: teca_multi_cf_reader.h:66
teca_multi_cf_reader_internals
Definition: teca_multi_cf_reader.cxx:31
teca_algorithm
Definition: teca_algorithm.h:25