libdballe  6.8
base.h
1 /*
2  * dballe/wr_importers/base - Base infrastructure for wreport importers
3  *
4  * Copyright (C) 2005--2013 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 
46  virtual void init() {}
47  virtual void run() = 0;
48 
49 public:
50  Importer(const msg::Importer::Options& opts) : opts(opts) {}
51  virtual ~Importer() {}
52 
53  virtual MsgType scanType(const wreport::Bulletin& bulletin) const = 0;
54 
55  void import(const wreport::Subset& subset, Msg& msg)
56  {
57  this->subset = &subset;
58  this->msg = &msg;
59  init();
60  run();
61  }
62 
63  static std::auto_ptr<Importer> createSynop(const msg::Importer::Options&);
64  static std::auto_ptr<Importer> createShip(const msg::Importer::Options&);
65  static std::auto_ptr<Importer> createMetar(const msg::Importer::Options&);
66  static std::auto_ptr<Importer> createTemp(const msg::Importer::Options&);
67  static std::auto_ptr<Importer> createPilot(const msg::Importer::Options&);
68  static std::auto_ptr<Importer> createFlight(const msg::Importer::Options&);
69  static std::auto_ptr<Importer> createSat(const msg::Importer::Options&);
70  static std::auto_ptr<Importer> createPollution(const msg::Importer::Options&);
71  static std::auto_ptr<Importer> createGeneric(const msg::Importer::Options&);
72 };
73 
74 class WMOImporter : public Importer
75 {
76 protected:
77  unsigned pos;
78 
79  void import_var(const wreport::Var& var);
80 
81  virtual void init()
82  {
83  pos = 0;
84  Importer::init();
85  }
86 
87 public:
88  WMOImporter(const msg::Importer::Options& opts) : Importer(opts) {}
89  virtual ~WMOImporter() {}
90 };
91 
94 {
95  double height_baro;
96  double press_std;
97  double height_sensor;
98  double depth;
99  bool height_sensor_seen;
100  bool swell_wave_group;
101 
102  void init();
103  void peek_var(const wreport::Var& var);
104 };
105 
108 {
109  int time_period;
110  int time_period_offset;
111  bool time_period_seen;
112  int time_sig;
113  int hour;
114  int last_B04024_pos;
115 
116  void init();
117  void peek_var(const wreport::Var& var, unsigned pos);
118 };
119 
124 {
125  Level level;
126 
127  const Level& clcmch();
128 
129  void init();
130  void on_vss(const wreport::Subset& subset, unsigned pos);
131 };
132 
134 {
135  const LevelContext& level;
136  const TimerangeContext& trange;
137 
138  // Configuration
139  bool simplified;
140 
141  // Import builder parts
142  const MsgVarShortcut* v;
143  wreport::Var* var;
144  Level chosen_lev;
145  Trange chosen_tr;
146 
147  // Output message
148  Msg* msg;
149 
150  ContextChooser(const LevelContext& level, const TimerangeContext& trange);
151  ~ContextChooser();
152 
153  void init(Msg& msg, bool simplified);
154 
155  void set_gen_sensor(const wreport::Var& var, wreport::Varcode code, const Level& defaultLevel, const Trange& trange);
156  void set_gen_sensor(const wreport::Var& var, int shortcut);
157  void set_gen_sensor(const wreport::Var& var, int shortcut, const Trange& tr_std, bool tr_careful=false);
158  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);
159  void set_baro_sensor(const wreport::Var& var, int shortcut);
160  void set_past_weather(const wreport::Var& var, int shortcut);
161  void set_wind(const wreport::Var& var, int shortcut);
162  void set_wind_max(const wreport::Var& var, int shortcut);
163  void set_pressure(const wreport::Var& var);
164  void set_water_temperature(const wreport::Var& var);
165  void set_swell_waves(const wreport::Var& var);
166 
167 protected:
168  void ib_start(int shortcut, const wreport::Var& var);
169  Level lev_real(const Level& standard) const;
170  Trange tr_real(const Trange& standard) const;
171  Level lev_shortcut() const { return Level(v->ltype1, v->l1, v->ltype2, v->l2); }
172  Trange tr_shortcut() const { return Trange(v->pind, v->p1, v->p2); }
173  void ib_annotate_level();
174  void ib_annotate_trange();
175  void ib_level_use_real(const Level& standard) { chosen_lev = lev_real(standard); }
176  void ib_trange_use_real(const Trange& standard) { chosen_tr = tr_real(standard); }
177  void ib_level_use_shorcut_and_discard_rest() { chosen_lev = lev_shortcut(); }
178  void ib_trange_use_shortcut_and_discard_rest() { chosen_tr = tr_shortcut(); }
179  void ib_level_use_shorcut_and_preserve_rest(const Level& standard);
180  void ib_trange_use_shorcut_and_preserve_rest(const Trange& standard);
181  void ib_level_use_standard_and_preserve_rest(const Level& standard);
182  void ib_trange_use_standard_and_preserve_rest(const Trange& standard);
183  void ib_level_use_shorcut_if_standard_else_real(const Level& standard);
184  void ib_trange_use_shorcut_if_standard_else_real(const Trange& standard);
185  void ib_set();
186 };
187 
192 {
193 protected:
194  CloudContext clouds;
195  LevelContext level;
196  TimerangeContext trange;
197  ContextChooser ctx;
198 
199  virtual void peek_var(const wreport::Var& var);
200  virtual void import_var(const wreport::Var& var);
201 
202 public:
204 
205  virtual void init();
206  virtual void run();
207 };
208 
209 } // namespace wr
210 } // namespace msg
211 } // namespace dballe
212 
213 /* vim:set ts=4 sw=4: */
214 #endif
Definition: base.h:39
Storage for related physical data.
Definition: msg.h:119
int p2
Time range P2 indicator.
Definition: vars.h:38
Definition: codec.h:56
Definition: base.h:74
Definition: defs.h:113
Keep track of level context changes.
Definition: base.h:93
Definition: base.h:133
Definition: cmdline.h:34
int l2
L2 value of the level.
Definition: vars.h:32
Definition: defs.h:54
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:123
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:107
int ltype1
Type of the first level.
Definition: vars.h:26
Definition: conversion.h:31
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:191
int pind
Time range type indicator.
Definition: vars.h:34