MeteoIODoc 20241221.207bde49
MeteoBlue.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2021 SLF */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef METEOBLUE_H
20#define METEOBLUE_H
21
22#include <meteoio/IOInterface.h>
23#include <meteoio/thirdParty/picojson.h>
24
25#include <string>
26#include <vector>
27
28#ifdef _MSC_VER
29 #pragma warning(disable:4512) //we don't need any = operator!
30#endif
31
32namespace mio {
33
42class MeteoBlue : public IOInterface {
43 public:
44 MeteoBlue(const std::string& configfile);
46 MeteoBlue(const Config&);
47
48 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
49 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
50 std::vector< std::vector<MeteoData> >& vecMeteo);
51
52 typedef struct METEOPARAM {
53 METEOPARAM() : param(), units_multiplier(1.), units_offset(0.) {}
55 : param(i_param), units_multiplier(1.), units_offset(0.) {}
56 METEOPARAM(const MeteoGrids::Parameters& i_param, const double& multiplier, const double& offset)
57 : param(i_param), units_multiplier(multiplier), units_offset(offset) {}
58
59 std::string getParameterName() const {return MeteoGrids::getParameterName( param );}
60 double convertValue(const double& val) const {return (units_multiplier*val + units_offset);}
61
62 std::string toString() const {
63 std::ostringstream os;
64 os << "[ " << MeteoGrids::getParameterName( param ) << " *" << units_multiplier << " +" << units_offset << "]";
65 return os.str();
66 }
67
69 double units_multiplier, units_offset;
70 } meteoParam;
71
72 private:
73 void init();
74 void readData(const StationData& sd, std::vector<MeteoData> &vecMeteo);
75 void readTime(const picojson::value &v, const StationData& sd, std::vector<MeteoData> &vecMeteo) const;
76 void readParameter(const picojson::value &v, const std::string& paramname, std::vector<MeteoData> &vecMeteo) const;
77 static picojson::value goToJSONPath(const std::string& path, const picojson::value& v);
78 static size_t data_write(void* buf, const size_t size, const size_t nmemb, void* userp);
79 bool curl_read(const std::string& url, std::ostream& os) const;
80
81 const Config cfg;
82 std::vector<StationData> vecMeta;
83 std::string coordin, coordinparam;
84 std::string endpoint, apikey, packages;
85 int http_timeout; //time out for http connections
86 bool debug;
87
88 static std::map< std::string, meteoParam > params_map;
89 static const std::string dflt_endpoint;
90 static const int http_timeout_dflt;
91 static const bool __init;
92 static bool initStaticData();
93};
94
95} //end namespace mio
96
97#endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition: IOInterface.h:98
This class enables the access to the MeteoBlue RESTful web service.
Definition: MeteoBlue.h:42
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
Fill vecStation with StationData objects for a certain date of interest.
Definition: MeteoBlue.cc:197
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: MeteoBlue.cc:203
MeteoBlue(const MeteoBlue &)
MeteoBlue(const std::string &configfile)
Definition: MeteoBlue.cc:140
static const std::string getParameterName(const size_t &parindex)
Definition: MeteoData.cc:85
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
Definition: Config.cc:31
Definition: MeteoBlue.h:52
MeteoGrids::Parameters param
Definition: MeteoBlue.h:68
std::string getParameterName() const
Definition: MeteoBlue.h:59
METEOPARAM(const MeteoGrids::Parameters &i_param)
Definition: MeteoBlue.h:54
METEOPARAM(const MeteoGrids::Parameters &i_param, const double &multiplier, const double &offset)
Definition: MeteoBlue.h:56
std::string toString() const
Definition: MeteoBlue.h:62
double units_multiplier
Definition: MeteoBlue.h:69
METEOPARAM()
Definition: MeteoBlue.h:53
double convertValue(const double &val) const
Definition: MeteoBlue.h:60