mirror of https://github.com/ecmwf/eccodes.git
ECC-1620: Fix stepUnits
This commit is contained in:
parent
32aceb86a0
commit
5392a164b0
|
@ -14,7 +14,8 @@ codetable[1] indicatorOfUnitOfTimeRange ('4.4.table',masterDir,localDir) : dump
|
|||
#alias forecastTimeUnit = indicatorOfUnitOfTimeRange;
|
||||
#template_nofail default_step_units "grib2/localConcepts/[centre:s]/default_step_units.def";
|
||||
#codetable[1] stepUnits 'stepUnits.table' = defaultStepUnits : transient,dump,no_copy;
|
||||
meta stepUnits optimal_step_units(forecastTime,indicatorOfUnitOfTimeRange,lengthOfTimeRange,indicatorOfUnitForTimeRange) : dump;
|
||||
meta stepUnits optimal_step_units(forecastTime,indicatorOfUnitOfTimeRange,lengthOfTimeRange,indicatorOfUnitForTimeRange) : transient,dump;
|
||||
transient forceStepUnits = 255;
|
||||
transient startStepUnit = 255;
|
||||
transient endStepUnit = 255;
|
||||
|
||||
|
|
|
@ -536,7 +536,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en
|
|||
|
||||
//auto [forecast_time, time_range] = find_common_units(Step{forecast_time_value, forecast_time_unit}.optimize_unit(), Step{time_range_value, time_range_unit}.optimize_unit());
|
||||
//auto [forecast_time, time_range] = find_common_units(Step{start_step_value, step_units}.optimize_unit(), Step{time_range_value, time_range_unit}.optimize_unit());
|
||||
auto [forecast_time_opt, time_range_opt] = find_common_units(start_step, time_range);
|
||||
auto [forecast_time_opt, time_range_opt] = find_common_units(start_step.optimize_unit(), time_range.optimize_unit());
|
||||
|
||||
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value, time_range_opt.value<long>())) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
@ -592,12 +592,21 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
int ret;
|
||||
|
||||
long end_step_unit;
|
||||
if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS)
|
||||
long force_step_units;
|
||||
if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (end_step_unit == 255)
|
||||
end_step_unit = UnitType{Unit::HOUR}.to_long();
|
||||
long end_step_unit;
|
||||
if (force_step_units == 255) {
|
||||
if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (end_step_unit == 255)
|
||||
end_step_unit = UnitType{Unit::HOUR}.to_long();
|
||||
}
|
||||
else {
|
||||
end_step_unit = force_step_units;
|
||||
}
|
||||
|
||||
return pack_long_(a, *val, end_step_unit);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
CLASS = accessor
|
||||
SUPER = grib_accessor_class_gen
|
||||
IMPLEMENTS = pack_long,unpack_long;dump
|
||||
IMPLEMENTS = unpack_string,unpack_string;dump
|
||||
IMPLEMENTS = pack_string,unpack_string;dump
|
||||
IMPLEMENTS = string_length
|
||||
IMPLEMENTS = init
|
||||
MEMBERS = const char* forecast_time_value
|
||||
|
@ -137,22 +137,24 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
|
|||
}
|
||||
|
||||
|
||||
//static int value_count(grib_accessor* a, long* count)
|
||||
//{
|
||||
//*count = 1;
|
||||
//return 0;
|
||||
//}
|
||||
|
||||
static size_t string_length(grib_accessor* a)
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
static long staticStepUnits = UnitType{Unit::MISSING}.to_long();
|
||||
static long staticForceStepUnits = UnitType{Unit::MISSING}.to_long();
|
||||
|
||||
static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
|
||||
int ret;
|
||||
staticStepUnits = *val;
|
||||
if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
@ -189,7 +191,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
|||
|
||||
static int pack_string(grib_accessor* a, const char* val, size_t* len)
|
||||
{
|
||||
staticStepUnits = UnitType{val}.to_long();
|
||||
long unit = UnitType{val}.to_long();
|
||||
pack_long(a, &unit, len);
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ int pack_long_new_(grib_accessor* a, const long start_step_value, const long sta
|
|||
Step time_range_new{};
|
||||
|
||||
auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit);
|
||||
|
||||
|
||||
if (time_range_opt) {
|
||||
auto time_range = time_range_opt.value();
|
||||
time_range = time_range - (forecast_time - start_step_old);
|
||||
|
@ -308,15 +308,22 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
{
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
int ret;
|
||||
//long step_units = UnitType{Unit::HOUR}.to_long();
|
||||
|
||||
|
||||
long start_step_unit;
|
||||
if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS)
|
||||
long force_step_units;
|
||||
if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (start_step_unit == 255)
|
||||
start_step_unit = UnitType{Unit::HOUR}.to_long();
|
||||
long start_step_unit;
|
||||
if (force_step_units == 255) {
|
||||
if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS)
|
||||
return ret;
|
||||
|
||||
if (start_step_unit == 255)
|
||||
start_step_unit = UnitType{Unit::HOUR}.to_long();
|
||||
}
|
||||
else {
|
||||
start_step_unit = force_step_units;
|
||||
}
|
||||
|
||||
ret = pack_long_new_(a, *val, start_step_unit);
|
||||
|
||||
|
|
|
@ -52,12 +52,20 @@ low_level_keys="forecastTime,indicatorOfUnitOfTimeRange:s,lengthOfTimeRange,indi
|
|||
${tools_dir}/grib_set -s forecastTime=24,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=1,indicatorOfUnitForTimeRange=D $fn $temp
|
||||
grib_check_key_equals $temp "-p $low_level_keys" "24 h 1 D"
|
||||
|
||||
${tools}/grib_set -s startStep:i=60,endStep:i=180,stepUnits:s=s $temp $temp2
|
||||
${tools_dir}/grib_set -s stepUnits:i=13,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "1 m 2 m"
|
||||
${tools}/grib_set -s startStep:i=60,endStep:i=180,stepUnits:s=m $temp $temp2
|
||||
${tools_dir}/grib_set -s stepUnits:s=s,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "1 m 2 m"
|
||||
|
||||
${tools_dir}/grib_set -s stepUnits:i=0,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "1 h 2 h"
|
||||
${tools}/grib_set -s startStep:i=60,endStep:i=180,stepUnits:s=h $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 180 h"
|
||||
${tools_dir}/grib_set -s stepUnits:s=m,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "1 h 2 h"
|
||||
|
||||
${tools_dir}/grib_set -s stepUnits:i=1,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 120 h"
|
||||
${tools_dir}/grib_set -s stepUnits:s=h,startStep:i=60,endStep:i=180 $temp $temp2
|
||||
grib_check_key_equals $temp2 "-p $low_level_keys" "60 h 120 h"
|
||||
|
||||
|
||||
#fn="${data_dir}/reduced_gaussian_sub_area.grib2"
|
||||
|
|
Loading…
Reference in New Issue