IODA Bundle
bufr2ioda.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 <string>
9 #include <iostream>
10 #include <ostream>
11 #include <iomanip>
12 
13 #include "eckit/config/YAMLConfiguration.h"
14 #include "eckit/exception/Exceptions.h"
15 #include "eckit/filesystem/PathName.h"
16 
19 #include "BufrParser/BufrParser.h"
22 #include "DataContainer.h"
23 
24 #include "ParserFactory.h"
25 
26 
27 namespace Ingester
28 {
29  void parse(std::string yamlPath)
30  {
31  std::unique_ptr<eckit::YAMLConfiguration>
32  yaml(new eckit::YAMLConfiguration(eckit::PathName(yamlPath)));
33 
34  if (yaml->has("observations"))
35  {
36  for (const auto& obsConf : yaml->getSubConfigurations("observations"))
37  {
38  if (!obsConf.has("obs space") ||
39  !obsConf.has("ioda"))
40  {
41  eckit::BadParameter(
42  "Incomplete obs found. All obs must have a obs space and ioda.");
43  }
44 
45  auto parser = ParserFactory::create(obsConf.getSubConfiguration("obs space"));
46  auto data = parser->parse();
47 
48  auto encoder = IodaEncoder(obsConf.getSubConfiguration("ioda"));
49  encoder.encode(data);
50  }
51  }
52  else
53  {
54  eckit::BadParameter("No section named \"observations\"");
55  }
56  }
57 
59  {
60  ParserFactory::registerParser<BufrParser>("bufr");
61  }
62 } // namespace Ingester
63 
64 
65 int main(int argc, char **argv)
66 {
67  if (argc < 2)
68  {
69  eckit::BadParameter("Missing argument. Must include YAML file path.");
70  }
71 
73  Ingester::parse(std::string(argv[1]));
74 
75  return 0;
76 }
77 
int main(int argc, char **argv)
Definition: bufr2ioda.cpp:65
Uses IodaDescription and parsed data to create IODA data.
Definition: IodaEncoder.h:25
static std::shared_ptr< Parser > create(const eckit::Configuration &conf)
Create a Parser.
Definition: ParserFactory.h:58
void registerParsers()
Definition: bufr2ioda.cpp:58
void parse(std::string yamlPath)
Definition: bufr2ioda.cpp:29