libdballe 9.13
base.h
1#ifndef DBALLE_MSG_WRIMPORTER_BASE_H
2#define DBALLE_MSG_WRIMPORTER_BASE_H
3
4#include <cstdint>
5#include <dballe/msg/fwd.h>
6#include <dballe/msg/wr_codec.h>
7#include <limits>
8
9namespace wreport {
10struct Subset;
11struct Bulletin;
12struct Var;
13} // namespace wreport
14
15namespace dballe {
16namespace impl {
17namespace msg {
18namespace wr {
19
20class Importer
21{
22protected:
23 const dballe::ImporterOptions& opts;
24 const wreport::Bulletin* bulletin;
25 const wreport::Subset* subset;
26 impl::Message* msg;
27
28 virtual void init();
29 virtual void run();
30 virtual void postprocess();
31
32 void set(const wreport::Var& var, const Shortcut& shortcut);
33 void set(const wreport::Var& var, wreport::Varcode code, const Level& level,
34 const Trange& trange);
35
36public:
37 Importer(const dballe::ImporterOptions& opts) : opts(opts) {}
38 virtual ~Importer() {}
39
40 virtual MessageType scanType(const wreport::Bulletin& bulletin) const = 0;
41
42 void import_subset(const wreport::Bulletin& bulletin,
43 const wreport::Subset& subset, impl::Message& msg);
44
45 static std::unique_ptr<Importer>
46 createSynop(const dballe::ImporterOptions&);
47 static std::unique_ptr<Importer> createShip(const dballe::ImporterOptions&);
48 static std::unique_ptr<Importer>
49 createMetar(const dballe::ImporterOptions&);
50 static std::unique_ptr<Importer> createTemp(const dballe::ImporterOptions&);
51 static std::unique_ptr<Importer>
52 createPilot(const dballe::ImporterOptions&);
53 static std::unique_ptr<Importer>
54 createFlight(const dballe::ImporterOptions&);
55 static std::unique_ptr<Importer> createSat(const dballe::ImporterOptions&);
56 static std::unique_ptr<Importer>
57 createPollution(const dballe::ImporterOptions&);
58 static std::unique_ptr<Importer>
59 createGeneric(const dballe::ImporterOptions&);
60};
61
62class WMOImporter : public Importer
63{
64protected:
65 unsigned pos;
66
67 void import_var(const wreport::Var& var);
68
69 void init() override
70 {
71 pos = 0;
72 Importer::init();
73 }
74
75public:
76 WMOImporter(const dballe::ImporterOptions& opts) : Importer(opts) {}
77 ~WMOImporter() override {}
78};
79
82{
83 static constexpr double missing = std::numeric_limits<double>::max();
84 double height_baro;
85 double press_std;
86 double height_sensor;
87 double sea_depth;
88 double ground_depth;
89 bool height_sensor_seen;
90 bool swell_wave_group;
91
92 void init();
93 void peek_var(const wreport::Var& var);
94};
95
98{
99 int time_period;
100 int time_period_offset;
101 bool time_period_seen;
102 int time_sig;
103 int hour;
104 int last_B04024_pos;
105
106 void init();
107 void peek_var(const wreport::Var& var, unsigned pos);
108};
109
114{
115 Level level;
116
117 const Level& clcmch();
118
119 void init();
120 void on_vss(const wreport::Subset& subset, unsigned pos);
121};
122
136{
137 const wreport::Var* B08023 = nullptr; // First order statistics (code table)
138
139 bool is_unsupported() const;
140
141 void init();
142 void peek_var(const wreport::Var& var, unsigned pos);
143};
144
149{
151 std::unique_ptr<wreport::Var> var;
162 unsigned level_deviation = 0;
163
168 Interpreted(const Shortcut& shortcut, const wreport::Var& var);
169 Interpreted(const Shortcut& shortcut, const wreport::Var& var,
170 const Level& level, const Trange& trange);
171 Interpreted(wreport::Varcode code, const wreport::Var& var,
172 const Level& level, const Trange& trange);
173 virtual ~Interpreted();
174
175 virtual void set_sensor_height(const LevelContext& ctx) = 0;
176 virtual void set_barometer_height(const LevelContext& ctx) = 0;
177 virtual void set_duration(const TimerangeContext& ctx) = 0;
178 virtual void set_wind_mean(const TimerangeContext& ctx) = 0;
179};
180
182{
184 void set_sensor_height(const LevelContext& ctx) override;
185 void set_barometer_height(const LevelContext& ctx) override;
186 void set_duration(const TimerangeContext& ctx) override;
187 void set_wind_mean(const TimerangeContext& ctx) override;
188};
189
191{
193 void set_sensor_height(const LevelContext& ctx) override;
194 void set_barometer_height(const LevelContext& ctx) override;
195 void set_duration(const TimerangeContext& ctx) override;
196 void set_wind_mean(const TimerangeContext& ctx) override;
197};
198
199template <typename... Args>
200std::unique_ptr<Interpreted> create_interpreted(bool simplified, Args&&... args)
201{
202 if (simplified)
203 return std::unique_ptr<Interpreted>(
204 new InterpretedSimplified(std::forward<Args>(args)...));
205 else
206 return std::unique_ptr<Interpreted>(
207 new InterpretedPrecise(std::forward<Args>(args)...));
208}
209
213class SynopBaseImporter : public WMOImporter
214{
215protected:
216 CloudContext clouds;
217 LevelContext level;
218 TimerangeContext trange;
219 UnsupportedContext unsupported;
220 std::vector<Interpreted*> queued;
221
222 virtual void peek_var(const wreport::Var& var);
223 virtual void import_var(const wreport::Var& var);
224
225 void set_gen_sensor(const wreport::Var& var, wreport::Varcode code,
226 const Level& defaultLevel, const Trange& trange);
227 void set_gen_sensor(const wreport::Var& var, const Shortcut& shortcut);
228 void set_baro_sensor(const wreport::Var& var, const Shortcut& shortcut);
229 void set_past_weather(const wreport::Var& var, const Shortcut& shortcut);
230 void set_wind(const wreport::Var& var, const Shortcut& shortcut);
231 void set_wind_max(const wreport::Var& var, const Shortcut& shortcut);
232 void set_pressure(const wreport::Var& var);
233 void set(const wreport::Var& var, const Shortcut& shortcut);
234 void set(const wreport::Var& var, wreport::Varcode code, const Level& level,
235 const Trange& trange);
236 void set(std::unique_ptr<Interpreted> val);
237
238public:
239 explicit SynopBaseImporter(const dballe::ImporterOptions& opts);
240 ~SynopBaseImporter() override;
241
242 void init() override;
243 void run() override;
244};
245
246} // namespace wr
247} // namespace msg
248} // namespace impl
249} // namespace dballe
250#endif
Options to control message import.
Definition importer.h:25
Storage for related physical data.
Definition msg.h:134
Vertical level or layer.
Definition types.h:625
Information on how a value has been sampled or computed with regards to time.
Definition types.h:689
Definition shortcuts.h:12
Keep track of the current cloud metadata.
Definition base.h:114
Interpreted(const Shortcut &shortcut, const wreport::Var &var)
Beging building using a copy of var, and level and timerange from shortcut.
Interpreted(const Shortcut &shortcut, const wreport::Var &var)
Beging building using a copy of var, and level and timerange from shortcut.
Interpreted(const Shortcut &shortcut, const wreport::Var &var)
Beging building using a copy of var, and level and timerange from shortcut.
std::unique_ptr< wreport::Var > var
Interpreted value being built.
Definition base.h:151
unsigned level_deviation
Distance from the standard level to the real one.
Definition base.h:162
Trange trange
Interpreted time range.
Definition base.h:155
Level level
Interpreted level.
Definition base.h:153
Keep track of level context changes.
Definition base.h:82
Keep track of time range context changes.
Definition base.h:98
Check if the current context state of BUFR information is something that we currently cannot handle.
Definition base.h:136