libdballe 9.6
base.h
1#ifndef DBALLE_MSG_WRIMPORTER_BASE_H
2#define DBALLE_MSG_WRIMPORTER_BASE_H
3
4#include <dballe/msg/wr_codec.h>
5#include <dballe/msg/fwd.h>
6#include <limits>
7#include <cstdint>
8
9namespace wreport {
10struct Subset;
11struct Bulletin;
12struct Var;
13}
14
15namespace dballe {
16namespace impl {
17namespace msg {
18namespace wr {
19
21{
22protected:
23 const dballe::ImporterOptions& opts;
24 const wreport::Subset* subset;
25 impl::Message* msg;
26
27 virtual void init();
28 virtual void run() = 0;
29
30 void set(const wreport::Var& var, const Shortcut& shortcut);
31 void set(const wreport::Var& var, wreport::Varcode code, const Level& level, const Trange& trange);
32
33public:
34 Importer(const dballe::ImporterOptions& opts) : opts(opts) {}
35 virtual ~Importer() {}
36
37 virtual MessageType scanType(const wreport::Bulletin& bulletin) const = 0;
38
39 void import(const wreport::Subset& subset, impl::Message& msg);
40
41 static std::unique_ptr<Importer> createSynop(const dballe::ImporterOptions&);
42 static std::unique_ptr<Importer> createShip(const dballe::ImporterOptions&);
43 static std::unique_ptr<Importer> createMetar(const dballe::ImporterOptions&);
44 static std::unique_ptr<Importer> createTemp(const dballe::ImporterOptions&);
45 static std::unique_ptr<Importer> createPilot(const dballe::ImporterOptions&);
46 static std::unique_ptr<Importer> createFlight(const dballe::ImporterOptions&);
47 static std::unique_ptr<Importer> createSat(const dballe::ImporterOptions&);
48 static std::unique_ptr<Importer> createPollution(const dballe::ImporterOptions&);
49 static std::unique_ptr<Importer> createGeneric(const dballe::ImporterOptions&);
50};
51
52class WMOImporter : public Importer
53{
54protected:
55 unsigned pos;
56
57 void import_var(const wreport::Var& var);
58
59 void init() override
60 {
61 pos = 0;
62 Importer::init();
63 }
64
65public:
66 WMOImporter(const dballe::ImporterOptions& opts) : Importer(opts) {}
67 virtual ~WMOImporter() {}
68};
69
72{
73 static constexpr double missing = std::numeric_limits<double>::max();
74 double height_baro;
75 double press_std;
76 double height_sensor;
77 double sea_depth;
78 double ground_depth;
79 bool height_sensor_seen;
80 bool swell_wave_group;
81
82 void init();
83 void peek_var(const wreport::Var& var);
84};
85
88{
89 int time_period;
90 int time_period_offset;
91 bool time_period_seen;
92 int time_sig;
93 int hour;
94 int last_B04024_pos;
95
96 void init();
97 void peek_var(const wreport::Var& var, unsigned pos);
98};
99
104{
105 Level level;
106
107 const Level& clcmch();
108
109 void init();
110 void on_vss(const wreport::Subset& subset, unsigned pos);
111};
112
126{
127 const wreport::Var* B08023 = nullptr; // First order statistics (code table)
128
129 bool is_unsupported() const;
130
131 void init();
132 void peek_var(const wreport::Var& var, unsigned pos);
133};
134
139{
141 std::unique_ptr<wreport::Var> var;
152 unsigned level_deviation = 0;
153
158 Interpreted(const Shortcut& shortcut, const wreport::Var& var);
159 Interpreted(const Shortcut& shortcut, const wreport::Var& var, const Level& level, const Trange& trange);
160 Interpreted(wreport::Varcode code, const wreport::Var& var, const Level& level, const Trange& trange);
161 virtual ~Interpreted();
162
163 virtual void set_sensor_height(const LevelContext& ctx) = 0;
164 virtual void set_barometer_height(const LevelContext& ctx) = 0;
165 virtual void set_duration(const TimerangeContext& ctx) = 0;
166 virtual void set_wind_mean(const TimerangeContext& ctx) = 0;
167};
168
170{
172 void set_sensor_height(const LevelContext& ctx) override;
173 void set_barometer_height(const LevelContext& ctx) override;
174 void set_duration(const TimerangeContext& ctx) override;
175 void set_wind_mean(const TimerangeContext& ctx) override;
176};
177
179{
181 void set_sensor_height(const LevelContext& ctx) override;
182 void set_barometer_height(const LevelContext& ctx) override;
183 void set_duration(const TimerangeContext& ctx) override;
184 void set_wind_mean(const TimerangeContext& ctx) override;
185};
186
187template<typename ...Args>
188std::unique_ptr<Interpreted> create_interpreted(bool simplified, Args&& ...args)
189{
190 if (simplified)
191 return std::unique_ptr<Interpreted>(new InterpretedSimplified(std::forward<Args>(args)...));
192 else
193 return std::unique_ptr<Interpreted>(new InterpretedPrecise(std::forward<Args>(args)...));
194}
195
200{
201protected:
202 CloudContext clouds;
203 LevelContext level;
204 TimerangeContext trange;
205 UnsupportedContext unsupported;
206 std::vector<Interpreted*> queued;
207
208 virtual void peek_var(const wreport::Var& var);
209 virtual void import_var(const wreport::Var& var);
210
211 void set_gen_sensor(const wreport::Var& var, wreport::Varcode code, const Level& defaultLevel, const Trange& trange);
212 void set_gen_sensor(const wreport::Var& var, const Shortcut& shortcut);
213 void set_baro_sensor(const wreport::Var& var, const Shortcut& shortcut);
214 void set_past_weather(const wreport::Var& var, const Shortcut& shortcut);
215 void set_wind(const wreport::Var& var, const Shortcut& shortcut);
216 void set_wind_max(const wreport::Var& var, const Shortcut& shortcut);
217 void set_pressure(const wreport::Var& var);
218 void set(const wreport::Var& var, const Shortcut& shortcut);
219 void set(const wreport::Var& var, wreport::Varcode code, const Level& level, const Trange& trange);
220 void set(std::unique_ptr<Interpreted> val);
221
222public:
225
226 void init() override;
227 void run() override;
228};
229
230}
231}
232}
233}
234#endif
Options to control message import.
Definition: importer.h:25
Storage for related physical data.
Definition: msg.h:131
Definition: base.h:21
Base class for synop, ship and other importer with synop-like data.
Definition: base.h:200
uint16_t Varcode
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:687
Definition: shortcuts.h:12
Keep track of the current cloud metadata.
Definition: base.h:104
Struct used to build an interpreted value.
Definition: base.h:139
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:141
unsigned level_deviation
Distance from the standard level to the real one.
Definition: base.h:152
Trange trange
Interpreted time range.
Definition: base.h:145
Level level
Interpreted level.
Definition: base.h:143
Keep track of level context changes.
Definition: base.h:72
Keep track of time range context changes.
Definition: base.h:88
Check if the current context state of BUFR information is something that we currently cannot handle.
Definition: base.h:126