OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
FileReader.hpp
Go to the documentation of this file.
1 
2 #ifndef FOCS_FILEREADER
3 #define FOCS_FILEREADER
4 
5 #include <array>
6 #include <cstdio>
7 #include <string>
8 #include <unordered_map>
9 
10 #include <boost/filesystem.hpp>
11 
12 #include "DataProvider.hpp"
13 #include "DataRecord.hpp"
14 
15 namespace focs {
16 
17 extern const std::array<int, 4> NETCDF1_MAGIC_NUMBER;
18 extern const std::array<int, 4> NETCDF2_MAGIC_NUMBER;
19 extern const std::array<int, 4> HDF4_MAGIC_NUMBER;
20 extern const std::array<int, 8> HDF5_MAGIC_NUMBER;
21 
22 // Everything that writes to hints.attributes_ is performing a copy (of what they're adding). Switch to smart pointers?
24  public:
25  FileReaderHints() = default;
26  explicit FileReaderHints(const std::string& path);
27 
28  bool magic_number(const std::string& bytes) const noexcept;
29  template<std::size_t N> bool magic_number(const std::array<int, N>& bytes) const noexcept;
30 
31  const std::array<int, 8>& first_bytes() const noexcept {return first_bytes_;}
32  void first_bytes(const std::array<int, 8>& bytes){first_bytes_ = bytes;}
33 
34  uintmax_t size() const noexcept {return size_;}
35  void size(uintmax_t size){size_ = size;}
36 
37  const std::string& filename() const noexcept {return filename_;}
38  void filename(const std::string& filename){filename_ = filename;}
39 
40  const std::string& format() const noexcept {return format_;}
41  void format(const std::string& format){format_ = format;}
42 
43  auto& attributes(){return attributes_;}
44 
45  bool is_hdf4() const noexcept;
46  bool is_hdf5() const noexcept;
47  bool is_netcdf() const noexcept;
48  private:
49  std::string filename_{};
50  std::array<int, 8> first_bytes_{{0, 0, 0, 0, 0, 0, 0, 0}};
51  uintmax_t size_{0};
52  std::string format_{"unknown"};
53  std::unordered_map<std::string, std::string> attributes_{};
54 };
55 class FileReader : public DataProvider {
56  public:
59 
60  enum validity {
62  };
63  virtual ~FileReader() override {}
64 
65  // virtual const std::vector<Product>& provides() const override;
66  virtual std::vector<std::shared_ptr<Product>>& needs() override; // returns empty
67 
68  // TODO: undefine these empty ones, it's not compiling without them for some reason
69  virtual validity is_valid_file(const std::string& file, FileReaderHints& hints){(void)file; (void)hints; return invalid;}
71  FileReaderHints hints{file};
72  return is_valid_file(file, hints);
73  }
74 
75  virtual std::unique_ptr<FileReader> initialize_reader(DataProviderConfiguration& configuration, const boost::filesystem::path& path) = 0;
76 
77  virtual TileParameters read_next_tile(DataProviderConfiguration& configuration, DataRecord& record){(void)configuration; (void)record; return {0,0}; } // true on finished? For now.
78 };
79 
80 
81 } // namespace focs
82 
83 #endif // FOCS_FILEREADER
84 
virtual std::vector< std::shared_ptr< Product > > & needs() override
validity is_valid_file(const std::string &file)
Definition: FileReader.hpp:70
void first_bytes(const std::array< int, 8 > &bytes)
Definition: FileReader.hpp:32
FileReader(const std::string &name, const std::string &description)
Definition: FileReader.hpp:57
const std::array< int, 4 > NETCDF1_MAGIC_NUMBER
bool is_hdf4() const noexcept
const std::string & name() const
FileReader(const std::string &name)
Definition: FileReader.hpp:58
const std::array< int, 4 > HDF4_MAGIC_NUMBER
bool is_hdf5() const noexcept
@ string
const std::string & filename() const noexcept
Definition: FileReader.hpp:37
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
const std::string & format() const noexcept
Definition: FileReader.hpp:40
virtual std::unique_ptr< FileReader > initialize_reader(DataProviderConfiguration &configuration, const boost::filesystem::path &path)=0
void size(uintmax_t size)
Definition: FileReader.hpp:35
const std::array< int, 8 > HDF5_MAGIC_NUMBER
virtual validity is_valid_file(const std::string &file, FileReaderHints &hints)
Definition: FileReader.hpp:69
string path
Definition: color_dtdb.py:221
virtual ~FileReader() override
Definition: FileReader.hpp:63
bool magic_number(const std::string &bytes) const noexcept
void format(const std::string &format)
Definition: FileReader.hpp:41
void filename(const std::string &filename)
Definition: FileReader.hpp:38
virtual TileParameters read_next_tile(DataProviderConfiguration &configuration, DataRecord &record)
Definition: FileReader.hpp:77
bool is_netcdf() const noexcept
const std::array< int, 4 > NETCDF2_MAGIC_NUMBER
const std::string & description() const
uintmax_t size() const noexcept
Definition: FileReader.hpp:34
const std::array< int, 8 > & first_bytes() const noexcept
Definition: FileReader.hpp:31