libdballe  7.6
base.h
1 /*
2  * dballe/wr_importers/base - Base infrastructure for wreport importers
3  *
4  * Copyright (C) 2005--2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBALLE_MSG_WRIMPORTER_BASE_H
23 #define DBALLE_MSG_WRIMPORTER_BASE_H
24 
25 #include <dballe/msg/wr_codec.h>
26 #include <dballe/msg/msg.h>
27 #include <stdint.h>
28 
29 namespace wreport {
30 struct Subset;
31 struct Bulletin;
32 struct Var;
33 }
34 
35 namespace dballe {
36 namespace msg {
37 namespace wr {
38 
39 class Importer
40 {
41 protected:
42  const msg::Importer::Options& opts;
43  const wreport::Subset* subset;
44  Msg* msg;
45  int ye, mo, da, ho, mi, se;
46 
47  virtual void init();
48  virtual void run() = 0;
49 
50 public:
51  Importer(const msg::Importer::Options& opts) : opts(opts) {}
52  virtual ~Importer() {}
53 
54  virtual MsgType scanType(const wreport::Bulletin& bulletin) const = 0;
55 
56  void import(const wreport::Subset& subset, Msg& msg);
57 
58  static std::unique_ptr<Importer> createSynop(const msg::Importer::Options&);
59  static std::unique_ptr<Importer> createShip(const msg::Importer::Options&);
60  static std::unique_ptr<Importer> createMetar(const msg::Importer::Options&);
61  static std::unique_ptr<Importer> createTemp(const msg::Importer::Options&);
62  static std::unique_ptr<Importer> createPilot(const msg::Importer::Options&);
63  static std::unique_ptr<Importer> createFlight(const msg::Importer::Options&);
64  static std::unique_ptr<Importer> createSat(const msg::Importer::Options&);
65  static std::unique_ptr<Importer> createPollution(const msg::Importer::Options&);
66  static std::unique_ptr<Importer> createGeneric(const msg::Importer::Options&);
67 };
68 
69 class WMOImporter : public Importer
70 {
71 protected:
72  unsigned pos;
73 
74  void import_var(const wreport::Var& var);
75 
76  virtual void init()
77  {
78  pos = 0;
79  Importer::init();
80  }
81 
82 public:
83  WMOImporter(const msg::Importer::Options& opts) : Importer(opts) {}
84  virtual ~WMOImporter() {}
85 };
86 
89 {
90  double height_baro;
91  double press_std;
92  double height_sensor;
93  double depth;
94  bool height_sensor_seen;
95  bool swell_wave_group;
96 
97  void init();
98  void peek_var(const wreport::Var& var);
99 };
100 
103 {
104  int time_period;
105  int time_period_offset;
106  bool time_period_seen;
107  int time_sig;
108  int hour;
109  int last_B04024_pos;
110 
111  void init();
112  void peek_var(const wreport::Var& var, unsigned pos);
113 };
114 
119 {
120  Level level;
121 
122  const Level& clcmch();
123 
124  void init();
125  void on_vss(const wreport::Subset& subset, unsigned pos);
126 };
127 
129 {
130  const LevelContext& level;
131  const TimerangeContext& trange;
132 
133  // Configuration
134  bool simplified;
135 
136  // Import builder parts
137  const MsgVarShortcut* v;
138  wreport::Var* var;
139  Level chosen_lev;
140  Trange chosen_tr;
141 
142  // Output message
143  Msg* msg;
144 
145  ContextChooser(const LevelContext& level, const TimerangeContext& trange);
146  ~ContextChooser();
147 
148  void init(Msg& msg, bool simplified);
149 
150  void set_gen_sensor(const wreport::Var& var, wreport::Varcode code, const Level& defaultLevel, const Trange& trange);
151  void set_gen_sensor(const wreport::Var& var, int shortcut);
152  void set_gen_sensor(const wreport::Var& var, int shortcut, const Trange& tr_std, bool tr_careful=false);
153  void set_gen_sensor(const wreport::Var& var, int shortcut, const Level& lev_std, const Trange& tr_std, bool lev_careful=false, bool tr_careful=false);
154  void set_baro_sensor(const wreport::Var& var, int shortcut);
155  void set_past_weather(const wreport::Var& var, int shortcut);
156  void set_wind(const wreport::Var& var, int shortcut);
157  void set_wind_max(const wreport::Var& var, int shortcut);
158  void set_pressure(const wreport::Var& var);
159  void set_water_temperature(const wreport::Var& var);
160  void set_swell_waves(const wreport::Var& var);
161 
162 protected:
163  void ib_start(int shortcut, const wreport::Var& var);
164  Level lev_real(const Level& standard) const;
165  Trange tr_real(const Trange& standard) const;
166  Level lev_shortcut() const { return Level(v->ltype1, v->l1, v->ltype2, v->l2); }
167  Trange tr_shortcut() const { return Trange(v->pind, v->p1, v->p2); }
168  void ib_annotate_level();
169  void ib_annotate_trange();
170  void ib_level_use_real(const Level& standard) { chosen_lev = lev_real(standard); }
171  void ib_trange_use_real(const Trange& standard) { chosen_tr = tr_real(standard); }
172  void ib_level_use_shorcut_and_discard_rest() { chosen_lev = lev_shortcut(); }
173  void ib_trange_use_shortcut_and_discard_rest() { chosen_tr = tr_shortcut(); }
174  void ib_level_use_shorcut_and_preserve_rest(const Level& standard);
175  void ib_trange_use_shorcut_and_preserve_rest(const Trange& standard);
176  void ib_level_use_standard_and_preserve_rest(const Level& standard);
177  void ib_trange_use_standard_and_preserve_rest(const Trange& standard);
178  void ib_level_use_shorcut_if_standard_else_real(const Level& standard);
179  void ib_trange_use_shorcut_if_standard_else_real(const Trange& standard);
180  void ib_set();
181 };
182 
187 {
188 protected:
189  CloudContext clouds;
190  LevelContext level;
191  TimerangeContext trange;
192  ContextChooser ctx;
193 
194  virtual void peek_var(const wreport::Var& var);
195  virtual void import_var(const wreport::Var& var);
196 
197 public:
199 
200  virtual void init();
201  virtual void run();
202 };
203 
204 } // namespace wr
205 } // namespace msg
206 } // namespace dballe
207 
208 /* vim:set ts=4 sw=4: */
209 #endif
Definition: base.h:39
Storage for related physical data.
Definition: msg.h:133
int p2
Time range P2 indicator.
Definition: vars.h:38
Definition: codec.h:35
Definition: base.h:69
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:565
Keep track of level context changes.
Definition: base.h:88
Definition: base.h:128
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
int l2
L2 value of the level.
Definition: vars.h:32
Vertical level or layer.
Definition: types.h:515
int p1
Time range P1 indicator.
Definition: vars.h:36
Abstraction for a weather report message which is independent from the encoding, used to make sense o...
Keep track of the current cloud metadata.
Definition: base.h:118
int ltype2
Type of the second level.
Definition: vars.h:30
Full data corresponding to a shortcut ID.
Definition: vars.h:22
Keep track of time range context changes.
Definition: base.h:102
int ltype1
Type of the first level.
Definition: vars.h:26
Definition: conversion.h:6
int l1
L1 value of the level.
Definition: vars.h:28
Base class for synop, ship and other importer with synop-like data.
Definition: base.h:186
MsgType
Source of the data.
Definition: msg.h:104
int pind
Time range type indicator.
Definition: vars.h:34