Skip to content

Commit 0100fb4

Browse files
committed
reworked, to use long as soon as we can
1 parent ff22ae1 commit 0100fb4

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/metkit/codes/GRIBDecoder.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ bool GRIBDecoder::match(const eckit::message::Message& msg) const {
3737
(p[0] == 'B' and p[1] == 'U' and p[2] == 'D' and p[3] == 'G'));
3838
}
3939

40+
namespace {
41+
bool isInteger(double val) {
42+
double intpart;
43+
return std::modf(val, &intpart) == 0.0;
44+
}
45+
} // namespace
46+
4047

4148
void GRIBDecoder::getMetadata(const eckit::message::Message& msg, eckit::message::MetadataGatherer& gather,
4249
const eckit::message::GetMetadataOptions& options) const {
@@ -59,9 +66,15 @@ void GRIBDecoder::getMetadata(const eckit::message::Message& msg, eckit::message
5966

6067
switch (options.valueRepresentation) {
6168
case eckit::message::ValueRepresentation::String: {
69+
// TODO - remove as soon as https://jira.ecmwf.int/browse/ECC-2113 is fixed
6270
if (k.name() == "levelist") {
63-
eckit::Translator<double, std::string> t;
64-
gather.setValue(name, t(k.getDouble()));
71+
double val = k.getDouble();
72+
if (isInteger(val)) {
73+
gather.setValue(name, eckit::translate<std::string>(static_cast<long>(val)));
74+
}
75+
else {
76+
gather.setValue(name, eckit::translate<std::string>(val));
77+
}
6578
}
6679
else {
6780
gather.setValue(name, k.getString());
@@ -72,8 +85,15 @@ void GRIBDecoder::getMetadata(const eckit::message::Message& msg, eckit::message
7285
std::visit(
7386
[&](auto&& v) {
7487
using Type = std::decay_t<decltype(v)>;
88+
// TODO - remove as soon as https://jira.ecmwf.int/browse/ECC-2113 is fixed
7589
if (k.name() == "levelist") {
76-
gather.setValue(name, k.getDouble());
90+
double val = k.getDouble();
91+
if (isInteger(val)) {
92+
gather.setValue(name, static_cast<long>(val));
93+
}
94+
else {
95+
gather.setValue(name, val);
96+
}
7797
}
7898
else if constexpr (std::is_same_v<Type, std::string> || std::is_arithmetic_v<Type>) {
7999
gather.setValue(name, std::forward<decltype(v)>(v));

0 commit comments

Comments
 (0)