MeteoIODoc 2.11.0
libacdd.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2020 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#ifndef LIBACDD_H
20#define LIBACDD_H
21
22#include <meteoio/IOUtils.h>
23#include <meteoio/Config.h>
26
27#include <string>
28#include <vector>
29
30namespace mio {
113class ACDD {
114 public:
116
117 typedef struct ACDD_ATTR {
118 ACDD_ATTR() : name(), value(), cfg_key(), default_value(), Default(true) {}
119 ACDD_ATTR(const std::string& i_name, const std::string& i_cfg_key, const std::string& i_default_value="") : name(i_name), value(), cfg_key(i_cfg_key), default_value(i_default_value), Default(i_name.empty()) {}
120 ACDD_ATTR(const std::string& i_name, const std::string& i_value, const std::string& i_cfg_key, const std::string& i_default_value) : name(i_name), value(i_value), cfg_key(i_cfg_key), default_value(i_default_value), Default(false) {}
121
122 std::string getValue() const {return value;}
123 std::string getName() const {return name;}
124 void setUserConfig(const mio::Config& cfg, const std::string& section, const bool& allow_multi_line);
125 void setValue(const std::string& i_value, const Mode& mode=MERGE);
126 bool isDefault() const {return Default;}
127
128 private:
129 static void readFromFile(std::string& value, const mio::Config& cfg, const std::string& cfg_key, const std::string& section, const bool& allow_multi_line);
130
131 std::string name, value, cfg_key, default_value;
132 bool Default;
133 } acdd_attrs;
134
139 ACDD(const bool& set_enable) : attributes(), linked_attributes(), enabled(set_enable) {}
140
141 //defining some iterators so the callers can loop over all available attributes
142 using const_iterator = std::map<std::string, acdd_attrs>::const_iterator;
143 const_iterator cbegin() const noexcept { return attributes.cbegin(); }
144 const_iterator cend() const noexcept { return attributes.cend(); }
145
151 void setEnabled(const bool& i_enable);
152 void setUserConfig(const mio::Config& cfg, const std::string& section, const bool& allow_multi_line=true);
153
154 void addAttribute(const std::string& att_name, const std::string& att_value, const Mode& mode=MERGE);
155 void addAttribute(const std::string& att_name, const double& att_value, const Mode& mode=MERGE);
156
161 bool isEnabled() const {return enabled;}
162 std::string getAttribute(std::string &att_name) const;
163
164 void setGeometry(const mio::Grid2DObject& grid, const bool& isLatLon);
165 void setGeometry(const std::vector< std::vector<mio::MeteoData> >& vecMeteo, const bool& isLatLon);
166 void setGeometry(const mio::Coords& location, const bool& isLatLon);
167 void setGeometry(const std::vector< mio::Coords >& vecLocation, const bool& isLatLon);
168
169 void setTimeCoverage(const std::vector< std::vector<mio::MeteoData> >& vecMeteo);
170 void setTimeCoverage(const std::vector<mio::MeteoData>& vecMeteo);
171 void setTimeCoverage(const std::vector<std::string>& vec_timestamp, const double& TZ);
172
173 std::string toString() const;
174
175 private:
176 static std::map<std::string, acdd_attrs> initAttributes();
177 static std::set< std::pair< std::string, std::set<std::string> > > initLinks();
178 static size_t countCommas(const std::string& str);
179 void checkLinkedAttributes();
180
181 std::map<std::string, acdd_attrs> attributes; //all the ACDD attributes with their properties
182 std::set< std::pair< std::string, std::set<std::string> > > linked_attributes; //attribute names that are linked together, ie must have the same number of sub-elements (comma delimited)
183 bool enabled; //helper boolean for callers to know if this object should be used or not
184};
185
186} //namespace
187#endif
This class contains and handles NetCDF Attribute Conventions Dataset Discovery attributes (see ACDD).
Definition: libacdd.h:113
void setUserConfig(const mio::Config &cfg, const std::string &section, const bool &allow_multi_line=true)
Read all config keys from the selected section and apply some special processing for some keys.
Definition: libacdd.cc:185
ACDD(const bool &set_enable)
Constructor, the argument allows the object to know if the acdd metadata should be written out or not...
Definition: libacdd.h:139
std::string toString() const
Definition: libacdd.cc:250
void setTimeCoverage(const std::vector< std::vector< mio::MeteoData > > &vecMeteo)
Definition: libacdd.cc:499
std::map< std::string, acdd_attrs >::const_iterator const_iterator
Definition: libacdd.h:142
void setEnabled(const bool &i_enable)
Set an internal boolean as a helper for the caller to know if ACDD support should be enabled or not....
Definition: libacdd.cc:198
Mode
Definition: libacdd.h:115
@ APPEND
Definition: libacdd.h:115
@ REPLACE
Definition: libacdd.h:115
@ MERGE
Definition: libacdd.h:115
const_iterator cend() const noexcept
Definition: libacdd.h:144
void addAttribute(const std::string &att_name, const std::string &att_value, const Mode &mode=MERGE)
Add an attribute and its content to the internal list.
Definition: libacdd.cc:270
std::string getAttribute(std::string &att_name) const
Given an attribute name, return its associated value (or an empty string if it does not exists)
Definition: libacdd.cc:298
const_iterator cbegin() const noexcept
Definition: libacdd.h:143
bool isEnabled() const
Get an internal boolean as a helper for the caller to know if ACDD support should be enabled or not.
Definition: libacdd.h:161
void setGeometry(const mio::Grid2DObject &grid, const bool &isLatLon)
Definition: libacdd.cc:306
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 geographic coordinate systems. This class offers an easy way to transparently conve...
Definition: Coords.h:83
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
Definition: Config.cc:31
Definition: libacdd.h:117
ACDD_ATTR()
Definition: libacdd.h:118
std::string getName() const
Definition: libacdd.h:123
void setUserConfig(const mio::Config &cfg, const std::string &section, const bool &allow_multi_line)
std::string getValue() const
Definition: libacdd.h:122
bool isDefault() const
Definition: libacdd.h:126
void setValue(const std::string &i_value, const Mode &mode=MERGE)
ACDD_ATTR(const std::string &i_name, const std::string &i_value, const std::string &i_cfg_key, const std::string &i_default_value)
Definition: libacdd.h:120
ACDD_ATTR(const std::string &i_name, const std::string &i_cfg_key, const std::string &i_default_value="")
Definition: libacdd.h:119