Skip to content

Commit

Permalink
Merge branch 'develop' into feature/modernisation-inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
joobog committed May 7, 2024
2 parents 7ddc88a + 7382fb3 commit 5d63a54
Show file tree
Hide file tree
Showing 22 changed files with 1,134 additions and 124 deletions.
4 changes: 2 additions & 2 deletions definitions/grib1/scanning_mode.def
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ flagbit jScansPositively(scanningMode,6) : dump;
flagbit jPointsAreConsecutive(scanningMode,5) : dump;
constant alternativeRowScanning=0 : dump;

transient iScansPositively = !iScansNegatively : constraint;
transient jScansNegatively = !jScansPositively : constraint;
transient iScansPositively = !iScansNegatively : constraint, read_only;
transient jScansNegatively = !jScansPositively : constraint, read_only;

alias geography.iScansNegatively=iScansNegatively;
alias geography.jScansPositively=jScansPositively;
Expand Down
4 changes: 2 additions & 2 deletions definitions/grib2/template.3.healpix.def
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ alias geography.orderingConvention = orderingConvention;
flags[1] scanningMode 'grib2/tables/[tablesVersion]/3.13.table';
flagbit iScansNegatively(scanningMode,7) : dump; # WMO bit 1
flagbit jScansPositively(scanningMode,6) : dump; # WMO bit 2
transient iScansPositively = !iScansNegatively : constraint;
transient jScansNegatively = !jScansPositively : constraint;
transient iScansPositively = !iScansNegatively : constraint, read_only;
transient jScansNegatively = !jScansPositively : constraint, read_only;

iterator healpix(numberOfPoints,missingValue,values,Nside,orderingConvention);
nearest healpix(values,radius,Nx,Ny);
Expand Down
4 changes: 2 additions & 2 deletions definitions/grib2/template.3.scanning_mode.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ alias geography.iScansNegatively=iScansNegatively;
alias geography.jScansPositively=jScansPositively;
alias geography.jPointsAreConsecutive=jPointsAreConsecutive;

transient iScansPositively = !iScansNegatively : constraint;
transient jScansNegatively = !jScansPositively : constraint;
transient iScansPositively = !iScansNegatively : constraint, read_only;
transient jScansNegatively = !jScansPositively : constraint, read_only;

flagbit scanningMode5(scanningMode,3) = 0: read_only;
flagbit scanningMode6(scanningMode,2) = 0: read_only;
Expand Down
2 changes: 1 addition & 1 deletion definitions/grib3/template.4.scanning_mode.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ alias geography.iScansNegatively=iScansNegatively;
alias geography.jScansPositively=jScansPositively;
alias geography.jPointsAreConsecutive=jPointsAreConsecutive;

transient iScansPositively = !iScansNegatively : constraint;
transient iScansPositively = !iScansNegatively : constraint, read_only;

flagbit scanningMode5(scanningMode,3) = 0: read_only;
flagbit scanningMode6(scanningMode,2) = 0: read_only;
Expand Down
14 changes: 1 addition & 13 deletions examples/C/new_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ int main(int argc, char** argv)
exit(1);
}

/* h = codes_grib_handle_new_from_samples(NULL, "GRIB2"); */
h = codes_handle_new_from_samples(NULL, "just a test");
h = codes_handle_new_from_samples(NULL, "nonexistentsample");
if (h) return 1;

h = codes_handle_new_from_samples(NULL, "GRIB2");
Expand Down Expand Up @@ -148,12 +147,6 @@ int main(int argc, char** argv)
CODES_CHECK(codes_set_long(h, "jScansPositively", 0), 0);
CODES_CHECK(codes_set_long(h, "jPointsAreConsecutive", 0), 0);
CODES_CHECK(codes_set_long(h, "alternativeRowScanning", 0), 0);
CODES_CHECK(codes_set_long(h, "iScansPositively", 1), 0);

/* ITERATOR */


/* NEAREST */

CODES_CHECK(codes_set_long(h, "timeRangeIndicator", 0), 0);
CODES_CHECK(codes_set_long(h, "NV", 0), 0);
Expand All @@ -165,15 +158,12 @@ int main(int argc, char** argv)

/* Parameter information */


/* 0 = Temperature (grib2/tables/4/4.1.0.table) */
CODES_CHECK(codes_set_long(h, "parameterCategory", 0), 0);


/* 0 = Temperature (K) (grib2/tables/4/4.2.0.0.table) */
CODES_CHECK(codes_set_long(h, "parameterNumber", 0), 0);


/* 0 = Analysis (grib2/tables/4/4.3.table) */
CODES_CHECK(codes_set_long(h, "typeOfGeneratingProcess", 0), 0);

Expand All @@ -185,7 +175,6 @@ int main(int argc, char** argv)
/* 1 = Hour (grib2/tables/4/4.4.table) */
CODES_CHECK(codes_set_long(h, "indicatorOfUnitOfTimeRange", 1), 0);


/* 1 = Hour (stepUnits.table) */
CODES_CHECK(codes_set_long(h, "stepUnits", 1), 0);

Expand Down Expand Up @@ -226,7 +215,6 @@ int main(int argc, char** argv)

/* grib 2 Section 6 BIT-MAP SECTION */


/* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */
CODES_CHECK(codes_set_long(h, "bitMapIndicator", 255), 0);

Expand Down
21 changes: 20 additions & 1 deletion src/accessor/grib_accessor_class_g2end_step.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len){
}
if (add_time_range) {
*val = start_step_value + time_range_value;
if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS)
return err;
}
else {
*val = start_step_value;
if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS)
return err;
}

return GRIB_SUCCESS;
Expand Down Expand Up @@ -174,9 +178,13 @@ int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* len){
}
if (add_time_range) {
*val = (start_step + time_range).value<double>(eccodes::Unit(step_units));
if ((err = grib_set_long_internal(h, "endStepUnit", step_units)) != GRIB_SUCCESS)
return err;
}
else {
*val = start_step.value<double>(eccodes::Unit(start_step_unit));
if ((err = grib_set_long_internal(h, "endStepUnit", start_step_unit)) != GRIB_SUCCESS)
return err;
}

return GRIB_SUCCESS;
Expand Down Expand Up @@ -302,14 +310,19 @@ int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, s
grib_handle* h = grib_handle_of_accessor(a);
int ret = 0;
long start_step_value;
long start_step_unit;
long numberOfTimeRange;

if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value)))
return ret;
if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)))
return ret;

/* point in time */
if (self->year == NULL) {
*val = start_step_value;
if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit)))
return ret;
return 0;
}

Expand Down Expand Up @@ -339,14 +352,19 @@ int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* va
grib_handle* h = grib_handle_of_accessor(a);
int ret = 0;
long start_step_value;
long start_step_unit;
long numberOfTimeRange;

if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value)))
return ret;
if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)))
return ret;

/* point in time */
if (self->year == NULL) {
*val = start_step_value;
if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit)))
return ret;
return 0;
}

Expand Down Expand Up @@ -401,7 +419,8 @@ int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_

/*point in time */
if (self->year == NULL) {
err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value<long>());
if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value<long>())) != GRIB_SUCCESS)
return err;
err = grib_set_long_internal(h, self->start_step_value, end_step.value<long>());
return err;
}
Expand Down
42 changes: 40 additions & 2 deletions src/accessor/grib_accessor_class_optimal_step_units.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const
grib_handle* h = grib_handle_of_accessor(a);
grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a;

long start_step = 0;
long start_step_unit = 0;
long end_step = 0;
long end_step_unit = 0;
int ret;

auto supported_units = eccodes::Unit::list_supported_units();
try {
eccodes::Unit unit{*val}; // throws if not supported
Expand All @@ -91,10 +97,42 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const
return GRIB_INVALID_ARGUMENT;
}

int ret;
// ECC-1813: When the stepUnits key is used without specifying a value, as in the command
// "grib-set -s stepUnits=m in.grib out.grib", the following code initiates an indirect update
// of the low-level keys: forecastTime,indicatorOfUnitOfTimeRange,indicatorOfUnitForTimeRange,lengthOfTimeRange

self->overwriteStepUnits = *val;
if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) {
if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS)
return ret;

if ((ret = grib_get_long_internal(h, "startStep", &start_step)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(h, "endStep", &end_step)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS)
return ret;

try {
eccodes::Step start{start_step, start_step_unit};
start.set_unit(*val);
eccodes::Step end{end_step, end_step_unit};
end.set_unit(*val);

if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value<long>())) != GRIB_SUCCESS)
return ret;
if ((ret = grib_set_long_internal(h, "startStep", start.value<long>())) != GRIB_SUCCESS)
return ret;
if ((ret = grib_set_long_internal(h, "endStepUnit", end.unit().value<long>())) != GRIB_SUCCESS)
return ret;
if ((ret = grib_set_long_internal(h, "endStep", end.value<long>())) != GRIB_SUCCESS)
return ret;
}
catch (std::exception& e) {
std::string msg = std::string{"Failed to convert steps to: "} + std::to_string(*val) + " (" + e.what() + ")";
grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str());
return GRIB_INTERNAL_ERROR;
}

return GRIB_SUCCESS;
Expand Down
Loading

0 comments on commit 5d63a54

Please sign in to comment.