IODA Bundle
BufrDescription.cpp
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 #include <ostream>
9 #include <memory>
10 
11 #include "eckit/exception/Exceptions.h"
12 #include "oops/util/IntSetParser.h"
13 
14 #include "BufrDescription.h"
15 #include "BufrMnemonicSet.h"
16 #include "BufrTypes.h"
17 
18 
19 namespace
20 {
21  namespace ConfKeys
22  {
23  const char* Filename = "obsdatain";
24  const char* IsWmoFormat = "isWmoFormat";
25  const char* TablePath = "tablepath";
26  const char* MnemonicSets = "mnemonicSets";
27  const char* Mnemonics = "mnemonics";
28  const char* Channels = "channels";
29  const char* Exports = "exports";
30  } // namespace ConfKeys
31 } // namespace
32 
33 namespace Ingester
34 {
35  BufrDescription::BufrDescription(const eckit::Configuration &conf) :
36  export_(Export(conf.getSubConfiguration(ConfKeys::Exports)))
37  {
38  setFilepath(conf.getString(ConfKeys::Filename));
39 
40  if (conf.has(ConfKeys::IsWmoFormat) && conf.getBool(ConfKeys::IsWmoFormat))
41  {
42  setIsWmoFormat(true);
43  }
44  else
45  {
46  setIsWmoFormat(false);
47  }
48 
49  if (conf.has(ConfKeys::TablePath))
50  {
51  setTablepath(conf.getString(ConfKeys::TablePath));
52  }
53  else
54  {
55  setTablepath("");
56  }
57 
58  if (conf.getSubConfigurations(ConfKeys::MnemonicSets).size() == 0)
59  {
60  std::stringstream errStr;
61  errStr << "bufr::mnemonicSets must contain a list of objects!";
62  throw eckit::BadParameter(errStr.str());
63  }
64 
65  for (const auto& mnemonicSetConf : conf.getSubConfigurations(ConfKeys::MnemonicSets))
66  {
67  Channels channels = {1};
68  if (mnemonicSetConf.has(ConfKeys::Channels))
69  {
70  auto intChannels = oops::parseIntSet(mnemonicSetConf.getString(ConfKeys::Channels));
71  channels = Channels(intChannels.begin(), intChannels.end());
72  }
73 
75  mnemonicSetConf.getStringVector(ConfKeys::Mnemonics), channels));
76  }
77  }
78 
80  {
81  mnemonicSets_.push_back(mnemonicSet);
82  }
83 } // namespace Ingester
std::vector< BufrMnemonicSet > mnemonicSets_
Sets of mnemonic strings for the data to read.
void setFilepath(const std::string &filepath)
void setTablepath(const std::string &tablepath)
void setIsWmoFormat(bool isWmoFormat)
void addMnemonicSet(const BufrMnemonicSet &mnemonicSet)
Add a BufrMnemonicSet to the description.
Defenition of BUFR mnemonics and associated channels of interest.
Uses configuration to determine all the things needed to be done on export.
Definition: Export.h:25
std::set< size_t > Channels
Definition: BufrTypes.h:18