TECA
teca_cf_reader.h
1 #ifndef teca_cf_reader_h
2 #define teca_cf_reader_h
3 
4 #include "teca_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_shared_object.h"
7 
8 #include <vector>
9 #include <string>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cf_reader)
12 
14 using p_teca_cf_reader_internals = std::shared_ptr<teca_cf_reader_internals>;
15 
17 
52 {
53 public:
54  TECA_ALGORITHM_STATIC_NEW(teca_cf_reader)
55  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_cf_reader)
56  TECA_ALGORITHM_CLASS_NAME(teca_cf_reader)
57  ~teca_cf_reader();
58 
59  // report/initialize to/from Boost program options
60  // objects.
61  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
62  TECA_SET_ALGORITHM_PROPERTIES()
63 
64  // list of file names to open. if this is set the files_regex
65  // is ignored.
66  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, file_name)
67 
68  // describe the set of files comprising the dataset. This
69  // should contain the full path and regex describing the
70  // file name pattern. only the final component of a path
71  // can contain a regex.
72  TECA_ALGORITHM_PROPERTY(std::string, files_regex)
73 
74  // set if the dataset has periodic boundary conditions
75  TECA_ALGORITHM_PROPERTY(int, periodic_in_x)
76  TECA_ALGORITHM_PROPERTY(int, periodic_in_y)
77  TECA_ALGORITHM_PROPERTY(int, periodic_in_z)
78 
79  // set the variable to use for the coordinate axes.
80  // the defaults are: x => lon, y => lat, z = "",
81  // t => "time". leaving z empty will result in a 2D
82  // mesh.
83  TECA_ALGORITHM_PROPERTY(std::string, x_axis_variable)
84  TECA_ALGORITHM_PROPERTY(std::string, y_axis_variable)
85  TECA_ALGORITHM_PROPERTY(std::string, z_axis_variable)
86  TECA_ALGORITHM_PROPERTY(std::string, t_axis_variable)
87 
88  // Override the calendar and time unit. When these are specified
89  // their values take precedence over the values found in the file.
90  TECA_ALGORITHM_PROPERTY(std::string, t_calendar)
91  TECA_ALGORITHM_PROPERTY(std::string, t_units)
92 
93  // a way to infer time from the filename if the time axis is not
94  // stored in the file itself. std::get_time format codes are used.
95  // If a calendar is not specified then the standard calendar is
96  // used. If time units are not specified then the time units will
97  // be "days since %Y-%m-%d 00:00:00" where Y,m, and d are computed
98  // from the filename of the first file. set t_axis_variable to an
99  // empty string to use.
100  //
101  // For example, for the list of files:
102  //
103  // my_file_20170516_00.nc
104  // my_file_20170516_03.nc
105  // ...
106  //
107  // the template would be
108  //
109  // my_file_%Y%m%d_%H.nc
110  TECA_ALGORITHM_PROPERTY(std::string, filename_time_template)
111 
112  // an explicit list of double precision time values to use.
113  // set t_axis_variable to an empty string to use.
114  TECA_ALGORITHM_VECTOR_PROPERTY(double, t_value)
115 
116  // set/get the number of ranks used to read the time axis.
117  // the default value of 1024 ranks works well on NERSC
118  // Cori scratch file system and may not be optimal on
119  // other systems.
120  TECA_ALGORITHM_PROPERTY(int, max_metadata_ranks)
121 
122 protected:
123  teca_cf_reader();
124  void clear_cached_metadata();
125 
126 private:
127  teca_metadata get_output_metadata(
128  unsigned int port,
129  const std::vector<teca_metadata> &input_md) override;
130 
131  const_p_teca_dataset execute(
132  unsigned int port,
133  const std::vector<const_p_teca_dataset> &input_data,
134  const teca_metadata &request) override;
135 
136  virtual void set_modified() override;
137 
138 private:
139  std::vector<std::string> file_names;
140  std::string files_regex;
141  std::string x_axis_variable;
142  std::string y_axis_variable;
143  std::string z_axis_variable;
144  std::string t_axis_variable;
145  std::string t_calendar;
146  std::string t_units;
147  std::string filename_time_template;
148  std::vector<double> t_values;
149  int periodic_in_x;
150  int periodic_in_y;
151  int periodic_in_z;
152  int max_metadata_ranks;
153  p_teca_cf_reader_internals internals;
154 };
155 
156 #endif
teca_cf_reader
a reader for data stored in NetCDF CF format
Definition: teca_cf_reader.h:52
teca_metadata
Definition: teca_metadata.h:17
teca_cf_reader_internals
Definition: teca_cf_reader.cxx:45
teca_algorithm
Definition: teca_algorithm.h:25