Skip to content

Commit

Permalink
Default native step type is string. It's long if unit is not shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
joobog committed Jan 19, 2024
1 parent afc918b commit b8830c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/grib_accessor_class_g2end_step.cc
Original file line number Diff line number Diff line change
Expand Up @@ -744,14 +744,15 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)

static int get_native_type(grib_accessor* a)
{
// TODO: Still experimental.
// Change the type to depend on the stepUnits for backward compatibility

grib_handle* h = grib_handle_of_accessor(a);
long step_units = 0;
if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) {
if (step_units == 1) {
return GRIB_TYPE_LONG;
int show_hours = a->context->show_hour_stepunit;

if (!show_hours) {
long step_units = 0;
if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) {
if (eccodes::Unit{step_units} == eccodes::Unit::Value::HOUR) {
return GRIB_TYPE_LONG;
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/grib_accessor_class_step_in_units.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,16 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)

static int get_native_type(grib_accessor* a)
{
// TODO: Still experimental.
// Change the type to depend on the stepUnits for backward compatibility

grib_handle* h = grib_handle_of_accessor(a);
long step_units = 0;
if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) {
if (step_units == 1) {
return GRIB_TYPE_LONG;
int show_hours = a->context->show_hour_stepunit;

if (!show_hours) {
long step_units = 0;
if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) {
if (eccodes::Unit{step_units} == eccodes::Unit::Value::HOUR) {
return GRIB_TYPE_LONG;
}
}
}

return GRIB_TYPE_STRING;
}

0 comments on commit b8830c3

Please sign in to comment.