23 #include "pism/util/VariableMetadata.hh"
25 #include "pism/util/Logger.hh"
26 #include "pism/util/error_handling.hh"
27 #include "pism/util/io/File.hh"
28 #include "pism/util/io/IO_Flags.hh"
34 : m_n_spatial_dims(ndims),
35 m_unit_system(std::move(system)),
37 m_time_independent(false),
89 const char *
units = units_string.c_str(), *name = name_string.c_str(), *file = filename.c_str();
95 if ((
min < valid_min - eps) or (
max > valid_max + eps)) {
98 "some values of '%s' in '%s' are outside the valid range [%e, %e] (%s).\n"
99 "computed min = %e %s, computed max = %e %s",
104 if (
min < valid_min - eps) {
107 "some values of '%s' in '%s' are less than the valid minimum (%e %s).\n"
108 "computed min = %e %s, computed max = %e %s",
113 if (
max > valid_max + eps) {
116 "some values of '%s' in '%s' are greater than the valid maximum (%e %s).\n"
117 "computed min = %e %s, computed max = %e %s",
124 const std::vector<double> &zlevels)
132 m_x[
"long_name"] =
"X-coordinate in Cartesian system";
133 m_x[
"standard_name"] =
"projection_x_coordinate";
137 m_y[
"long_name"] =
"Y-coordinate in Cartesian system";
138 m_y[
"standard_name"] =
"projection_y_coordinate";
144 m_z[
"long_name"] =
"Z-coordinate in Cartesian system";
146 m_z[
"positive"] =
"up";
161 bool found_by_standard_name) {
168 std::string spacer(
get_name().size(),
' ');
172 if (found_by_standard_name) {
175 " %s / standard_name=%-10s\n"
176 " %s \\ min,max = %9.3f,%9.3f (%s)\n",
182 " %s / WARNING! standard_name=%s is missing, found by short_name\n"
183 " %s \\ min,max = %9.3f,%9.3f (%s)\n",
192 " %s \\ min,max = %9.3f,%9.3f (%s)\n",
228 if (name !=
"units" and (j->second).empty()) {
275 return (j->second)[0];
279 "variable \"%s\" does not have a double attribute \"%s\"",
316 if (name ==
"units") {
322 }
else if (name ==
"output_units") {
332 }
else if (name ==
"short_name") {
346 if (name ==
"short_name") {
364 size_t max_name_length = 0;
365 for (
const auto &s : strings) {
366 max_name_length =
std::max(max_name_length, s.first.size());
368 for (
const auto &d : doubles) {
369 max_name_length =
std::max(max_name_length, d.first.size());
373 for (
const auto &s : strings) {
374 std::string name = s.first;
375 std::string value = s.second;
376 std::string padding(max_name_length - name.size(),
' ');
382 log.
message(verbosity_threshold,
" %s%s = \"%s\"\n",
383 name.c_str(), padding.c_str(), value.c_str());
387 for (
const auto &d : doubles) {
388 std::string name = d.first;
389 std::vector<double> values = d.second;
390 std::string padding(max_name_length - name.size(),
' ');
392 if (values.empty()) {
396 const double large = 1.0e7;
397 const double small = 1.0e-4;
398 if ((std::fabs(values[0]) >= large) || (std::fabs(values[0]) <= small)) {
400 log.
message(verbosity_threshold,
" %s%s = %12.3e\n",
401 name.c_str(), padding.c_str(), values[0]);
403 log.
message(verbosity_threshold,
" %s%s = %12.5f\n",
404 name.c_str(), padding.c_str(), values[0]);
415 : m_name(std::move(a.m_name)), m_var(a.m_var) {
420 ConstAttribute::operator std::string()
const {
421 return m_var->get_string(m_name);
424 ConstAttribute::operator double()
const {
425 auto values = m_var->get_numbers(m_name);
426 if (values.size() == 1) {
430 "%s:%s has more than one value",
431 m_var->get_name().c_str(), m_name.c_str());
434 ConstAttribute::operator std::vector<double> ()
const {
435 return m_var->get_numbers(m_name);
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
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
double min(const array::Scalar &input)
Finds minimum over all the values in an array::Scalar object. Ignores ghosts.
bool are_convertible(const Unit &u1, const Unit &u2)