24#include "pism/util/VariableMetadata.hh"
26#include "pism/util/Logger.hh"
27#include "pism/util/error_handling.hh"
28#include "pism/util/io/File.hh"
29#include "pism/util/io/IO_Flags.hh"
36 : m_n_spatial_dims(ndims),
37 m_unit_system(std::move(system)),
39 m_time_independent(false),
40 m_output_type(io::PISM_NAT) {
91 const char *
units = units_string.c_str(), *name = name_string.c_str(), *file = filename.c_str();
97 if ((min < valid_min - eps) or (max > valid_max + eps)) {
100 "some values of '%s' in '%s' are outside the valid range [%e, %e] (%s).\n"
101 "computed min = %e %s, computed max = %e %s",
102 name, file, valid_min, valid_max, units, min, units, max, units);
106 if (min < valid_min - eps) {
109 "some values of '%s' in '%s' are less than the valid minimum (%e %s).\n"
110 "computed min = %e %s, computed max = %e %s",
111 name, file, valid_min, units, min, units, max, units);
115 if (max > valid_max + eps) {
118 "some values of '%s' in '%s' are greater than the valid maximum (%e %s).\n"
119 "computed min = %e %s, computed max = %e %s",
120 name, file, valid_max, units, min, units, max, units);
126 const std::vector<double> &zlevels)
134 m_x[
"long_name"] =
"X-coordinate in Cartesian system";
135 m_x[
"standard_name"] =
"projection_x_coordinate";
139 m_y[
"long_name"] =
"Y-coordinate in Cartesian system";
140 m_y[
"standard_name"] =
"projection_y_coordinate";
146 m_z[
"long_name"] =
"Z-coordinate in Cartesian system";
148 m_z[
"positive"] =
"up";
170 std::string spacer(name.size(),
' ');
176 range =
pism::printf(
"constant %9.3f %s", min, units.c_str());
178 range =
pism::printf(
"min = %9.3f, max = %9.3f %s", min, max, units.c_str());
184 name.c_str(), info.c_str(), spacer.c_str(), range.c_str());
217 if (name !=
"units" and (j->second).empty()) {
264 return (j->second)[0];
268 "variable \"%s\" does not have a double attribute \"%s\"",
305 if (name ==
"units") {
311 }
else if (name ==
"output_units") {
321 }
else if (name ==
"short_name") {
335 if (name ==
"short_name") {
353 size_t max_name_length = 0;
354 for (
const auto &s : strings) {
355 max_name_length = std::max(max_name_length, s.first.size());
357 for (
const auto &d : doubles) {
358 max_name_length = std::max(max_name_length, d.first.size());
362 for (
const auto &s : strings) {
363 std::string name = s.first;
364 std::string value = s.second;
365 std::string padding(max_name_length - name.size(),
' ');
371 log.
message(verbosity_threshold,
" %s%s = \"%s\"\n",
372 name.c_str(), padding.c_str(), value.c_str());
376 for (
const auto &d : doubles) {
377 std::string name = d.first;
378 std::vector<double> values = d.second;
379 std::string padding(max_name_length - name.size(),
' ');
381 if (values.empty()) {
385 const double large = 1.0e7;
386 const double small = 1.0e-4;
387 if ((std::fabs(values[0]) >= large) || (std::fabs(values[0]) <= small)) {
389 log.
message(verbosity_threshold,
" %s%s = %12.3e\n",
390 name.c_str(), padding.c_str(), values[0]);
392 log.
message(verbosity_threshold,
" %s%s = %12.5f\n",
393 name.c_str(), padding.c_str(), values[0]);
404 : m_name(std::move(a.m_name)), m_var(a.m_var) {
409ConstAttribute::operator std::string()
const {
410 return m_var->get_string(m_name);
409ConstAttribute::operator std::string()
const {
…}
414 auto values = m_var->get_numbers(m_name);
415 if (values.size() == 1) {
419 "%s:%s has more than one value",
420 m_var->get_name().c_str(), m_name.c_str());
423ConstAttribute::operator std::vector<double> ()
const {
424 return m_var->get_numbers(m_name);
423ConstAttribute::operator std::vector<double> ()
const {
…}
void operator=(const std::string &value)
ConstAttribute(const ConstAttribute &)=delete
void message(int threshold, const char format[],...) const __attribute__((format(printf
Print a message to the log.
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
bool are_convertible(const Unit &u1, const Unit &u2)
std::string printf(const char *format,...)