IODA Bundle
BufrParser.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #pragma once
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "Eigen/Dense"
16 
17 #include "eckit/config/LocalConfiguration.h"
18 
19 #include "Parser.h"
20 #include "BufrTypes.h"
21 #include "BufrDescription.h"
22 
23 
24 namespace Ingester
25 {
26  class BufrMnemonicSet;
27  class DataContainer;
28 
29  /// \brief Uses a BufrDescription and helper classes to parse the contents of a BUFR file.
30  class BufrParser final : public Parser
31  {
32  public:
33  explicit BufrParser(const BufrDescription& description);
34  explicit BufrParser(const eckit::Configuration& conf);
35 
36  ~BufrParser();
37 
38  /// \brief Uses the provided description to parse the buffer file.
39  /// \param maxMsgsToParse Messages to parse (0 for everything)
40  std::shared_ptr<DataContainer> parse(const size_t maxMsgsToParse = 0) final;
41 
42  /// \brief Start over from beginning of the BUFR file
43  void reset() final;
44 
45  private:
46  typedef std::map<std::vector<std::string>, BufrDataMap> CatDataMap;
47 
48  /// \brief The description the defines what to parse from the BUFR file
50 
51  /// \brief The Fortran file ID to an open BUFR file (0 when no file open)
52  unsigned int fortranFileId_;
53 
54  /// \brief The Fortran file ID to an open BUFR file (0 when no file open)
55  unsigned int table1FileId_;
56 
57  /// \brief The Fortran file ID to an open BUFR file (0 when no file open)
58  unsigned int table2FileId_;
59 
60  /// \brief Exports collected data into a DataContainer
61  /// \param srcData Data to export
62  std::shared_ptr<DataContainer> exportData(const BufrDataMap& srcData);
63 
64  /// \brief Function responsible for dividing the data into subcategories.
65  /// \details This function is intended to be called over and over for each specified Split
66  /// object, sub-splitting the data given into all the possible subcategories.
67  /// \param splitMaps Pre-split map of data.
68  /// \param split Object that knows how to split data.
69  CatDataMap splitData(CatDataMap& splitMaps, Split& split);
70 
71  /// \brief Opens a BUFR file using the Fortran BUFR interface.
72  /// \param filepath Path to bufr file.
73  /// \param isWmoFormat _optional_ Bufr file is in the standard format.
74  /// \param tablepath _optional_ Path to WMO master tables (needed for standard bufr files).
75  void
76  openBufrFile(const std::string& filepath, bool isWmoFormat, const std::string& tablepath);
77 
78  /// \brief Closes the open BUFR file.
79  void closeBufrFile();
80 
81  /// \brief Convenience method to print the Categorical data map to stdout.
82  void printMap(const CatDataMap& map);
83  };
84 } // namespace Ingester
Description of the data to be read from a BUFR file and how to expose that data to the outside world.
Uses a BufrDescription and helper classes to parse the contents of a BUFR file.
Definition: BufrParser.h:31
void closeBufrFile()
Closes the open BUFR file.
Definition: BufrParser.cpp:175
unsigned int fortranFileId_
The Fortran file ID to an open BUFR file (0 when no file open)
Definition: BufrParser.h:52
void printMap(const CatDataMap &map)
Convenience method to print the Categorical data map to stdout.
Definition: BufrParser.cpp:196
BufrDescription description_
The description the defines what to parse from the BUFR file.
Definition: BufrParser.h:49
unsigned int table2FileId_
The Fortran file ID to an open BUFR file (0 when no file open)
Definition: BufrParser.h:58
std::map< std::vector< std::string >, BufrDataMap > CatDataMap
Definition: BufrParser.h:46
CatDataMap splitData(CatDataMap &splitMaps, Split &split)
Function responsible for dividing the data into subcategories.
Definition: BufrParser.cpp:132
std::shared_ptr< DataContainer > exportData(const BufrDataMap &srcData)
Exports collected data into a DataContainer.
Definition: BufrParser.cpp:83
std::shared_ptr< DataContainer > parse(const size_t maxMsgsToParse=0) final
Uses the provided description to parse the buffer file.
Definition: BufrParser.cpp:54
void reset() final
Start over from beginning of the BUFR file.
Definition: BufrParser.cpp:184
void openBufrFile(const std::string &filepath, bool isWmoFormat, const std::string &tablepath)
Opens a BUFR file using the Fortran BUFR interface.
Definition: BufrParser.cpp:151
unsigned int table1FileId_
The Fortran file ID to an open BUFR file (0 when no file open)
Definition: BufrParser.h:55
BufrParser(const BufrDescription &description)
Definition: BufrParser.cpp:31
Base class for all input Parsers.
Definition: Parser.h:18
Base class for all Split objects that split data into sub-parts.
Definition: Split.h:19
IngesterArrayMap BufrDataMap
Definition: BufrTypes.h:21