MeteoIODoc 20241221.207bde49
BUFRFile.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
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
20#ifndef BUFRFILE_H
21#define BUFRFILE_H
22
23#include <meteoio/IOInterface.h>
25
26#include <string>
27
28namespace mio {
29
30using namespace codes;
31
32class BUFRFile {
33 public:
34 BUFRFile(const std::string &filename, const std::string& ref_coords, bool verbose = false, double default_timezone = IOUtils::nodata);
35
36 void readMetaData(const std::string& ref_coords);
37 // takes a map that contatins the bufr keys as keys, and names as values. Should map to itself, if no renaming is needed
38 // returns a vector of meteo data timeseries, one for each station
39 void readData(std::vector<METEO_SET> &vecMeteo, std::map<std::string,size_t>& station_ids, const std::vector<std::string> &additional_params);
40
41 const std::map<std::string, StationData>& getMetadata() const { return meta_data; };
42
43 bool hasMultipleSubets(const size_t &msg_index) const { return subset_numbers[msg_index] > 1; };
44
45 private:
46 std::string filename;
47 std::map<std::string, StationData> meta_data;
48 std::map<std::string, double> station_timezones;
49
50
51 Date start_date;
52 Date end_date;
53 double default_timezone;
54
55 bool isMeteoTimeseries;
56 bool isProfile;
57 // for each message see if we need subset indexing
58 std::vector<size_t> subset_numbers;
59
60 std::vector<std::string> station_ids_in_file;
61
62 bool verbose;
63
64 // HELPERS
65 bool isNewStation(const std::string &station_id) { return station_ids_in_file.end() == std::find(station_ids_in_file.begin(), station_ids_in_file.end(), station_id); };
66 double getNumSubsets(CodesHandlePtr &message, double default_value);
67 void processSubsets(CodesHandlePtr &message, const std::string &ref_coords, const size_t& num_subsets, std::map<std::string, std::set<Date>> &station_dates);
68 void processNewStation(const std::string &station_id, const StationData &new_meta, const Date &new_date, std::map<std::string, std::set<Date>> &station_dates);
69 void processExistingStation(const std::string &station_id, const StationData &new_meta, const Date &new_date, std::map<std::string, std::set<Date>> &station_dates);
70 void updateDateRange(const Date &new_date);
71 void updateStationIdsMapping(std::vector<METEO_SET> &vecMeteo, std::map<std::string, size_t>& station_ids_mapping);
72 void processMessage(std::vector<METEO_SET> &vecMeteo, std::map<std::string, size_t>& station_ids_mapping, const std::vector<std::string> &additional_params, CodesHandlePtr &message, size_t msg_id);
73
74
75
76};
77
78} //namespace
79
80
81#endif // BUFRFILE_H
Definition: BUFRFile.h:32
void readMetaData(const std::string &ref_coords)
Definition: BUFRFile.cc:192
bool hasMultipleSubets(const size_t &msg_index) const
Definition: BUFRFile.h:43
BUFRFile(const std::string &filename, const std::string &ref_coords, bool verbose=false, double default_timezone=IOUtils::nodata)
Definition: BUFRFile.cc:30
void readData(std::vector< METEO_SET > &vecMeteo, std::map< std::string, size_t > &station_ids, const std::vector< std::string > &additional_params)
Definition: BUFRFile.cc:287
const std::map< std::string, StationData > & getMetadata() const
Definition: BUFRFile.h:41
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
This namespace handles all the low level manipulation of GRIB and BUFR files with ecCodes.
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
std::unique_ptr< codes_handle, HandleDeleter > CodesHandlePtr
Definition: libcodes.h:52
Definition: Config.cc:31