20 #include "pism/util/Units.hh"
24 #include "pism/external/calcalcs/utCalendar2_cal.h"
26 #include "pism/util/error_handling.hh"
33 Impl(
const std::string &path) {
36 ut_set_error_message_handler(ut_ignore);
38 if (not path.empty()) {
39 tmp = ut_read_xml(path.c_str());
41 tmp = ut_read_xml(NULL);
47 ut_set_error_message_handler(ut_write_to_stderr);
71 const std::string &spec1,
const std::string &spec2) {
80 unit = ut_parse(sys->m_impl->system, spec.c_str(), UT_ASCII);
84 "unit specification '%s' is unknown or invalid",
120 if (
this == &other) {
130 if (
m_impl->unit == NULL) {
138 return ut_are_convertible(
m_impl->unit, other.
m_impl->unit) != 0;
142 return m_impl->unit_string;
162 "cannot convert time %f to a date in calendar %s",
178 "cannot convert date and time %d-%d-%d %d:%d:%f to time in calendar %s",
192 Unit u1(sys, spec1), u2(sys, spec2);
194 if (not u1.is_convertible(u2)) {
196 "cannot convert '%s' to '%s'",
197 spec1.c_str(), spec2.c_str());
203 "cannot create a converter from %s to %s",
204 spec1.c_str(), spec2.c_str());
217 "failed to create a converter from '%s' to '%s'",
234 const std::string &spec1,
const std::string &spec2) {
247 return cv_convert_double(
m_impl->converter, input);
251 cv_convert_doubles(
m_impl->converter, data, length, data);
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
std::shared_ptr< Impl > m_impl
double operator()(double input) const
void convert_doubles(double *data, size_t length) const
System(const std::string &path="")
std::shared_ptr< Impl > m_impl
std::shared_ptr< System > Ptr
DateTime date(double T, const std::string &calendar) const
std::string format() const
Unit & operator=(const Unit &other)
System::Ptr system() const
double time(const DateTime &d, const std::string &calendar) const
Unit(System::Ptr system, const std::string &spec)
std::shared_ptr< Impl > m_impl
bool is_convertible(const Unit &other) const
#define PISM_ERROR_LOCATION
bool are_convertible(const Unit &u1, const Unit &u2)
double convert(System::Ptr system, double input, const std::string &spec1, const std::string &spec2)
Convert a quantity from unit1 to unit2.
static std::string calendar(const File *input_file, const Config &config, const Logger &log)
Impl(const Unit &u1, const Unit &u2)
Impl(System::Ptr sys, const std::string &spec1, const std::string &spec2)
Impl(const std::string &path)
Impl(System::Ptr sys, const std::string &spec)
Impl(const Unit::Impl &other)
int utCalendar2_cal(double val, ut_unit *dataunits, int *year, int *month, int *day, int *hour, int *minute, double *second, const char *calendar_name)
int utInvCalendar2_cal(int year, int month, int day, int hour, int minute, double second, ut_unit *user_unit, double *value, const char *calendar_name)