MeteoIODoc 20241221.207bde49
GRIBFile.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2012 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 GRIBFILE_H
21#define GRIBFILE_H
22
23#include <meteoio/IOUtils.h>
26
27#include <string>
28#include <vector>
29#include <unordered_set>
30
31namespace mio {
32
33using namespace codes;
34
35class GRIBTable {
36
37 enum class PARAM_TYPE {
38 DOUBLE,
39 LONG,
40 STRING,
41 };
42
43 public:
44 GRIBTable(const std::string &in_filename);
45 GRIBTable();
46
47 // GETTERS
48 std::vector<std::string> getIndexes() const;
49 std::string getParamKey() const { return param_indexing; };
50 std::string getLevelKey() const { return level_indexing; };
51
52
53 void getParamId(const std::string &param_name, std::string &paramId, double &paramId_num, long &paramId_long) const;
54 std::string getLevelType(const std::string &param_name) const;
55 long getLevelNo(const std::string &param_name) const;
56
57#ifdef DEBUG
58 void printTable() const;
59#endif
60
61 private:
62 std::string filename;
63
64 std::string param_indexing;
65 std::string level_indexing;
66
67 std::map<std::string, std::string> param_table;
68 std::map<std::string, double> param_table_double;
69 std::map<std::string, long> param_table_long;
70 std::map<std::string, std::string> level_type_table;
71 std::map<std::string, long> level_no_table;
72
73 PARAM_TYPE parameter_id_type;
74
75 std::unordered_set<std::string> known_params;
76
77 // initialization
78 void init_known_params();
79
80 void readTable();
81 bool parseIndexing(const std::vector<std::string> &line_vals);
82 bool parseParamType(const std::vector<std::string> &line_vals);
83 void fillParameterTables(const std::vector<std::string> &line_vals);
84
85
86};
87
88// Needs to contain all variables for 1 timepoint, and only 1 timepoint
89class GRIBFile {
90 public:
91 GRIBFile(const std::string &in_filename, const std::vector<std::string> &indexes);
92
93 template <typename T>
94 std::vector<CodesHandlePtr> listParameterMessages(const std::string& param_key, const T& paramID, const std::string& level_key,const std::string &levelType) {
95 return getMessages(file, param_key, paramID, level_key, levelType);
96 }
97
98 std::map<std::string, double> getGridParams() const {
99 return grid_params;
100 }
101
102 bool isValidDate(const Date& date) const {
103 return timepoints.find(date) != timepoints.end();
104 }
105
106 std::string getFilename() const {
107 return filename;
108 };
109
110 std::set<Date> getDates() const {
111 return timepoints;
112 }
113
115 return *timepoints.begin();
116 }
117
118 private:
119 std::string filename;
120 CodesIndexPtr file; // TODO: will this save the contents of the file? If so, it will be way to big to save, but then do calls to selectIndex always open the file?
121
122 std::map<std::string, double> grid_params;
123 std::set<Date> timepoints;
124
125 void checkValidity();
126
127};
128
129} // namespace mio
130
131#endif // GRIBFILE_H
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
Definition: GRIBFile.h:89
std::string getFilename() const
Definition: GRIBFile.h:106
std::vector< CodesHandlePtr > listParameterMessages(const std::string &param_key, const T &paramID, const std::string &level_key, const std::string &levelType)
Definition: GRIBFile.h:94
GRIBFile(const std::string &in_filename, const std::vector< std::string > &indexes)
Definition: GRIBFile.cc:250
Date getStartDate() const
Definition: GRIBFile.h:114
std::set< Date > getDates() const
Definition: GRIBFile.h:110
std::map< std::string, double > getGridParams() const
Definition: GRIBFile.h:98
bool isValidDate(const Date &date) const
Definition: GRIBFile.h:102
Definition: GRIBFile.h:35
std::string getLevelType(const std::string &param_name) const
Definition: GRIBFile.cc:218
GRIBTable()
Definition: GRIBFile.cc:31
std::string getParamKey() const
Definition: GRIBFile.h:49
std::vector< std::string > getIndexes() const
Definition: GRIBFile.cc:196
long getLevelNo(const std::string &param_name) const
Definition: GRIBFile.cc:220
void getParamId(const std::string &param_name, std::string &paramId, double &paramId_num, long &paramId_long) const
Definition: GRIBFile.cc:200
std::string getLevelKey() const
Definition: GRIBFile.h:50
This namespace handles all the low level manipulation of GRIB and BUFR files with ecCodes.
std::unique_ptr< codes_index, IndexDeleter > CodesIndexPtr
Definition: libcodes.h:53
std::vector< CodesHandlePtr > getMessages(const std::string &filename, ProductKind product)
Definition: libcodes.cc:315
Definition: Config.cc:31