diff --git a/.github/ci-nightly-test.sh b/.github/ci-nightly-test.sh index c1221ccd8..f83f9ad06 100644 --- a/.github/ci-nightly-test.sh +++ b/.github/ci-nightly-test.sh @@ -14,13 +14,13 @@ module load python3 version=$(cat $TMPDIR/eccodes/VERSION) -regression_suite_dir=$TMPDIR/eccodes-regression-tests -mkdir -p $regression_suite_dir -git clone git@github.com:ecmwf/eccodes-regression-tests.git $regression_suite_dir +# regression_suite_dir=$TMPDIR/eccodes-regression-tests +# mkdir -p $regression_suite_dir +# git clone git@github.com:ecmwf/eccodes-regression-tests.git $regression_suite_dir # cd $regression_suite_dir cd ~masn/REGRESSION_TESTING/ecCodes ./par-suite.sh -w $TMPDIR/install/eccodes/$version # For debugging specific test(s) -# ./seq-suite.sh -w $TMPDIR/install/eccodes/$version -d -t py_ +# ./seq-suite.sh -w $TMPDIR/install/eccodes/$version -d -t $test_name diff --git a/definitions/grib2/local/ecmf/section4_extras.def b/definitions/grib2/local/ecmf/section4_extras.def index 2477b2481..0d70c1ac9 100644 --- a/definitions/grib2/local/ecmf/section4_extras.def +++ b/definitions/grib2/local/ecmf/section4_extras.def @@ -4,7 +4,7 @@ if (centre is "ecmf" or datasetForLocal is "era6") { concept modelName(unknown, "modelNameConcept.def", conceptsMasterDir, conceptsLocalDirAll): no_copy, dump, read_only; - if (!(modelName is "unknown")) { + if (modelName isnot "unknown") { concept modelVersion(unknown, "modelVersionConcept_[modelName].def", conceptsMasterDir, conceptsLocalDirAll): no_copy, dump, read_only; # alias ls.model = modelName; # alias mars.model = modelName; diff --git a/definitions/grib2/post_meta_data.hook.products_12.def b/definitions/grib2/post_meta_data.hook.products_12.def index f01e08f71..e80da9e03 100644 --- a/definitions/grib2/post_meta_data.hook.products_12.def +++ b/definitions/grib2/post_meta_data.hook.products_12.def @@ -9,6 +9,6 @@ concept destineOrigin(unknown, "destineOriginConcept.def", conceptsDir2, concept unalias mars.domain; # ECC-1796: stepRange indexing for DestinE ExtremesDT and On-Demand ExtremesDT data -if ( defined(dataset) && !(dataset is "climate-dt") ) { +if ( defined(dataset) && dataset isnot "climate-dt" ) { alias mars.step=stepRange; } diff --git a/definitions/grib2/section.4.def b/definitions/grib2/section.4.def index c40709877..edb34d9b7 100644 --- a/definitions/grib2/section.4.def +++ b/definitions/grib2/section.4.def @@ -51,7 +51,7 @@ concept datasetForLocal(unknown) { "unknown" = { dummy=1; } } -if (!(datasetForLocal is "unknown")) { +if (datasetForLocal isnot "unknown") { constant conceptsDir2 = "grib2/localConcepts/[datasetForLocal]": hidden; constant conceptsDir1 = "grib2": hidden; } diff --git a/definitions/grib2/template.3.resolution_flags.def b/definitions/grib2/template.3.resolution_flags.def index 01c65f762..78e0eecaf 100644 --- a/definitions/grib2/template.3.resolution_flags.def +++ b/definitions/grib2/template.3.resolution_flags.def @@ -1,19 +1,18 @@ # (C) Copyright 2005- ECMWF. -# Resolution and component flags flags[1] resolutionAndComponentFlags 'grib2/tables/[tablesVersion]/3.3.table' : edition_specific,no_copy; # Note our flagbit numbers run from 7 to 0, while WMO convention uses 1 to 8 # (most significant to least significant) -flagbit resolutionAndComponentFlags1(resolutionAndComponentFlags,7) = 0: read_only; -flagbit resolutionAndComponentFlags2(resolutionAndComponentFlags,6) = 0: read_only; +flagbit resolutionAndComponentFlags1(resolutionAndComponentFlags,7) = 0: read_only; #Reserved +flagbit resolutionAndComponentFlags2(resolutionAndComponentFlags,6) = 0: read_only; #Reserved flagbit iDirectionIncrementGiven(resolutionAndComponentFlags,5); flagbit jDirectionIncrementGiven(resolutionAndComponentFlags,4); flagbit uvRelativeToGrid(resolutionAndComponentFlags,3); -flagbit resolutionAndComponentFlags6(resolutionAndComponentFlags,7) = 0: read_only; -flagbit resolutionAndComponentFlags7(resolutionAndComponentFlags,6) = 0: read_only; -flagbit resolutionAndComponentFlags8(resolutionAndComponentFlags,6) = 0: read_only; +flagbit resolutionAndComponentFlags6(resolutionAndComponentFlags,2) = 0: read_only; #Reserved +flagbit resolutionAndComponentFlags7(resolutionAndComponentFlags,1) = 0: read_only; #Reserved +flagbit resolutionAndComponentFlags8(resolutionAndComponentFlags,0) = 0: read_only; #Reserved concept ijDirectionIncrementGiven { '1' = { diff --git a/definitions/grib2/template.3.scanning_mode.def b/definitions/grib2/template.3.scanning_mode.def index 1be608f41..1028d290d 100644 --- a/definitions/grib2/template.3.scanning_mode.def +++ b/definitions/grib2/template.3.scanning_mode.def @@ -23,10 +23,11 @@ alias geography.jPointsAreConsecutive=jPointsAreConsecutive; 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; -flagbit scanningMode7(scanningMode,1) = 0: read_only; -flagbit scanningMode8(scanningMode,0) = 0: read_only; +# The following modes are not yet supported +flagbit scanningMode5(scanningMode,3) = 0: read_only; #Points within odd rows... +flagbit scanningMode6(scanningMode,2) = 0: read_only; #Points within even rows... +flagbit scanningMode7(scanningMode,1) = 0: read_only; #Points offset +flagbit scanningMode8(scanningMode,0) = 0: read_only; #Rows have Ni grid points... meta swapScanningX change_scanning_direction( values,Ni,Nj, diff --git a/definitions/mars/grib.mmsf.an.def b/definitions/mars/grib.mmsf.an.def index 0a489319c..86ccb55b5 100644 --- a/definitions/mars/grib.mmsf.an.def +++ b/definitions/mars/grib.mmsf.an.def @@ -1,15 +1,16 @@ #no step in type an unalias mars.step; -if (class is "od") { alias mars.system = systemNumber; } -if (class is "me") { alias mars.system = systemNumber; } -if (class is "en") { alias mars.system = systemNumber; } -if (class is "c3") { alias mars.system = systemNumber; } -if (class is "ci") { alias mars.system = systemNumber; } +if (class is "od" || class is "me" || class is "en" || + class is "c3" || class is "ci") +{ + alias mars.system = systemNumber; +} + alias mars.number = perturbationNumber; alias mars.method = methodNumber; -if (!(class is "gw")) { # ECC-1448 +if (class isnot "gw") { # ECC-1448 alias mars.origin = centre; } @@ -20,4 +21,3 @@ if (centre == 80 && subCentre == 98 && class is "c3") { } if (class is "ci") { unalias mars.method; } - diff --git a/definitions/mars/grib.mmsf.fc.def b/definitions/mars/grib.mmsf.fc.def index c002f9d76..30b2f7394 100644 --- a/definitions/mars/grib.mmsf.fc.def +++ b/definitions/mars/grib.mmsf.fc.def @@ -4,15 +4,16 @@ if (levtype is "o2d" || levtype is "o3d") { alias mars.step = endStep; } -if (class is "od") { alias mars.system = systemNumber; } -if (class is "me") { alias mars.system = systemNumber; } -if (class is "en") { alias mars.system = systemNumber; } -if (class is "c3") { alias mars.system = systemNumber; } -if (class is "ci") { alias mars.system = systemNumber; } +if (class is "od" || class is "me" || class is "en" || + class is "c3" || class is "ci") +{ + alias mars.system = systemNumber; +} + alias mars.number = perturbationNumber; alias mars.method = methodNumber; -if (!(class is "gw")) { # ECC-1448 +if (class isnot "gw") { # ECC-1448 alias mars.origin = centre; } @@ -23,4 +24,3 @@ if (centre == 80 && subCentre == 98 && class is "c3") { } if (class is "ci") { unalias mars.method; } - diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index b9059220f..06163f8d2 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -101,6 +100,7 @@ static int extra_set(grib_accessor* a, long val) long is_chemical_srcsink = 0; long is_aerosol = 0; long is_aerosol_optical = 0; + long is_wave = 0, is_wave_prange = 0; grib_get_long(hand, "is_chemical", &is_chemical); grib_get_long(hand, "is_chemical_srcsink", &is_chemical_srcsink); @@ -108,6 +108,9 @@ static int extra_set(grib_accessor* a, long val) grib_get_long(hand, "is_aerosol", &is_aerosol); grib_get_long(hand, "is_aerosol_optical", &is_aerosol_optical); + is_wave = grib_is_defined(hand, "waveDirectionNumber"); + is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval"); + switch (self->index) { case 0: /* class */ @@ -287,6 +290,11 @@ static int extra_set(grib_accessor* a, long val) return GRIB_INTERNAL_ERROR; } + if (is_wave || is_wave_prange) { + // ECC-1867 + productDefinitionTemplateNumberNew = -1; // disable PDT selection + } + if (productDefinitionTemplateNumberNew >= 0) { grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) diff --git a/src/accessor/grib_accessor_class_gen.cc b/src/accessor/grib_accessor_class_gen.cc index 7223f39a9..3a721f196 100644 --- a/src/accessor/grib_accessor_class_gen.cc +++ b/src/accessor/grib_accessor_class_gen.cc @@ -202,13 +202,11 @@ void grib_accessor_gen_t::destroy(grib_context* ct) } - - // ======================== grib_accessor_class_gen ======================== -grib_accessor_class_gen_t _grib_accessor_class_gen = grib_accessor_class_gen_t("gen"); -grib_accessor_class* grib_accessor_class_gen = &_grib_accessor_class_gen; +grib_accessor_class_gen_t _grib_accessor_class_gen = grib_accessor_class_gen_t("gen"); +grib_accessor_class* grib_accessor_class_gen = &_grib_accessor_class_gen; void grib_accessor_class_gen_t::init(grib_accessor* a, const long len, grib_arguments* param) { @@ -229,7 +227,7 @@ void grib_accessor_class_gen_t::init(grib_accessor* a, const long len, grib_argu grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0); int type = grib_expression_native_type(grib_handle_of_accessor(a), expression); switch (type) { - // TODO(maee): add single-precision case + // TODO(maee): add single-precision case case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); @@ -313,8 +311,8 @@ long grib_accessor_class_gen_t::byte_offset(grib_accessor* a) int grib_accessor_class_gen_t::unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) { unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = a->byte_count(); - const long offset = a->byte_offset(); + const long length = a->byte_count(); + const long offset = a->byte_offset(); if (*len < length) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it is %ld bytes long", a->name, length); @@ -331,8 +329,8 @@ int grib_accessor_class_gen_t::unpack_bytes(grib_accessor* a, unsigned char* val int grib_accessor_class_gen_t::clear(grib_accessor* a) { unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = a->byte_count(); - const long offset = a->byte_offset(); + const long length = a->byte_count(); + const long offset = a->byte_offset(); memset(buf + offset, 0, length); @@ -342,7 +340,7 @@ int grib_accessor_class_gen_t::clear(grib_accessor* a) int grib_accessor_class_gen_t::unpack_long(grib_accessor* a, long* v, size_t* len) { is_overridden_[UNPACK_LONG] = 0; - int type = GRIB_TYPE_UNDEFINED; + int type = GRIB_TYPE_UNDEFINED; if (is_overridden_[UNPACK_DOUBLE] == 1) { double val = 0.0; size_t l = 1; @@ -398,7 +396,7 @@ int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* if (is_overridden_[UNPACK_DOUBLE] == 1) { double val = 0.0; size_t l = 1; - err = a->unpack_double(&val, &l); + err = a->unpack_double(&val, &l); if (is_overridden_[UNPACK_DOUBLE] == 1) { if (err) return err; snprintf(v, 64, "%g", val); @@ -411,7 +409,7 @@ int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* if (is_overridden_[UNPACK_LONG] == 1) { long val = 0; size_t l = 1; - err = a->unpack_long(&val, &l); + err = a->unpack_long(&val, &l); if (is_overridden_[UNPACK_LONG] == 1) { if (err) return err; snprintf(v, 64, "%ld", val); @@ -432,7 +430,7 @@ int grib_accessor_class_gen_t::unpack_string_array(grib_accessor* a, char** v, s if (err) return err; v[0] = (char*)grib_context_malloc_clear(a->context, length); - a->unpack_string(v[0], &length); // TODO(masn): check return value + a->unpack_string(v[0], &length); // TODO(masn): check return value *len = 1; return GRIB_SUCCESS; @@ -497,7 +495,7 @@ int grib_accessor_class_gen_t::pack_expression(grib_accessor* a, grib_expression int grib_accessor_class_gen_t::pack_long(grib_accessor* a, const long* v, size_t* len) { is_overridden_[PACK_LONG] = 0; - grib_context* c = a->context; + grib_context* c = a->context; if (is_overridden_[PACK_DOUBLE]) { double* val = (double*)grib_context_malloc(c, *len * (sizeof(double))); if (!val) { @@ -541,7 +539,7 @@ int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* len) int grib_accessor_class_gen_t::pack_double(grib_accessor* a, const double* v, size_t* len) { is_overridden_[PACK_DOUBLE] = 0; - grib_context* c = a->context; + grib_context* c = a->context; if (is_overridden_[PACK_LONG] || strcmp(a->cclass->name, "codetable") == 0) { /* ECC-648: Special case of codetable */ @@ -561,7 +559,7 @@ int grib_accessor_class_gen_t::pack_string_array(grib_accessor* a, const char** size_t length = 0; grib_accessor* as = 0; - as = a; + as = a; long i = (long)*len - 1; while (as && i >= 0) { length = strlen(v[i]); @@ -578,9 +576,9 @@ int grib_accessor_class_gen_t::pack_string(grib_accessor* a, const char* v, size { is_overridden_[PACK_STRING] = 0; if (is_overridden_[PACK_DOUBLE]) { - size_t l = 1; + size_t l = 1; char* endPtr = NULL; /* for error handling */ - double val = strtod(v, &endPtr); + double val = strtod(v, &endPtr); if (*endPtr) { grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid value (%s) for key '%s'. String cannot be converted to a double", @@ -593,7 +591,7 @@ int grib_accessor_class_gen_t::pack_string(grib_accessor* a, const char* v, size if (is_overridden_[PACK_LONG]) { size_t l = 1; long val = atol(v); - int err = a->pack_long(&val, &l); + int err = a->pack_long(&val, &l); if (is_overridden_[PACK_LONG]) { return err; } @@ -721,31 +719,37 @@ grib_accessor* grib_accessor_class_gen_t::make_clone(grib_accessor* a, grib_sect } +grib_accessor_class_gen_t::~grib_accessor_class_gen_t() {}; - -grib_accessor_class_gen_t::~grib_accessor_class_gen_t(){}; - -void grib_accessor_class_gen_t::post_init(grib_accessor*){ +void grib_accessor_class_gen_t::post_init(grib_accessor*) +{ return; }; -int grib_accessor_class_gen_t::pack_missing(grib_accessor*) { +int grib_accessor_class_gen_t::pack_missing(grib_accessor*) +{ throw std::runtime_error("grib_accessor_class_gen_t::pack_missing not implemented"); }; -int grib_accessor_class_gen_t::pack_float(grib_accessor*, const float*, size_t* len) { +int grib_accessor_class_gen_t::pack_float(grib_accessor*, const float*, size_t* len) +{ throw std::runtime_error("grib_accessor_class_gen_t::pack_float not implemented"); }; -void grib_accessor_class_gen_t::resize(grib_accessor*, size_t) { +void grib_accessor_class_gen_t::resize(grib_accessor*, size_t) +{ throw std::runtime_error("grib_accessor_class_gen_t::resize not implemented"); }; -int grib_accessor_class_gen_t::nearest_smaller_value(grib_accessor*, double, double*) { +int grib_accessor_class_gen_t::nearest_smaller_value(grib_accessor*, double, double*) +{ throw std::runtime_error("grib_accessor_class_gen_t::nearest_smaller_value not implemented"); }; -int grib_accessor_class_gen_t::unpack_float_element(grib_accessor*, size_t, float*) { +int grib_accessor_class_gen_t::unpack_float_element(grib_accessor*, size_t, float*) +{ throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element not implemented"); }; -int unpack_element_set(grib_accessor*, const size_t*, size_t, double*) { +int unpack_element_set(grib_accessor*, const size_t*, size_t, double*) +{ throw std::runtime_error("grib_accessor_class_gen_t::unpack_element_set not implemented"); }; -int grib_accessor_class_gen_t::unpack_float_element_set(grib_accessor*, const size_t*, size_t, float*) { +int grib_accessor_class_gen_t::unpack_float_element_set(grib_accessor*, const size_t*, size_t, float*) +{ throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element_set not implemented"); }; diff --git a/src/accessor/grib_accessor_class_getenv.cc b/src/accessor/grib_accessor_class_getenv.cc index d812cc276..a6d6f9c72 100644 --- a/src/accessor/grib_accessor_class_getenv.cc +++ b/src/accessor/grib_accessor_class_getenv.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,14 +10,15 @@ #include "grib_accessor_class_getenv.h" -grib_accessor_class_getenv_t _grib_accessor_class_getenv{"getenv"}; +grib_accessor_class_getenv_t _grib_accessor_class_getenv{ "getenv" }; grib_accessor_class* grib_accessor_class_getenv = &_grib_accessor_class_getenv; -void grib_accessor_class_getenv_t::init(grib_accessor* a, const long l, grib_arguments* args){ +void grib_accessor_class_getenv_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ grib_accessor_class_ascii_t::init(a, l, args); grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; - static char undefined[] = "undefined"; + static char undefined[] = "undefined"; self->name = grib_arguments_get_string(grib_handle_of_accessor(a), args, 0); self->default_value = grib_arguments_get_string(grib_handle_of_accessor(a), args, 1); @@ -27,14 +27,16 @@ void grib_accessor_class_getenv_t::init(grib_accessor* a, const long l, grib_arg self->value = 0; } -int grib_accessor_class_getenv_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_getenv_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_getenv_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_getenv_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; - char* v = 0; - size_t l = 0; + char* v = 0; + size_t l = 0; if (!self->value) { v = getenv(self->name); @@ -52,11 +54,13 @@ int grib_accessor_class_getenv_t::unpack_string(grib_accessor* a, char* val, siz return GRIB_SUCCESS; } -int grib_accessor_class_getenv_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_getenv_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -size_t grib_accessor_class_getenv_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_getenv_t::string_length(grib_accessor* a) +{ return 1024; } diff --git a/src/accessor/grib_accessor_class_global_gaussian.cc b/src/accessor/grib_accessor_class_global_gaussian.cc index 34ac67881..7fa8c96e6 100644 --- a/src/accessor/grib_accessor_class_global_gaussian.cc +++ b/src/accessor/grib_accessor_class_global_gaussian.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,15 +10,16 @@ #include "grib_accessor_class_global_gaussian.h" -grib_accessor_class_global_gaussian_t _grib_accessor_class_global_gaussian{"global_gaussian"}; +grib_accessor_class_global_gaussian_t _grib_accessor_class_global_gaussian{ "global_gaussian" }; grib_accessor_class* grib_accessor_class_global_gaussian = &_grib_accessor_class_global_gaussian; -void grib_accessor_class_global_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_global_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); self->N = grib_arguments_get_name(h, c, n++); self->Ni = grib_arguments_get_name(h, c, n++); @@ -34,9 +34,10 @@ void grib_accessor_class_global_gaussian_t::init(grib_accessor* a, const long l, self->subdivision = grib_arguments_get_name(h, c, n++); } -int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, basic_angle, subdivision, N, Ni; double dlatfirst, dlatlast, dlonfirst, dlonlast; double angular_precision = 0; @@ -140,9 +141,10 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v return ret; } -int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, di, diold, basic_angle = 0, N, Ni; long factor; double* lats; diff --git a/src/accessor/grib_accessor_class_julian_date.cc b/src/accessor/grib_accessor_class_julian_date.cc index e633b42e4..945f4e803 100644 --- a/src/accessor/grib_accessor_class_julian_date.cc +++ b/src/accessor/grib_accessor_class_julian_date.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,16 +10,16 @@ #include "grib_accessor_class_julian_date.h" -grib_accessor_class_julian_date_t _grib_accessor_class_julian_date{"julian_date"}; +grib_accessor_class_julian_date_t _grib_accessor_class_julian_date{ "julian_date" }; grib_accessor_class* grib_accessor_class_julian_date = &_grib_accessor_class_julian_date; - -void grib_accessor_class_julian_date_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_julian_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_double_t::init(a, l, c); grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); self->year = grib_arguments_get_name(h, c, n++); self->month = grib_arguments_get_name(h, c, n++); @@ -51,15 +50,17 @@ void grib_accessor_class_julian_date_t::init(grib_accessor* a, const long l, gri a->length = 0; } -void grib_accessor_class_julian_date_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_julian_date_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_string(dumper, a, NULL); } -int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; if (self->ymd == NULL) { @@ -108,12 +109,14 @@ int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* v return ret; } -int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - int ret = 0; - long hour = 0; - long minute = 0; - long second = 0; + + int ret = 0; + long hour = 0; + long minute = 0; + long second = 0; long ymd = 0, hms = 0; long year, month, day; grib_handle* h = grib_handle_of_accessor(a); @@ -157,13 +160,14 @@ int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const doubl return ret; } -int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - char* sep = self->sep; - grib_handle* h = grib_handle_of_accessor(a); + char* sep = self->sep; + grib_handle* h = grib_handle_of_accessor(a); if (*len < 15) return GRIB_BUFFER_TOO_SMALL; @@ -210,7 +214,8 @@ int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val } if (sep[1] != 0 && sep[2] != 0 && sep[3] != 0 && sep[4] != 0) { - snprintf(val, 1024, "%04ld%c%02ld%c%02ld%c%02ld%c%02ld%c%02ld", year, sep[0], month, sep[1], day, sep[2], hour, sep[3], minute, sep[4], second); + snprintf(val, 1024, "%04ld%c%02ld%c%02ld%c%02ld%c%02ld%c%02ld", + year, sep[0], month, sep[1], day, sep[2], hour, sep[3], minute, sep[4], second); } else if (sep[0] != 0) { snprintf(val, 1024, "%04ld%02ld%02ld%c%02ld%02ld%02ld", year, month, day, sep[0], hour, minute, second); @@ -218,19 +223,21 @@ int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val else { snprintf(val, 1024, "%04ld%02ld%02ld%02ld%02ld%02ld", year, month, day, hour, minute, second); } - *len = strlen(val)+1; + *len = strlen(val) + 1; return ret; } -int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - char* sep = self->sep; - grib_handle* h = grib_handle_of_accessor(a); + char* sep = self->sep; + grib_handle* h = grib_handle_of_accessor(a); - ret = sscanf(val, "%04ld%c%02ld%c%02ld%c%02ld%c%02ld%c%02ld", &year, &sep[0], &month, &sep[1], &day, &sep[2], &hour, &sep[3], &minute, &sep[4], &second); + ret = sscanf(val, "%04ld%c%02ld%c%02ld%c%02ld%c%02ld%c%02ld", + &year, &sep[0], &month, &sep[1], &day, &sep[2], &hour, &sep[3], &minute, &sep[4], &second); if (ret != 11) { if (strlen(val) == 15) { ret = sscanf(val, "%04ld%02ld%02ld%c%02ld%02ld%02ld", &year, &month, &day, &sep[0], &hour, &minute, &second); @@ -292,16 +299,19 @@ int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* return ret; } -int grib_accessor_class_julian_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_julian_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot unpack %s as long", a->name); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_julian_date_t::pack_long(grib_accessor* a, const long* v, size_t* len){ +int grib_accessor_class_julian_date_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot pack %s as long", a->name); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_expression* e){ +int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_expression* e) +{ size_t len = 1; long lval = 0; double dval = 0; @@ -319,14 +329,16 @@ int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_ex } /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %ld\n", a->name,lval);*/ - return a->pack_long(&lval, &len); } + return a->pack_long(&lval, &len); + } case GRIB_TYPE_DOUBLE: { len = 1; ret = grib_expression_evaluate_double(hand, e, &dval); /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %g\n", a->name, dval);*/ - return a->pack_double(&dval, &len); } + return a->pack_double(&dval, &len); + } case GRIB_TYPE_STRING: { char tmp[1024]; @@ -339,7 +351,8 @@ int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_ex len = strlen(cval); /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %s\n", a->name, cval);*/ - return a->pack_string(cval, &len); } + return a->pack_string(cval, &len); + } } return GRIB_NOT_IMPLEMENTED; diff --git a/src/accessor/grib_accessor_class_julian_day.cc b/src/accessor/grib_accessor_class_julian_day.cc index e46751181..a27772e6b 100644 --- a/src/accessor/grib_accessor_class_julian_day.cc +++ b/src/accessor/grib_accessor_class_julian_day.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,14 +10,15 @@ #include "grib_accessor_class_julian_day.h" -grib_accessor_class_julian_day_t _grib_accessor_class_julian_day{"julian_day"}; +grib_accessor_class_julian_day_t _grib_accessor_class_julian_day{ "julian_day" }; grib_accessor_class* grib_accessor_class_julian_day = &_grib_accessor_class_julian_day; -void grib_accessor_class_julian_day_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_julian_day_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_double_t::init(a, l, c); grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; - int n = 0; + int n = 0; self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->hour = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -28,22 +28,26 @@ void grib_accessor_class_julian_day_t::init(grib_accessor* a, const long l, grib a->length = 0; } -void grib_accessor_class_julian_day_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_julian_day_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_string(dumper, a, NULL); } -int grib_accessor_class_julian_day_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_julian_day_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ const double v = *val; return pack_double(a, &v, len); } -int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double* val, size_t* len){ +int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; - int ret = 0; - long hour = 0; - long minute = 0; - long second = 0; - long date = 0; + + int ret = 0; + long hour = 0; + long minute = 0; + long second = 0; + long date = 0; long year, month, day; ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second); @@ -66,17 +70,18 @@ int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double return ret; } -int grib_accessor_class_julian_day_t::unpack_long(grib_accessor* a, long* val, size_t* len){ - int ret = 0; +int grib_accessor_class_julian_day_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ double v = 0; - ret = unpack_double(a, &v, len); + int ret = unpack_double(a, &v, len); *val = (long)v; return ret; } -int grib_accessor_class_julian_day_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_julian_day_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ int ret = 0; long date, hour, minute, second; long year, month, day; diff --git a/src/accessor/grib_accessor_class_local_definition.cc b/src/accessor/grib_accessor_class_local_definition.cc index 0964a3005..95f671118 100644 --- a/src/accessor/grib_accessor_class_local_definition.cc +++ b/src/accessor/grib_accessor_class_local_definition.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,15 +10,16 @@ #include "grib_accessor_class_local_definition.h" -grib_accessor_class_local_definition_t _grib_accessor_class_local_definition{"local_definition"}; +grib_accessor_class_local_definition_t _grib_accessor_class_local_definition{ "local_definition" }; grib_accessor_class* grib_accessor_class_local_definition = &_grib_accessor_class_local_definition; -void grib_accessor_class_local_definition_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_local_definition_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_unsigned_t::init(a, l, c); grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; self->grib2LocalSectionNumber = grib_arguments_get_name(hand, c, n++); self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); @@ -32,15 +32,18 @@ void grib_accessor_class_local_definition_t::init(grib_accessor* a, const long l self->derivedForecast = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_local_definition_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_local_definition_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; return grib_get_long(grib_handle_of_accessor(a), self->grib2LocalSectionNumber, val); } -int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const long* val, size_t* len){ - grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; +int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; grib_handle* hand = grib_handle_of_accessor(a); + long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberInternal = -1; long productDefinitionTemplateNumberNew = -1; @@ -90,8 +93,8 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo if (grib_is_defined(hand, "perturbationNumber")) { eps = 1; } - //if (grib2_is_PDTN_EPS(productDefinitionTemplateNumber)) - // eps = 1; + // if (grib2_is_PDTN_EPS(productDefinitionTemplateNumber)) + // eps = 1; switch (localDefinitionNumber) { case 0: @@ -107,10 +110,10 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo productDefinitionTemplateNumberNew = 0; break; - case 1: // MARS labelling - case 36: // MARS labelling for long window 4Dvar system - case 40: // MARS labeling with domain and model (for LAM) - case 42: // LC-WFV: Wave forecast verification + case 1: // MARS labelling + case 36: // MARS labelling for long window 4Dvar system + case 40: // MARS labeling with domain and model (for LAM) + case 42: // LC-WFV: Wave forecast verification if (isInstant) { // type=em || type=es if (type == 17) { @@ -148,7 +151,7 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo } } break; - case 41: // EFAS: uses post-processing templates + case 41: // EFAS: uses post-processing templates if (isInstant) { if (eps == 1) productDefinitionTemplateNumberNew = 71; @@ -164,12 +167,12 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo } break; - case 15: // Seasonal forecast data - case 16: // Seasonal forecast monthly mean data - case 12: // Seasonal forecast monthly mean data for lagged systems - case 18: // Multianalysis ensemble data - case 26: // MARS labelling or ensemble forecast data - case 30: // Forecasting Systems with Variable Resolution + case 15: // Seasonal forecast data + case 16: // Seasonal forecast monthly mean data + case 12: // Seasonal forecast monthly mean data for lagged systems + case 18: // Multianalysis ensemble data + case 26: // MARS labelling or ensemble forecast data + case 30: // Forecasting Systems with Variable Resolution if (isInstant) { productDefinitionTemplateNumberNew = 1; } @@ -178,21 +181,21 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo } break; - case 5: // Forecast probability data - case 7: // Sensitivity data - case 9: // Singular vectors and ensemble perturbations - case 11: // Supplementary data used by the analysis - case 14: // Brightness temperature - case 20: // 4D variational increments - case 21: // Sensitive area predictions - case 23: // Coupled atmospheric, wave and ocean means - case 24: // Satellite Channel Number Data + case 5: // Forecast probability data + case 7: // Sensitivity data + case 9: // Singular vectors and ensemble perturbations + case 11: // Supplementary data used by the analysis + case 14: // Brightness temperature + case 20: // 4D variational increments + case 21: // Sensitive area predictions + case 23: // Coupled atmospheric, wave and ocean means + case 24: // Satellite Channel Number Data case 25: - case 28: // COSMO local area EPS - case 38: // 4D variational increments for long window 4Dvar system - case 39: // 4DVar model errors for long window 4Dvar system - case 60: // Ocean data analysis - case 192: // Multiple ECMWF local definitions + case 28: // COSMO local area EPS + case 38: // 4D variational increments for long window 4Dvar system + case 39: // 4DVar model errors for long window 4Dvar system + case 60: // Ocean data analysis + case 192: // Multiple ECMWF local definitions if (isInstant) { productDefinitionTemplateNumberNew = 0; } @@ -279,13 +282,13 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo productDefinitionTemplateNumberNew = 45; } else { - //productDefinitionTemplateNumberNew = 47; This PDT is deprecated + // productDefinitionTemplateNumberNew = 47; This PDT is deprecated productDefinitionTemplateNumberNew = 85; } } else { if (isInstant) { - productDefinitionTemplateNumberNew = 48; //44 is deprecated*/ + productDefinitionTemplateNumberNew = 48; // 44 is deprecated*/ } else { productDefinitionTemplateNumberNew = 46; @@ -309,7 +312,7 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { if (a->context->debug) { fprintf(stderr, "ECCODES DEBUG grib_accessor_local_definition_t: ldNumber=%d, newPDTN=%ld\n", - localDefinitionNumber, productDefinitionTemplateNumberNew); + localDefinitionNumber, productDefinitionTemplateNumberNew); } if (tooEarly) grib_set_long(hand, self->productDefinitionTemplateNumberInternal, productDefinitionTemplateNumberNew); @@ -324,7 +327,8 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo return 0; } -int grib_accessor_class_local_definition_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_local_definition_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_optimal_step_units.cc b/src/accessor/grib_accessor_class_optimal_step_units.cc index adc89e743..e6ff3fe73 100644 --- a/src/accessor/grib_accessor_class_optimal_step_units.cc +++ b/src/accessor/grib_accessor_class_optimal_step_units.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -13,11 +12,12 @@ #include "step.h" #include "step_utilities.h" -grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{"optimal_step_units"}; +grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{ "optimal_step_units" }; grib_accessor_class* grib_accessor_class_optimal_step_units = &_grib_accessor_class_optimal_step_units; -void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_gen_t::init(a, l, c); grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; grib_handle* hand = grib_handle_of_accessor(a); @@ -27,72 +27,78 @@ void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long self->forecast_time_unit = grib_arguments_get_name(hand, c, n++); self->time_range_value = grib_arguments_get_name(hand, c, n++); self->time_range_unit = grib_arguments_get_name(hand, c, n++); - a->length = 0; - self->overwriteStepUnits = eccodes::Unit{eccodes::Unit::Value::MISSING}.value(); + a->length = 0; + self->overwriteStepUnits = eccodes::Unit{ eccodes::Unit::Value::MISSING }.value(); } -void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper){ +void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper) +{ grib_dump_string(dumper, a, NULL); } -size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a) +{ return 255; } -int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e){ - const char* cval = NULL; - int ret = 0; - long lval = 0; - size_t len = 1; - grib_handle* hand = grib_handle_of_accessor(a); +int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e) +{ + const char* cval = NULL; + int ret = 0; + long lval = 0; + size_t len = 1; + grib_handle* hand = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; if (strcmp(e->cclass->name, "long") == 0) { - grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */ - ret = a->pack_long(&lval, &len); } + grib_expression_evaluate_long(hand, e, &lval); // TODO: check return value + ret = a->pack_long(&lval, &len); + } else { char tmp[1024]; len = sizeof(tmp); cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { grib_context_log(a->context, GRIB_LOG_ERROR, - "%s.%s: Unable to evaluate string %s to be set in %s", - cclass_name, __func__, grib_expression_get_name(e), a->name); + "%s.%s: Unable to evaluate string %s to be set in %s", + cclass_name, __func__, grib_expression_get_name(e), a->name); return ret; } len = strlen(cval) + 1; - //if (hand->context->debug) - // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); - ret = a->pack_string(cval, &len); } + // if (hand->context->debug) + // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); + ret = a->pack_string(cval, &len); + } return ret; } -int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ 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 = 0; long start_step_unit = 0; - long end_step = 0; - long end_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 + eccodes::Unit unit{ *val }; // throws if not supported auto iter = std::find(supported_units.begin(), supported_units.end(), unit); if (iter == supported_units.end()) { - throw std::runtime_error{"eccodes::Unit not supported"}; + throw std::runtime_error{ "eccodes::Unit not supported" }; } } catch (std::exception& e) { std::string supported_units_str; for (auto& u : supported_units) - supported_units_str += eccodes::Unit{u}.value() + ","; + supported_units_str += eccodes::Unit{ u }.value() + ","; supported_units_str.pop_back(); - std::string msg = std::string{"Invalid unit: "} + std::to_string(*val) + " (" + e.what() + ")" + - ". Available units are: " + supported_units_str; + std::string msg = std::string{ "Invalid unit: " } + std::to_string(*val) + " (" + e.what() + ")" + + ". Available units are: " + supported_units_str; grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INVALID_ARGUMENT; } @@ -115,9 +121,9 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const return ret; try { - eccodes::Step start{start_step, start_step_unit}; + eccodes::Step start{ start_step, start_step_unit }; start.set_unit(*val); - eccodes::Step end{end_step, end_step_unit}; + eccodes::Step end{ end_step, end_step_unit }; end.set_unit(*val); if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value())) != GRIB_SUCCESS) @@ -130,7 +136,7 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const return ret; } catch (std::exception& e) { - std::string msg = std::string{"Failed to convert steps to: "} + std::to_string(*val) + " (" + e.what() + ")"; + 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; } @@ -144,17 +150,17 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long grib_handle* h = grib_handle_of_accessor(a); try { - if (eccodes::Unit{self->overwriteStepUnits} != eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ self->overwriteStepUnits } != eccodes::Unit{ eccodes::Unit::Value::MISSING }) { *val = self->overwriteStepUnits; return GRIB_SUCCESS; } auto forecast_time_opt = get_step(h, self->forecast_time_value, self->forecast_time_unit); - auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit); + auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit); if (forecast_time_opt && time_range_opt) { auto [step_a, step_b] = find_common_units(forecast_time_opt.value().optimize_unit(), - (forecast_time_opt.value() + time_range_opt.value()).optimize_unit()); + (forecast_time_opt.value() + time_range_opt.value()).optimize_unit()); *val = step_a.unit().value(); } else if (forecast_time_opt && !time_range_opt) { @@ -164,7 +170,7 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long *val = time_range_opt.value().optimize_unit().unit().value(); } else if (!forecast_time_opt && !time_range_opt) { - *val = eccodes::Unit{eccodes::Unit::Value::HOUR}.value(); + *val = eccodes::Unit{ eccodes::Unit::Value::HOUR }.value(); } } catch (std::exception& e) { @@ -175,16 +181,17 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long return GRIB_SUCCESS; } -int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len){ +int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ try { - long unit = eccodes::Unit{val}.value(); + long unit = eccodes::Unit{ val }.value(); pack_long(a, &unit, len); } catch (std::exception& e) { auto supported_units = eccodes::Unit::list_supported_units(); std::string supported_units_str; for (auto& u : supported_units) - supported_units_str += eccodes::Unit{u}.value() + ","; + supported_units_str += eccodes::Unit{ u }.value() + ","; supported_units_str.pop_back(); std::string msg = "Invalid unit: " + std::string(val) + " (" + e.what() + ")" + ". Available units are: " + supported_units_str; @@ -195,22 +202,25 @@ int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, cons return GRIB_SUCCESS; } -int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len){ - int ret = 0; - long unit = 0; +int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + int ret = 0; + long unit = 0; size_t unit_len = 0; if ((ret = unpack_long(a, &unit, &unit_len)) != GRIB_SUCCESS) return ret; - *len = snprintf(val, *len, "%s", eccodes::Unit{unit}.value().c_str()); + *len = snprintf(val, *len, "%s", eccodes::Unit{ unit }.value().c_str()); return GRIB_SUCCESS; } // Step units are never missing // If the user does not specify a step unit, we default to hours -int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a){ +int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a) +{ return 0; } -int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_packing_type.cc b/src/accessor/grib_accessor_class_packing_type.cc index 5dd862a07..50ac9540d 100644 --- a/src/accessor/grib_accessor_class_packing_type.cc +++ b/src/accessor/grib_accessor_class_packing_type.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,13 +10,14 @@ #include "grib_accessor_class_packing_type.h" -grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{"packing_type"}; +grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{ "packing_type" }; grib_accessor_class* grib_accessor_class_packing_type = &_grib_accessor_class_packing_type; -void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args){ +void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ grib_accessor_class_gen_t::init(a, l, args); - int n = 0; + int n = 0; grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->packing_type = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); @@ -25,21 +25,25 @@ void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, gr a->length = 0; } -size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a) +{ return 1024; } -int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a){ +int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a) +{ return GRIB_TYPE_STRING; } -int grib_accessor_class_packing_type_t::pack_string(grib_accessor*a, const char* sval, size_t* len){ +int grib_accessor_class_packing_type_t::pack_string(grib_accessor* a, const char* sval, size_t* len) +{ grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - double* values = NULL; + + grib_handle* h = grib_handle_of_accessor(a); + double* values = NULL; grib_context* c = a->context; - size_t size = 0; - int err = 0; + size_t size = 0; + int err = 0; if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) return err; @@ -66,9 +70,10 @@ int grib_accessor_class_packing_type_t::pack_string(grib_accessor*a, const char* return GRIB_SUCCESS; } -int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); return grib_get_string(h, self->packing_type, val, len); } diff --git a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc index ea7c4c931..8d5f4b99f 100644 --- a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -12,7 +11,7 @@ #include "grib_accessor_class_second_order_bits_per_value.h" #include "grib_scaling.h" -grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{"second_order_bits_per_value"}; +grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{ "second_order_bits_per_value" }; grib_accessor_class* grib_accessor_class_second_order_bits_per_value = &_grib_accessor_class_second_order_bits_per_value; @@ -35,10 +34,11 @@ static const size_t nbits[64] = { 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000 }; -static int number_of_bits(size_t x, long* result){ +static int number_of_bits(size_t x, long* result) +{ const size_t* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); - *result = 0; + *result = 0; while (x >= *n) { n++; (*result)++; @@ -49,27 +49,30 @@ static int number_of_bits(size_t x, long* result){ return GRIB_SUCCESS; } -void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); - int n = 0; + int n = 0; grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->bitsPerValue = 0; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->bitsPerValue = 0; a->length = 0; } -int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; - self->bitsPerValue = (long)*val; - *len = 1; + self->bitsPerValue = (long)*val; + *len = 1; - return 0; + return GRIB_SUCCESS; } -int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ int ret = GRIB_SUCCESS; size_t size = 0; size_t i; diff --git a/src/accessor/grib_accessor_class_select_step_template.cc b/src/accessor/grib_accessor_class_select_step_template.cc index bc72a5220..d2c5eeb6a 100644 --- a/src/accessor/grib_accessor_class_select_step_template.cc +++ b/src/accessor/grib_accessor_class_select_step_template.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,30 +10,33 @@ #include "grib_accessor_class_select_step_template.h" -grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{"select_step_template"}; +grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{ "select_step_template" }; grib_accessor_class* grib_accessor_class_select_step_template = &_grib_accessor_class_select_step_template; -void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_unsigned_t::init(a, l, c); grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->instant = grib_arguments_get_long(hand, c, n++); + self->instant = grib_arguments_get_long(hand, c, n++); } -int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ *val = 1; return GRIB_SUCCESS; } -int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len){ +int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - long productDefinitionTemplateNumber = 0; - long productDefinitionTemplateNumberNew = 0; + grib_handle* hand = grib_handle_of_accessor(a); + long productDefinitionTemplateNumber = 0; + long productDefinitionTemplateNumberNew = 0; grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); @@ -64,28 +66,28 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons case 14: productDefinitionTemplateNumberNew = 4; break; - case 42: // DET chemical + case 42: // DET chemical productDefinitionTemplateNumberNew = 40; break; - case 43: // ENS chemical + case 43: // ENS chemical productDefinitionTemplateNumberNew = 41; break; - case 46: // DET aerosol - productDefinitionTemplateNumberNew = 48; // 44 is deprecated + case 46: // DET aerosol + productDefinitionTemplateNumberNew = 48; // 44 is deprecated break; - case 47: // ENS aerosol + case 47: // ENS aerosol productDefinitionTemplateNumberNew = 45; break; - case 67: // DET chemical distrib func + case 67: // DET chemical distrib func productDefinitionTemplateNumberNew = 57; break; - case 68: // ENS chemical distrib func + case 68: // ENS chemical distrib func productDefinitionTemplateNumberNew = 58; break; - case 72: // DET post-processing + case 72: // DET post-processing productDefinitionTemplateNumberNew = 70; break; - case 73: // ENS post-processing */ + case 73: // ENS post-processing */ productDefinitionTemplateNumberNew = 71; break; case 0: @@ -128,25 +130,25 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons case 6: productDefinitionTemplateNumberNew = 10; break; - case 40: // DET chemical + case 40: // DET chemical productDefinitionTemplateNumberNew = 42; break; - case 41: // ENS chemical + case 41: // ENS chemical productDefinitionTemplateNumberNew = 43; break; - case 45: // ENS aerosol - productDefinitionTemplateNumberNew = 85; // 47 is deprecated + case 45: // ENS aerosol + productDefinitionTemplateNumberNew = 85; // 47 is deprecated break; - case 57: // DET chemical distrib func + case 57: // DET chemical distrib func productDefinitionTemplateNumberNew = 67; break; - case 58: // ENS chemical distrib func + case 58: // ENS chemical distrib func productDefinitionTemplateNumberNew = 68; break; - case 70: // DET post-processing + case 70: // DET post-processing productDefinitionTemplateNumberNew = 72; break; - case 71: // ENS post-processing + case 71: // ENS post-processing productDefinitionTemplateNumberNew = 73; break; case 7: @@ -172,7 +174,8 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons return GRIB_SUCCESS; } -int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c){ +int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c) +{ *c = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_simple_packing_error.cc b/src/accessor/grib_accessor_class_simple_packing_error.cc index 5f713a950..5bdd21553 100644 --- a/src/accessor/grib_accessor_class_simple_packing_error.cc +++ b/src/accessor/grib_accessor_class_simple_packing_error.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -12,11 +11,12 @@ #include "grib_accessor_class_simple_packing_error.h" #include "grib_scaling.h" -grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{"simple_packing_error"}; +grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{ "simple_packing_error" }; grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_class_simple_packing_error; -void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_double_t::init(a, l, c); grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; int n = 0; @@ -32,7 +32,8 @@ void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const lo a->length = 0; } -int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len){ +int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; int ret = 0; @@ -40,7 +41,7 @@ int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, long bitsPerValue = 0; long decimalScaleFactor = 0; double referenceValue = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_spectral_truncation.cc b/src/accessor/grib_accessor_class_spectral_truncation.cc index 2fc45511f..fda29784c 100644 --- a/src/accessor/grib_accessor_class_spectral_truncation.cc +++ b/src/accessor/grib_accessor_class_spectral_truncation.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,14 +10,15 @@ #include "grib_accessor_class_spectral_truncation.h" -grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{"spectral_truncation"}; +grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{ "spectral_truncation" }; grib_accessor_class* grib_accessor_class_spectral_truncation = &_grib_accessor_class_spectral_truncation; -void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_long_t::init(a, l, c); grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; - int n = 0; + int n = 0; self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -28,9 +28,10 @@ void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const lon a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len){ +int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; - int ret = 0; + int ret = GRIB_SUCCESS; long J, K, M, T, Tc; diff --git a/src/accessor/grib_accessor_class_sprintf.cc b/src/accessor/grib_accessor_class_sprintf.cc index cc9e37e6a..533d66d7a 100644 --- a/src/accessor/grib_accessor_class_sprintf.cc +++ b/src/accessor/grib_accessor_class_sprintf.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,18 +10,20 @@ #include "grib_accessor_class_sprintf.h" -grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{"sprintf"}; +grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{ "sprintf" }; grib_accessor_class* grib_accessor_class_sprintf = &_grib_accessor_class_sprintf; -void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c){ +void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ grib_accessor_class_ascii_t::init(a, l, c); grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; - self->args = c; + self->args = c; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len){ +int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; char result[1024]; char tempBuffer[2048]; @@ -61,7 +62,8 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), tempname, &ires)) != GRIB_SUCCESS) return ret; /* Bug GRIB-56: Check to see if the key is missing */ - is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); if (ret != GRIB_SUCCESS) + is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); + if (ret != GRIB_SUCCESS) return ret; if (is_missing) { snprintf(tempBuffer, sizeof(tempBuffer), "%sMISSING", result); @@ -117,11 +119,13 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si return GRIB_SUCCESS; } -int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count){ +int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count) +{ *count = 1; return 0; } -size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a){ +size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a) +{ return 1024; } diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 9bceeb202..6cbb4a5bc 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -281,6 +281,7 @@ int grib_index_dump_file(FILE* fout, const char* filename, unsigned long flags); void grib_index_dump(FILE* fout, grib_index* index, unsigned long flags); char* grib_get_field_file(grib_index* index, off_t* offset); grib_handle* grib_handle_new_from_index(grib_index* index, int* err); +void grib_index_rewind(grib_index *index); grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err); int codes_index_set_product_kind(grib_index* index, ProductKind product_kind); int codes_index_set_unpack_bufr(grib_index* index, int unpack); diff --git a/src/grib_index.cc b/src/grib_index.cc index 211b30cb5..0a96b57e3 100644 --- a/src/grib_index.cc +++ b/src/grib_index.cc @@ -65,7 +65,6 @@ static int index_count; static long values_count = 0; static int codes_index_add_file_internal(grib_index* index, const char* filename, int message_type); -static void grib_index_rewind(grib_index* index); static char* get_key(char** keys, int* type) { @@ -1967,7 +1966,7 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err) return h; } -static void grib_index_rewind(grib_index* index) +void grib_index_rewind(grib_index* index) { index->rewind = 1; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9a4464136..cedaf00d3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -276,7 +276,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1467 grib_ecc-1764 grib_ecc-1792 - grib_ecc-1846 + grib_modelName grib_sub_hourly grib_set_bytes grib_set_force diff --git a/tests/grib2_wave_spectra.sh b/tests/grib2_wave_spectra.sh index 44b58add8..ea465b04b 100755 --- a/tests/grib2_wave_spectra.sh +++ b/tests/grib2_wave_spectra.sh @@ -12,6 +12,8 @@ label="grib2_wave_spectra_test" temp=temp.$label +tempGribA=temp.$label.A.grib +tempGribB=temp.$label.B.grib tempSample=temp.$label.tmpl sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl @@ -52,5 +54,18 @@ grib_check_key_equals $temp firstWavelengthInNanometres '12' grib_check_key_equals $temp firstWavelengthInMetres '1.2e-08' +# ECC-1867: Unexpected PDT change for wave template for ensemble DA streams +sample_ld=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl # Sample with a mars local def +${tools_dir}/grib_set -s tablesVersion=32,productDefinitionTemplateNumber=99,waveFrequencyNumber=14 $sample_ld $tempGribA +${tools_dir}/grib_set -s stream=ewla $tempGribA $tempGribB +grib_check_key_equals $tempGribB productDefinitionTemplateNumber,waveFrequencyNumber '99 14' +${tools_dir}/grib_compare -b marsStream $tempGribA $tempGribB + +${tools_dir}/grib_set -s type=em $tempGribA $tempGribB +${tools_dir}/grib_compare -b marsType,typeOfProcessedData,typeOfGeneratingProcess $tempGribA $tempGribB +${tools_dir}/grib_set -s type=es $tempGribA $tempGribB +${tools_dir}/grib_compare -b marsType,typeOfProcessedData,typeOfGeneratingProcess $tempGribA $tempGribB + + # Clean up -rm -f $tempSample $temp +rm -f $tempSample $temp $tempGribA $tempGribB diff --git a/tests/grib_get_fail.sh b/tests/grib_get_fail.sh index a76f7c39f..efaf3b5d2 100755 --- a/tests/grib_get_fail.sh +++ b/tests/grib_get_fail.sh @@ -86,6 +86,16 @@ set -e grep -q "unreadable message" $tempText rm -f $outfile +# ---------------------- +# Printing array keys +# ---------------------- +set +e +${tools_dir}/grib_get -p bitmap $data_dir/reduced_latlon_surface.grib2 > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Hint: Tool grib_get cannot print keys of array type" $tempText + # ---------------------- # Wrong message type diff --git a/tests/grib_ls.sh b/tests/grib_ls.sh index 98c32563c..f0d1c339f 100755 --- a/tests/grib_ls.sh +++ b/tests/grib_ls.sh @@ -291,5 +291,16 @@ if [ $HAVE_GEOGRAPHY -eq 1 ]; then grep -q "unable to open mask file" $tempText fi +# ---------------------- +# Printing array keys +# ---------------------- +set +e +${tools_dir}/grib_ls -p bitmap $data_dir/reduced_latlon_surface.grib2 > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Hint: Tool grib_ls cannot print keys of array type" $tempText + + # Clean up rm -f $temp1 $temp2 $tempText $tempLog diff --git a/tests/grib_ecc-1846.sh b/tests/grib_modelName.sh similarity index 97% rename from tests/grib_ecc-1846.sh rename to tests/grib_modelName.sh index 1416cf1e7..d0dde3cc4 100755 --- a/tests/grib_ecc-1846.sh +++ b/tests/grib_modelName.sh @@ -10,7 +10,9 @@ . ./include.ctest.sh -label="grib_ecc-1846_test" +# See ECC-1846 + +label="grib_modelName_test" tempGrib=temp.$label.grib tempFilt=temp.$label.filt tempLog=temp.$label.log diff --git a/tools/grib_tools.cc b/tools/grib_tools.cc index 976f712be..cde99abac 100644 --- a/tools/grib_tools.cc +++ b/tools/grib_tools.cc @@ -1239,14 +1239,18 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h) //GRIB_CHECK_NOLINE(ret, options->print_keys[i].name); grib_context_log(h->context, GRIB_LOG_ERROR, "%s (%s)", options->print_keys[i].name, grib_get_error_message(ret)); + if (ret == GRIB_ARRAY_TOO_SMALL || ret == GRIB_BUFFER_TOO_SMALL) { + fprintf(dump_file, "\tHint: Tool %s cannot print keys of array type. Use grib_filter.\n", tool_name); + } exit(ret); } if (ret == GRIB_NOT_FOUND) { strcpy(value, notfound); } else { fprintf(dump_file, "%s (%s)\n", options->print_keys[i].name, grib_get_error_message(ret)); - if (ret == GRIB_ARRAY_TOO_SMALL) + if (ret == GRIB_ARRAY_TOO_SMALL || ret == GRIB_BUFFER_TOO_SMALL) { fprintf(dump_file, "\tHint: Tool %s cannot print keys of array type. Use grib_filter.\n", tool_name); + } exit(ret); } }