20 #include "pism/util/Config.hh"
21 #include "pism/util/io/File.hh"
22 #include "pism/util/pism_options.hh"
23 #include "pism/util/error_handling.hh"
24 #include "pism/util/io/io_helpers.hh"
25 #include "pism/util/Logger.hh"
26 #include "pism/pism_config.hh"
27 #include "pism/util/io/IO_Flags.hh"
34 m_data(name, system) {
48 if (doubles.find(name) != doubles.end()) {
53 "parameter '%s' is unset. (Parameters read from '%s'.)",
61 if (doubles.find(name) != doubles.end()) {
66 "parameter '%s' is unset. (Parameters read from '%s'.)",
76 result[d.first] = d.second;
87 const std::vector<double> &values) {
95 if (strings.find(name) != strings.end()) {
100 "Parameter '%s' was not set. (Read from '%s'.)\n", name.c_str(),
103 return std::string();
110 for (
const auto& s : strings) {
111 std::string name = s.first;
112 std::string value = s.second;
114 auto k = strings.find(name +
"_type");
115 if (
k != strings.end() and
k->second ==
"flag") {
120 result[name] = value;
132 return value ==
"false" or value ==
"off" or value ==
"no";
136 return value ==
"true" or value ==
"on" or value ==
"yes";
141 auto j = strings.find(name);
142 if (j != strings.end()) {
144 const std::string &value = j->second;
155 "Please make sure that it is set to one of 'true', 'yes', 'on', 'false', 'no', 'off'.",
156 name.c_str(), value.c_str());
169 std::string name = b.first;
170 std::string value = b.second;
175 result[name] =
false;
183 m_data[name] = value ?
"true" :
"false";
204 if (not variable_exists) {
216 const std::string &variable_name,
217 const std::string &option,
228 if (use_default_path or file.
is_set()) {
230 log.
message(2,
"Reading configuration parameters (%s) from file '%s'.\n",
236 this->
init(log,
true);
240 this->
init(log,
false);
std::map< std::string, std::string > Strings
std::map< std::string, std::vector< double > > Doubles
void read(MPI_Comm com, const std::string &filename)
std::map< std::string, bool > Flags
A class for storing and accessing PISM configuration flags and parameters.
DefaultConfig(MPI_Comm com, const std::string &variable_name, const std::string &option, units::System::Ptr unit_system)
Config that respects command-line options and stores data in a NetCDF variable.
void init_with_default(const Logger &log)
Initialize (use default path if no option was set).
void init(const Logger &log)
Initialize (leave empty if no option was set).
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
std::string filename() const
void define_variable(const std::string &name, io::Type nctype, const std::vector< std::string > &dims) const
Define a variable.
High-level PISM I/O class.
void message(int threshold, const char format[],...) const __attribute__((format(printf
Print a message to the log.
bool get_flag_impl(const std::string &name) const
void set_numbers_impl(const std::string &name, const std::vector< double > &values)
bool is_set_impl(const std::string &name) const
Doubles all_doubles_impl() const
void set_number_impl(const std::string &name, double value)
NetCDFConfig(MPI_Comm com, const std::string &name, units::System::Ptr unit_system)
void set_flag_impl(const std::string &name, bool value)
Set a value of a flag flag.
std::string get_string_impl(const std::string &name) const
double get_number_impl(const std::string &name) const
void write_impl(const File &nc) const
Write a config variable to a file (with all its attributes).
void set_string_impl(const std::string &name, const std::string &value)
Strings all_strings_impl() const
Flags all_flags_impl() const
std::vector< double > get_numbers_impl(const std::string &name) const
std::string m_config_filename
the name of the file this config database was initialized from
void read_impl(const File &nc)
Read flag flags and double parameters from a NetCDF file.
A class for reading, writing and accessing PISM configuration flags and parameters.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
std::shared_ptr< System > Ptr
#define PISM_ERROR_LOCATION
void write_attributes(const File &file, const VariableMetadata &variable, io::Type nctype)
Write variable attributes to a NetCDF file.
void read_attributes(const File &file, const std::string &variable_name, VariableMetadata &variable)
static bool string_is_false(const std::string &value)
static bool string_is_true(const std::string &value)