24 #include "pism/util/io/File.hh"
30 #include "pism/util/Logger.hh"
37 : m_n_spatial_dims(ndims),
38 m_unit_system(std::move(system)),
40 m_time_independent(false),
88 *units = units_string.c_str(),
89 *name = name_string.c_str(),
90 *file = filename.c_str();
96 if ((
min < valid_min - eps) or (
max > valid_max + eps)) {
98 "computed min = %e %s, computed max = %e %s",
100 valid_min, valid_max, units,
min, units,
max, units);
104 if (
min < valid_min - eps) {
106 "computed min = %e %s, computed max = %e %s",
108 valid_min, units,
min, units,
max, units);
112 if (
max > valid_max + eps) {
114 "computed min = %e %s, computed max = %e %s",
116 valid_max, units,
min, units,
max, units);
122 const std::string &name,
123 const std::vector<double> &zlevels)
131 m_x[
"long_name"] =
"X-coordinate in Cartesian system";
132 m_x[
"standard_name"] =
"projection_x_coordinate";
136 m_y[
"long_name"] =
"Y-coordinate in Cartesian system";
137 m_y[
"standard_name"] =
"projection_y_coordinate";
141 m_z[
"long_name"] =
"Z-coordinate in Cartesian system";
143 m_z[
"positive"] =
"up";
160 bool found_by_standard_name) {
169 std::string spacer(
get_name().size(),
' ');
173 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",
229 if (name !=
"units" and (j->second).empty()) {
249 m_doubles[name] = std::vector<double>(1, value);
273 return (j->second)[0];
277 "variable \"%s\" does not have a double attribute \"%s\"",
306 m_strings[
"glaciological_units"] = value;
312 if (name ==
"units") {
317 m_strings[
"glaciological_units"] = value;
318 }
else if (name ==
"glaciological_units") {
328 }
else if (name ==
"short_name") {
340 if (name ==
"short_name") {
358 size_t max_name_length = 0;
359 for (
const auto &s : strings) {
360 max_name_length =
std::max(max_name_length, s.first.size());
362 for (
const auto &d : doubles) {
363 max_name_length =
std::max(max_name_length, d.first.size());
367 for (
const auto &s : strings) {
368 std::string name = s.first;
369 std::string value = s.second;
370 std::string padding(max_name_length - name.size(),
' ');
376 log.
message(verbosity_threshold,
" %s%s = \"%s\"\n",
377 name.c_str(), padding.c_str(), value.c_str());
381 for (
const auto &d : doubles) {
382 std::string name = d.first;
383 std::vector<double> values = d.second;
384 std::string padding(max_name_length - name.size(),
' ');
386 if (values.empty()) {
390 const double large = 1.0e7;
391 const double small = 1.0e-4;
392 if ((std::fabs(values[0]) >= large) || (std::fabs(values[0]) <= small)) {
394 log.
message(verbosity_threshold,
" %s%s = %12.3e\n",
395 name.c_str(), padding.c_str(), values[0]);
397 log.
message(verbosity_threshold,
" %s%s = %12.5f\n",
398 name.c_str(), padding.c_str(), values[0]);
409 : m_name(std::move(a.m_name)), m_var(a.m_var) {
414 ConstAttribute::operator std::string()
const {
415 return m_var->get_string(m_name);
418 ConstAttribute::operator double()
const {
419 auto values = m_var->get_numbers(m_name);
420 if (values.size() == 1) {
424 "%s:%s has more than one value",
425 m_var->get_name().c_str(), m_name.c_str());
428 ConstAttribute::operator std::vector<double> ()
const {
429 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
bool are_convertible(const Unit &u1, const Unit &u2)
double max(const IceModelVec2S &input)
Finds maximum over all the values in an IceModelVec2S object. Ignores ghosts.
double min(const IceModelVec2S &input)
Finds minimum over all the values in an IceModelVec2S object. Ignores ghosts.