14 #include "eckit/exception/Exceptions.h"
16 #if __has_include("bufr_interface.h")
17 #include "bufr_interface.h"
19 #include "bufr.interface.h"
32 description_(description),
56 const unsigned int SubsetStringLength = 25;
60 throw eckit::BadValue(
"Fortran File ID is an invalid number (must be > 10).");
66 char subset[SubsetStringLength];
69 unsigned int messageNum = 0;
77 if (maxMsgsToParse > 0 && ++messageNum >= maxMsgsToParse)
break;
88 auto splitMap = exportDescription.getSplits();
89 auto varMap = exportDescription.getVariables();
93 for (
const auto& filter : filters)
95 filter->apply(dataCopy);
100 for (
const auto& splitPair : splitMap)
102 std::ostringstream catName;
103 catName <<
"splits/" << splitPair.first;
104 catMap.insert({catName.str(), splitPair.second->subCategories(dataCopy)});
108 splitDataMaps.insert({std::vector<std::string>(), dataCopy});
109 for (
const auto& splitPair : splitMap)
111 splitDataMaps =
splitData(splitDataMaps, *splitPair.second);
115 auto exportData = std::make_shared<DataContainer>(catMap);
116 for (
const auto& dataPair : splitDataMaps)
118 for (
const auto& varPair : varMap)
120 std::ostringstream pathStr;
121 pathStr <<
"variables/" << varPair.first;
124 varPair.second->exportData(dataPair.second),
136 for (
const auto& splitMapPair : splitMaps)
138 auto newData = split.
split(splitMapPair.second);
140 for (
const auto& newDataPair : newData)
142 auto catVect = splitMapPair.first;
143 catVect.push_back(newDataPair.first);
144 splitDataMap.insert({catVect, newDataPair.second});
153 const std::string& tablepath)
166 if (!tablepath.empty())
198 for (
const auto &mp : map)
200 std::cout <<
" keys: ";
201 for (
const auto &s : mp.first)
206 std::cout <<
" subkeys: ";
207 for (
const auto &m2p : mp.second)
209 std::cout << m2p.first <<
" " << m2p.second.rows() <<
" ";
212 std::cout << std::endl;
Description of the data to be read from a BUFR file and how to expose that data to the outside world.
std::vector< BufrMnemonicSet > getMnemonicSets() const
std::string tablepath() const
std::string filepath() const
void closeBufrFile()
Closes the open BUFR file.
unsigned int fortranFileId_
The Fortran file ID to an open BUFR file (0 when no file open)
void printMap(const CatDataMap &map)
Convenience method to print the Categorical data map to stdout.
BufrDescription description_
The description the defines what to parse from the BUFR file.
unsigned int table2FileId_
The Fortran file ID to an open BUFR file (0 when no file open)
std::map< std::vector< std::string >, BufrDataMap > CatDataMap
CatDataMap splitData(CatDataMap &splitMaps, Split &split)
Function responsible for dividing the data into subcategories.
std::shared_ptr< DataContainer > exportData(const BufrDataMap &srcData)
Exports collected data into a DataContainer.
std::shared_ptr< DataContainer > parse(const size_t maxMsgsToParse=0) final
Uses the provided description to parse the buffer file.
void reset() final
Start over from beginning of the BUFR file.
void openBufrFile(const std::string &filepath, bool isWmoFormat, const std::string &tablepath)
Opens a BUFR file using the Fortran BUFR interface.
unsigned int table1FileId_
The Fortran file ID to an open BUFR file (0 when no file open)
BufrParser(const BufrDescription &description)
Filters getFilters() const
Base class for all Split objects that split data into sub-parts.
virtual std::map< std::string, BufrDataMap > split(const BufrDataMap &dataMap)=0
Split the data according to internal rules.
std::map< std::string, SubCategory > CategoryMap
Map of data set id's to vector of possible value strings.
IngesterArrayMap BufrDataMap
def subset(infile, nlocsout, suffix, geofile, diagfile)