From 3722e3bfa0058048ef40e7c8edfcac8508f30fb4 Mon Sep 17 00:00:00 2001 From: Sebastien Villaume Date: Fri, 9 Feb 2024 11:37:03 +0000 Subject: [PATCH 001/156] adding a switch to stepRange instead of step for levtypes o2d and o3d for mmsf/fc --- definitions/mars/grib.mmsf.fc.def | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/definitions/mars/grib.mmsf.fc.def b/definitions/mars/grib.mmsf.fc.def index d213cee45..7adb27059 100644 --- a/definitions/mars/grib.mmsf.fc.def +++ b/definitions/mars/grib.mmsf.fc.def @@ -17,3 +17,9 @@ if (centre == 80 && subCentre == 98 && class is "c3") { } if (class is "ci") { unalias mars.method; } + +if (levtype is "o2d" || levtype is "o3d") { + alias mars.step = stepRange; +} else { + alias mars.step = endStep; +} From 42f7ea1f746c12db0d296156ec6a5daa4be47394 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 13 Feb 2024 21:18:39 +0000 Subject: [PATCH 002/156] ECC-1364: GRIB: Geoiterator for Lambert Conformal in the southern hemisphere --- src/grib_iterator_class_lambert_conformal.cc | 76 ++++++++++++++++---- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/src/grib_iterator_class_lambert_conformal.cc b/src/grib_iterator_class_lambert_conformal.cc index 3e9d51055..b50ad72cf 100644 --- a/src/grib_iterator_class_lambert_conformal.cc +++ b/src/grib_iterator_class_lambert_conformal.cc @@ -162,6 +162,25 @@ static double calculate_eccentricity(double minor, double major) return sqrt(1.0 - temp * temp); } +static void inverse(double radius, double n, double f, double rho0_bare, double LoVInRadians, double x, double y, + double* latDeg, double* lonDeg) +{ + x /= radius; + y /= radius; + y = rho0_bare - y; + double rho = hypot(x, y); + Assert(rho != 0.0); + if (n < 0.0) { + rho = -rho; + x = -x; + y = -y; + } + double lp_phi = 2. * atan(pow(f / rho, 1.0/n)) - M_PI_2; + double lp_lam = atan2(x, y) / n; + *lonDeg = lp_lam*RAD2DEG + LoVInRadians*RAD2DEG; + *latDeg = lp_phi*RAD2DEG; +} + static int init_sphere(grib_handle* h, grib_iterator_lambert_conformal* self, size_t nv, long nx, long ny, @@ -171,8 +190,8 @@ static int init_sphere(grib_handle* h, double LoVInRadians, double Latin1InRadians, double Latin2InRadians, double LaDInRadians) { - int i, j; - double f, n, rho, rho0, angle, x0, y0, x, y, tmp, tmp2; + long i, j; + double f, n, rho, rho0, angle, x0, y0, x, y; double latDeg, lonDeg, lonDiff; if (fabs(Latin1InRadians - Latin2InRadians) < 1E-09) { @@ -185,8 +204,10 @@ static int init_sphere(grib_handle* h, f = (cos(Latin1InRadians) * pow(tan(M_PI_4 + Latin1InRadians / 2.0), n)) / n; rho = radius * f * pow(tan(M_PI_4 + latFirstInRadians / 2.0), -n); rho0 = radius * f * pow(tan(M_PI_4 + LaDInRadians / 2.0), -n); - if (n < 0) /* adjustment for southern hemisphere */ - rho0 = -rho0; + double rho0_bare = f * pow(tan(M_PI_4 + LaDInRadians / 2.0), -n); + + //if (n < 0) /* adjustment for southern hemisphere */ + // rho0 = -rho0; lonDiff = lonFirstInRadians - LoVInRadians; /* Adjust longitude to range -180 to 180 */ @@ -212,21 +233,52 @@ static int init_sphere(grib_handle* h, grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Error allocating %zu bytes", ITER, nv * sizeof(double)); return GRIB_OUT_OF_MEMORY; } - + + //------------PROJ lcc_e_inverse ------ + //double x0_bare = x0/radius; + //double y0_bare = y0/radius; + // y0_bare = rho0_bare - y0_bare; +// rho = hypot(x0_bare, y0_bare); +// Assert(rho != 0.0); +// if (n < 0.0) { +// rho = -rho; +// x0_bare = -x0_bare; +// y0_bare = -y0_bare; +// } +// double lp_phi = 2. * atan(pow(f / rho, 1./n)) - M_PI_2; +// double lp_lam = atan2(x0_bare, y0_bare) / n; +// lonDeg = lp_lam * RAD2DEG + LoVInDegrees; +// latDeg = lp_phi * RAD2DEG; +// printf("phi=%g lam=%g\n", lp_phi ,lp_lam); + //-------------------------------------- + //inverse(radius, n, f, rho0_bare, LoVInRadians, x0, y0, &latDeg, &lonDeg); + + for (j = 0; j < ny; j++) { + y = y0 + j * Dy; + for (i = 0; i < nx; i++) { + const long index = i + j * nx; + x = x0 + i * Dx; + inverse(radius, n, f, rho0_bare, LoVInRadians, x, y, &latDeg, &lonDeg); + self->lons[index] = lonDeg; + self->lats[index] = latDeg; + } + } +#if 0 /* Populate our arrays */ for (j = 0; j < ny; j++) { y = y0 + j * Dy; - if (n < 0) { /* adjustment for southern hemisphere */ - y = -y; - } + //if (n < 0) { /* adjustment for southern hemisphere */ + // y = -y; + //} tmp = rho0 - y; tmp2 = tmp * tmp; for (i = 0; i < nx; i++) { int index = i + j * nx; x = x0 + i * Dx; - if (n < 0) { /* adjustment for southern hemisphere */ - x = -x; - } + //printf("j=%d i=%d xy= %.6f %.6f\t",j,i,x,y); + //if (n < 0) { /* adjustment for southern hemisphere */ + // x = -x; + //} angle = atan2(x, tmp); /* See ECC-524 */ rho = sqrt(x * x + tmp2); if (n <= 0) rho = -rho; @@ -237,7 +289,7 @@ static int init_sphere(grib_handle* h, self->lats[index] = latDeg; } } - +#endif return GRIB_SUCCESS; } From 7a38c69aa457a9b70e9ee6277146cc9af73ba675 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 10:48:24 +0000 Subject: [PATCH 003/156] ECC-1364: Cleanup --- src/grib_iterator_class_lambert_conformal.cc | 70 ++++++++------------ 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/src/grib_iterator_class_lambert_conformal.cc b/src/grib_iterator_class_lambert_conformal.cc index b50ad72cf..eea6f40c9 100644 --- a/src/grib_iterator_class_lambert_conformal.cc +++ b/src/grib_iterator_class_lambert_conformal.cc @@ -162,26 +162,32 @@ static double calculate_eccentricity(double minor, double major) return sqrt(1.0 - temp * temp); } -static void inverse(double radius, double n, double f, double rho0_bare, double LoVInRadians, double x, double y, +static void xy2latlon(double radius, double n, double f, double rho0_bare, double LoVInRadians, + double x, double y, double* latDeg, double* lonDeg) { x /= radius; y /= radius; y = rho0_bare - y; double rho = hypot(x, y); - Assert(rho != 0.0); - if (n < 0.0) { - rho = -rho; - x = -x; - y = -y; + if (rho != 0.0) { + if (n < 0.0) { + rho = -rho; + x = -x; + y = -y; + } + double lp_phi = 2. * atan(pow(f / rho, 1.0/n)) - M_PI_2; + double lp_lam = atan2(x, y) / n; + *lonDeg = lp_lam*RAD2DEG + LoVInRadians*RAD2DEG; + *latDeg = lp_phi*RAD2DEG; + } + else { + *lonDeg = 0.0; + *latDeg = (n > 0.0 ? M_PI_2 : -M_PI_2) * RAD2DEG; } - double lp_phi = 2. * atan(pow(f / rho, 1.0/n)) - M_PI_2; - double lp_lam = atan2(x, y) / n; - *lonDeg = lp_lam*RAD2DEG + LoVInRadians*RAD2DEG; - *latDeg = lp_phi*RAD2DEG; } -static int init_sphere(grib_handle* h, +static int init_sphere(const grib_handle* h, grib_iterator_lambert_conformal* self, size_t nv, long nx, long ny, double LoVInDegrees, @@ -190,9 +196,7 @@ static int init_sphere(grib_handle* h, double LoVInRadians, double Latin1InRadians, double Latin2InRadians, double LaDInRadians) { - long i, j; - double f, n, rho, rho0, angle, x0, y0, x, y; - double latDeg, lonDeg, lonDiff; + double n, angle, x0, y0, x, y; if (fabs(Latin1InRadians - Latin2InRadians) < 1E-09) { n = sin(Latin1InRadians); @@ -201,14 +205,14 @@ static int init_sphere(grib_handle* h, log(tan(M_PI_4 + Latin2InRadians / 2.0) / tan(M_PI_4 + Latin1InRadians / 2.0)); } - f = (cos(Latin1InRadians) * pow(tan(M_PI_4 + Latin1InRadians / 2.0), n)) / n; - rho = radius * f * pow(tan(M_PI_4 + latFirstInRadians / 2.0), -n); - rho0 = radius * f * pow(tan(M_PI_4 + LaDInRadians / 2.0), -n); + double f = (cos(Latin1InRadians) * pow(tan(M_PI_4 + Latin1InRadians / 2.0), n)) / n; + double rho = radius * f * pow(tan(M_PI_4 + latFirstInRadians / 2.0), -n); double rho0_bare = f * pow(tan(M_PI_4 + LaDInRadians / 2.0), -n); + double rho0 = radius * rho0_bare; //if (n < 0) /* adjustment for southern hemisphere */ // rho0 = -rho0; - lonDiff = lonFirstInRadians - LoVInRadians; + double lonDiff = lonFirstInRadians - LoVInRadians; /* Adjust longitude to range -180 to 180 */ if (lonDiff > M_PI) @@ -233,32 +237,14 @@ static int init_sphere(grib_handle* h, grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Error allocating %zu bytes", ITER, nv * sizeof(double)); return GRIB_OUT_OF_MEMORY; } - - //------------PROJ lcc_e_inverse ------ - //double x0_bare = x0/radius; - //double y0_bare = y0/radius; - // y0_bare = rho0_bare - y0_bare; -// rho = hypot(x0_bare, y0_bare); -// Assert(rho != 0.0); -// if (n < 0.0) { -// rho = -rho; -// x0_bare = -x0_bare; -// y0_bare = -y0_bare; -// } -// double lp_phi = 2. * atan(pow(f / rho, 1./n)) - M_PI_2; -// double lp_lam = atan2(x0_bare, y0_bare) / n; -// lonDeg = lp_lam * RAD2DEG + LoVInDegrees; -// latDeg = lp_phi * RAD2DEG; -// printf("phi=%g lam=%g\n", lp_phi ,lp_lam); - //-------------------------------------- - //inverse(radius, n, f, rho0_bare, LoVInRadians, x0, y0, &latDeg, &lonDeg); - - for (j = 0; j < ny; j++) { + + double latDeg = 0, lonDeg = 0; + for (long j = 0; j < ny; j++) { y = y0 + j * Dy; - for (i = 0; i < nx; i++) { + for (long i = 0; i < nx; i++) { const long index = i + j * nx; x = x0 + i * Dx; - inverse(radius, n, f, rho0_bare, LoVInRadians, x, y, &latDeg, &lonDeg); + xy2latlon(radius, n, f, rho0_bare, LoVInRadians, x, y, &latDeg, &lonDeg); self->lons[index] = lonDeg; self->lats[index] = latDeg; } @@ -294,7 +280,7 @@ static int init_sphere(grib_handle* h, } /* Oblate spheroid */ -static int init_oblate(grib_handle* h, +static int init_oblate(const grib_handle* h, grib_iterator_lambert_conformal* self, size_t nv, long nx, long ny, double LoVInDegrees, From 951ff99b50a06f2ef31e96df8c4725d53b123aa2 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 12:07:42 +0000 Subject: [PATCH 004/156] Tools: Verbose messages --- tools/codes_split_file.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/codes_split_file.cc b/tools/codes_split_file.cc index 384904602..62484b2e3 100644 --- a/tools/codes_split_file.cc +++ b/tools/codes_split_file.cc @@ -20,7 +20,7 @@ #include "grib_api_internal.h" #include -static int verbose = 0; +static bool verbose = false; static const char* OUTPUT_FILENAME_FORMAT = "%s_%03d"; /* x_001, x_002 etc */ static void usage(const char* prog) { @@ -29,6 +29,11 @@ static void usage(const char* prog) exit(1); } +static void print_num_messages_written(const char* output_filename, size_t n) +{ + printf("Wrote output file %s (%zu message%s)\n", output_filename, n, n==1?"":"s"); +} + static int split_file(FILE* in, const char* filename, const int nchunks, unsigned long* count) { void* mesg = NULL; @@ -76,8 +81,9 @@ static int split_file(FILE* in, const char* filename, const int nchunks, unsigne read_size += size; msg_size += size; if (read_size > chunk_size && msg_size < insize) { - if (verbose) - printf("Wrote output file %s (%zu msgs)\n", ofilename, num_msg); + if (verbose) { + print_num_messages_written(ofilename, num_msg); + } fclose(out); i++; /* Start writing to the next file */ @@ -95,8 +101,9 @@ static int split_file(FILE* in, const char* filename, const int nchunks, unsigne (*count)++; } } - if (verbose) - printf("Wrote output file %s (%zu msgs)\n", ofilename, num_msg - 1); + if (verbose) { + print_num_messages_written(ofilename, num_msg - 1); + } fclose(out); free(ofilename); @@ -118,7 +125,7 @@ int main(int argc, char* argv[]) i = 1; if (strcmp(argv[i], "-v") == 0) { i++; - verbose = 1; + verbose = true; if (argc != 4) usage(argv[0]); } From 404778c7c0a53a2c2b346ea7c9e31494a89898f2 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 12:27:27 +0000 Subject: [PATCH 005/156] ECC-1364: Test --- tests/CMakeLists.txt | 1 + tests/grib_ecc-1364.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 tests/grib_ecc-1364.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 71babe949..32c20a5a5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -254,6 +254,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1000 grib_ecc-1001 grib_ecc-1030 + grib_ecc-1364 grib_ecc-1397 grib_ecc-1425 grib_ecc-1467 diff --git a/tests/grib_ecc-1364.sh b/tests/grib_ecc-1364.sh new file mode 100755 index 000000000..cb4555834 --- /dev/null +++ b/tests/grib_ecc-1364.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + + +# ECC-1364: GRIB: Geoiterator for Lambert Conformal in the southern hemisphere + +label="grib_ecc-1364_test" +tempGrib=temp.$label.grib +tempFilt=temp.$label.filt +tempLog=temp.$label.log +tempRef=temp.$label.ref + +sample_grib1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl + +# Create a GRIB with a similar grid to the one in the JIRA issue +cat >$tempFilt< $tempLog + +${tools_dir}/grib_ls -l -11.6277,-47.9583,1 $tempGrib > $tempLog +grep -q "Grid Point chosen #1 index=1247750 " $tempLog +grep -q "index=1247750 .* distance=0.01 " $tempLog + + +# Clean up +rm -f $tempGrib $tempFilt $tempLog $tempRef From db48ecd3a938446a3a9a4ace7c5060e5fd6fb59b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 13:26:47 +0000 Subject: [PATCH 006/156] Examples: BUFR radiosonde updated Fortran code (From Bruce Ingleby) --- examples/F90/bufr_read_tempf.f90 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/F90/bufr_read_tempf.f90 b/examples/F90/bufr_read_tempf.f90 index 3d37c546e..99a8df742 100644 --- a/examples/F90/bufr_read_tempf.f90 +++ b/examples/F90/bufr_read_tempf.f90 @@ -25,9 +25,9 @@ program bufr_read_tempf integer :: ibufr integer :: i, count = 0 integer :: iflag - integer :: status_id, status_ht, status_time = 0, status_p - integer :: status_airt, status_dewt - integer :: status_rsno, status_rssoft, status_balloonwt + integer :: status_id, status_bl, status_num, status_ht, status_time = 0, status_p + integer :: status_airt, status_dewt, status_wdir, status_wsp + integer :: status_rsno, status_rssoft, status_balloonwt, statid_missing integer(kind=4) :: sizews integer(kind=4) :: blockNumber, stationNumber integer(kind=4) :: ymd, hms @@ -74,9 +74,10 @@ program bufr_read_tempf IF (status_id /= CODES_SUCCESS) statid = dropid ! call codes_is_missing(ibufr, 'shipOrMobileLandStationIdentifier', statid_missing) ! IF (statid_missing == 1) statid = "MISSING" - call codes_get(ibufr, 'blockNumber', blockNumber) - call codes_get(ibufr, 'stationNumber', stationNumber) - IF (blockNumber <= 99.0 .AND. stationNumber <= 1000) write (statid, '(I2.2,I3.3,3X)') blockNumber, stationNumber + blockNumber = 9999 + call codes_get(ibufr, 'blockNumber', blockNumber, status_bl) + call codes_get(ibufr, 'stationNumber', stationNumber, status_num) + IF (blockNumber <= 99 .AND. stationNumber <= 1000) write (statid, '(I2.2,I3.3,3X)') blockNumber, stationNumber call codes_get(ibufr, 'year', year) call codes_get(ibufr, 'month', month) @@ -118,8 +119,8 @@ program bufr_read_tempf call codes_get(ibufr, 'extendedVerticalSoundingSignificance', vssVal) call codes_get(ibufr, 'airTemperature', tVal, status_airt) call codes_get(ibufr, 'dewpointTemperature', tdVal, status_dewt) - call codes_get(ibufr, 'windDirection', wdirVal) - call codes_get(ibufr, 'windSpeed', wspVal) + call codes_get(ibufr, 'windDirection', wdirVal, status_wdir) + call codes_get(ibufr, 'windSpeed', wspVal, status_wsp) ! ---- Array sizes (pressure size can be larger - wind shear levels) sizews = size(wspVal) @@ -140,13 +141,21 @@ program bufr_read_tempf allocate(tdVal(sizews)) tdVal(:) = -999999999.0 END IF + IF (status_wdir /= CODES_SUCCESS) THEN + allocate(wdirVal(sizews)) + wdirVal(:) = -999999999.0 + END IF + IF (status_wsp /= CODES_SUCCESS) THEN + allocate(wspVal(sizews)) + wspVal(:) = -999999999.0 + END IF ! ---- Print the values -------------------------------- write (*, '(A,I7,A,A8,I9,I7.6,F9.3,F10.3,2F7.1,I4,I5)') 'Ob: ', count, & ' ', statid, ymd, hms, lat(1), lon(1), htg, htp, INT(sondeType), sizews IF (status_rsno == CODES_SUCCESS) write (*, '(A,A,A,F7.3)') & 'RS number/software/balloonwt: ', rsnumber, rssoftware, balloonwt - IF (status_ht == CODES_SUCCESS .AND. SIZE(lat) > 1) write (*, '(A,A,F9.3,F10.3,F7.1)') & + IF (status_ht == CODES_SUCCESS .AND. SIZE(lat) > 1) write (*, '(A,A10,F9.3,F10.3,F7.1)') & 'WMO list lat, lon, ht: ', statid, lat(2), lon(2), htec write (*, '(A)') 'level dtime dlat dlon pressure geopotH airTemp dewPtT windDir windSp signif' do i = 1, sizews From 6dbbf152b7a07cf2a2124cb0ac8e9257d1317c9a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 14:52:56 +0000 Subject: [PATCH 007/156] ECC-1364: Cleanup --- src/grib_iterator_class_lambert_conformal.cc | 135 +++++++++---------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/src/grib_iterator_class_lambert_conformal.cc b/src/grib_iterator_class_lambert_conformal.cc index eea6f40c9..5d15a67b6 100644 --- a/src/grib_iterator_class_lambert_conformal.cc +++ b/src/grib_iterator_class_lambert_conformal.cc @@ -85,21 +85,21 @@ static void init_class(grib_iterator_class* c) #define EPSILON 1.0e-10 #ifndef M_PI -#define M_PI 3.14159265358979323846 /* Whole pie */ +#define M_PI 3.14159265358979323846 // Whole pie #endif #ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 /* Half a pie */ +#define M_PI_2 1.57079632679489661923 // Half a pie #endif #ifndef M_PI_4 -#define M_PI_4 0.78539816339744830962 /* Quarter of a pie */ +#define M_PI_4 0.78539816339744830962 // Quarter of a pie #endif -#define RAD2DEG 57.29577951308232087684 /* 180 over pi */ -#define DEG2RAD 0.01745329251994329576 /* pi over 180 */ +#define RAD2DEG 57.29577951308232087684 // 180 over pi +#define DEG2RAD 0.01745329251994329576 // pi over 180 -/* Adjust longitude (in radians) to range -180 to 180 */ +// Adjust longitude (in radians) to range -180 to 180 static double adjust_lon_radians(double lon) { if (lon > M_PI) lon -= 2 * M_PI; @@ -107,16 +107,15 @@ static double adjust_lon_radians(double lon) return lon; } -/* Function to compute the latitude angle, phi2, for the inverse - * From the book "Map Projections-A Working Manual-John P. Snyder (1987)" - * Equation (7-9) involves rapidly converging iteration: Calculate t from (15-11) - * Then, assuming an initial trial phi equal to (pi/2 - 2*arctan t) in the right side of equation (7-9), - * calculate phi on the left side. Substitute the calculated phi) into the right side, - * calculate a new phi, etc., until phi does not change significantly from the preceding trial value of phi - */ +// Function to compute the latitude angle, phi2, for the inverse +// From the book "Map Projections-A Working Manual-John P. Snyder (1987)" +// Equation (7-9) involves rapidly converging iteration: Calculate t from (15-11) +// Then, assuming an initial trial phi equal to (pi/2 - 2*arctan t) in the right side of equation (7-9), +// calculate phi on the left side. Substitute the calculated phi) into the right side, +// calculate a new phi, etc., until phi does not change significantly from the preceding trial value of phi static double compute_phi( - double eccent, /* Spheroid eccentricity */ - double ts, /* Constant value t */ + double eccent, // Spheroid eccentricity + double ts, // Constant value t int* error) { double eccnth, phi, con, dphi, sinpi; @@ -136,19 +135,19 @@ static double compute_phi( return 0; } -/* Compute the constant small m which is the radius of - a parallel of latitude, phi, divided by the semimajor axis */ +// Compute the constant small m which is the radius of +// a parallel of latitude, phi, divided by the semimajor axis static double compute_m(double eccent, double sinphi, double cosphi) { const double con = eccent * sinphi; return ((cosphi / (sqrt(1.0 - con * con)))); } -/* Compute the constant small t for use in the forward computations */ +// Compute the constant small t for use in the forward computations static double compute_t( - double eccent, /* Eccentricity of the spheroid */ - double phi, /* Latitude phi */ - double sinphi) /* Sine of the latitude */ + double eccent, // Eccentricity of the spheroid + double phi, // Latitude phi + double sinphi) // Sine of the latitude { double con = eccent * sinphi; double com = 0.5 * eccent; @@ -162,10 +161,12 @@ static double calculate_eccentricity(double minor, double major) return sqrt(1.0 - temp * temp); } -static void xy2latlon(double radius, double n, double f, double rho0_bare, double LoVInRadians, +static void xy2lonlat(double radius, double n, double f, double rho0_bare, double LoVInRadians, double x, double y, - double* latDeg, double* lonDeg) + double* lonDeg, double* latDeg) { + DEBUG_ASSERT(radius > 0); + DEBUG_ASSERT(n != 0.0); x /= radius; y /= radius; y = rho0_bare - y; @@ -176,10 +177,10 @@ static void xy2latlon(double radius, double n, double f, double rho0_bare, doubl x = -x; y = -y; } - double lp_phi = 2. * atan(pow(f / rho, 1.0/n)) - M_PI_2; - double lp_lam = atan2(x, y) / n; - *lonDeg = lp_lam*RAD2DEG + LoVInRadians*RAD2DEG; - *latDeg = lp_phi*RAD2DEG; + double latRadians = 2. * atan(pow(f / rho, 1.0/n)) - M_PI_2; + double lonRadians = atan2(x, y) / n; + *lonDeg = (lonRadians + LoVInRadians) * RAD2DEG; + *latDeg = latRadians * RAD2DEG; } else { *lonDeg = 0.0; @@ -196,7 +197,7 @@ static int init_sphere(const grib_handle* h, double LoVInRadians, double Latin1InRadians, double Latin2InRadians, double LaDInRadians) { - double n, angle, x0, y0, x, y; + double n, x, y; if (fabs(Latin1InRadians - Latin2InRadians) < 1E-09) { n = sin(Latin1InRadians); @@ -208,25 +209,22 @@ static int init_sphere(const grib_handle* h, double f = (cos(Latin1InRadians) * pow(tan(M_PI_4 + Latin1InRadians / 2.0), n)) / n; double rho = radius * f * pow(tan(M_PI_4 + latFirstInRadians / 2.0), -n); double rho0_bare = f * pow(tan(M_PI_4 + LaDInRadians / 2.0), -n); - double rho0 = radius * rho0_bare; - - //if (n < 0) /* adjustment for southern hemisphere */ - // rho0 = -rho0; + double rho0 = radius * rho0_bare; // scaled double lonDiff = lonFirstInRadians - LoVInRadians; - /* Adjust longitude to range -180 to 180 */ + // Adjust longitude to range -180 to 180 if (lonDiff > M_PI) lonDiff -= 2 * M_PI; if (lonDiff < -M_PI) lonDiff += 2 * M_PI; - angle = n * lonDiff; - x0 = rho * sin(angle); - y0 = rho0 - rho * cos(angle); - /*Dx = iScansNegatively == 0 ? Dx : -Dx;*/ - /* GRIB-405: Don't change sign of Dy. Latitudes ALWAYS increase from latitudeOfFirstGridPoint */ - /*Dy = jScansPositively == 1 ? Dy : -Dy;*/ + double angle = n * lonDiff; + double x0 = rho * sin(angle); + double y0 = rho0 - rho * cos(angle); + // Dx = iScansNegatively == 0 ? Dx : -Dx; + // GRIB-405: Don't change sign of Dy. Latitudes ALWAYS increase from latitudeOfFirstGridPoint + // Dy = jScansPositively == 1 ? Dy : -Dy; - /* Allocate latitude and longitude arrays */ + // Allocate latitude and longitude arrays self->lats = (double*)grib_context_malloc(h->context, nv * sizeof(double)); if (!self->lats) { grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Error allocating %zu bytes", ITER, nv * sizeof(double)); @@ -244,13 +242,13 @@ static int init_sphere(const grib_handle* h, for (long i = 0; i < nx; i++) { const long index = i + j * nx; x = x0 + i * Dx; - xy2latlon(radius, n, f, rho0_bare, LoVInRadians, x, y, &latDeg, &lonDeg); + xy2lonlat(radius, n, f, rho0_bare, LoVInRadians, x, y, &lonDeg, &latDeg); self->lons[index] = lonDeg; self->lats[index] = latDeg; } } + #if 0 - /* Populate our arrays */ for (j = 0; j < ny; j++) { y = y0 + j * Dy; //if (n < 0) { /* adjustment for southern hemisphere */ @@ -260,8 +258,7 @@ static int init_sphere(const grib_handle* h, tmp2 = tmp * tmp; for (i = 0; i < nx; i++) { int index = i + j * nx; - x = x0 + i * Dx; - //printf("j=%d i=%d xy= %.6f %.6f\t",j,i,x,y); + x = x0 + i * Dx; //if (n < 0) { /* adjustment for southern hemisphere */ // x = -x; //} @@ -279,7 +276,7 @@ static int init_sphere(const grib_handle* h, return GRIB_SUCCESS; } -/* Oblate spheroid */ +// Oblate spheroid static int init_oblate(const grib_handle* h, grib_iterator_lambert_conformal* self, size_t nv, long nx, long ny, @@ -292,20 +289,20 @@ static int init_oblate(const grib_handle* h, { int i, j, err = 0; double x0, y0, x, y, latRad, lonRad, latDeg, lonDeg, sinphi, ts, rh1, theta; - double false_easting; /* x offset in meters */ - double false_northing; /* y offset in meters */ + double false_easting; // x offset in meters + double false_northing; // y offset in meters - double ns; /* ratio of angle between meridian */ - double F; /* flattening of ellipsoid */ - double rh; /* height above ellipsoid */ - double sin_po; /* sin value */ - double cos_po; /* cos value */ - double con; /* temporary variable */ - double ms1; /* small m 1 */ - double ms2; /* small m 2 */ - double ts0; /* small t 0 */ - double ts1; /* small t 1 */ - double ts2; /* small t 2 */ + double ns; // ratio of angle between meridian + double F; // flattening of ellipsoid + double rh; // height above ellipsoid + double sin_po; // sin value + double cos_po; // cos value + double con; // temporary variable + double ms1; // small m 1 + double ms2; // small m 2 + double ts0; // small t 0 + double ts1; // small t 1 + double ts2; // small t 2 double e = calculate_eccentricity(earthMinorAxisInMetres, earthMajorAxisInMetres); @@ -330,7 +327,7 @@ static int init_oblate(const grib_handle* h, F = ms1 / (ns * pow(ts1, ns)); rh = earthMajorAxisInMetres * F * pow(ts0, ns); - /* Forward projection: convert lat,lon to x,y */ + // Forward projection: convert lat,lon to x,y con = fabs(fabs(latFirstInRadians) - M_PI_2); if (con > EPSILON) { sinphi = sin(latFirstInRadians); @@ -350,7 +347,7 @@ static int init_oblate(const grib_handle* h, x0 = -x0; y0 = -y0; - /* Allocate latitude and longitude arrays */ + // Allocate latitude and longitude arrays self->lats = (double*)grib_context_malloc(h->context, nv * sizeof(double)); if (!self->lats) { grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Error allocating %zu bytes", ITER, nv * sizeof(double)); @@ -362,7 +359,7 @@ static int init_oblate(const grib_handle* h, return GRIB_OUT_OF_MEMORY; } - /* Populate our arrays */ + // Populate our arrays false_easting = x0; false_northing = y0; for (j = 0; j < ny; j++) { @@ -371,7 +368,7 @@ static int init_oblate(const grib_handle* h, const int index = i + j * nx; double _x, _y; x = i * Dx; - /* Inverse projection to convert from x,y to lat,lon */ + // Inverse projection to convert from x,y to lat,lon _x = x - false_easting; _y = rh - y + false_northing; rh1 = sqrt(_x * _x + _y * _y); @@ -401,7 +398,7 @@ static int init_oblate(const grib_handle* h, if (i == 0 && j == 0) { DEBUG_ASSERT(fabs(latFirstInRadians - latRad) <= EPSILON); } - latDeg = latRad * RAD2DEG; /* Convert to degrees */ + latDeg = latRad * RAD2DEG; // Convert to degrees lonDeg = normalise_longitude_in_degrees(lonRad * RAD2DEG); self->lons[index] = lonDeg; self->lats[index] = latDeg; @@ -431,7 +428,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) const char* sLatin2InDegrees = grib_arguments_get_name(h, args, self->carg++); const char* slatFirstInDegrees = grib_arguments_get_name(h, args, self->carg++); const char* slonFirstInDegrees = grib_arguments_get_name(h, args, self->carg++); - /* Dx and Dy are in Metres */ + // Dx and Dy are in Metres const char* sDx = grib_arguments_get_name(h, args, self->carg++); const char* sDy = grib_arguments_get_name(h, args, self->carg++); const char* siScansNegatively = grib_arguments_get_name(h, args, self->carg++); @@ -481,16 +478,16 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) if ((err = grib_get_long_internal(h, salternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS) return err; - /* Standard Parallels cannot be equal and on opposite sides of the equator */ + // Standard Parallels cannot be equal and on opposite sides of the equator if (fabs(Latin1InDegrees + Latin2InDegrees) < EPSILON) { grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Cannot have equal latitudes for standard parallels on opposite sides of equator", ITER); return GRIB_WRONG_GRID; } - /* - * See Wolfram MathWorld: http://mathworld.wolfram.com/LambertConformalConicProjection.html - */ + // + // See Wolfram MathWorld: http://mathworld.wolfram.com/LambertConformalConicProjection.html + // latFirstInRadians = latFirstInDegrees * DEG2RAD; lonFirstInRadians = lonFirstInDegrees * DEG2RAD; Latin1InRadians = Latin1InDegrees * DEG2RAD; @@ -516,7 +513,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) iter->e = -1; - /* Apply the scanning mode flags which may require data array to be transformed */ + // Apply the scanning mode flags which may require data array to be transformed err = transform_iterator_data(h->context, iter->data, iScansNegatively, jScansPositively, jPointsAreConsecutive, alternativeRowScanning, iter->nv, nx, ny); From 30d31f151d7d68d22f78358698f8727a5786e926 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 14 Feb 2024 20:29:46 +0000 Subject: [PATCH 008/156] ECC-1769: GRIB: Rename keys FirstLatitude and SecondLatitude --- definitions/grib2/template.3.30.def | 4 ++-- definitions/grib2/template.3.63.def | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/definitions/grib2/template.3.30.def b/definitions/grib2/template.3.30.def index 0168c967d..7bd63fc00 100644 --- a/definitions/grib2/template.3.30.def +++ b/definitions/grib2/template.3.30.def @@ -62,12 +62,12 @@ include "grib2/template.3.scanning_mode.def" # Latin 1 - first latitude from the pole at which the secant cone cuts the sphere signed[4] Latin1 : edition_specific; -alias FirstLatitude=Latin1; +alias firstLatitude=Latin1; meta geography.Latin1InDegrees scale(Latin1,one,grib2divider,truncateDegrees) : dump; # Latin 2 - second latitude from the pole at which the secant cone cuts the sphere signed[4] Latin2 : dump; -alias SecondLatitude=Latin2; +alias secondLatitude=Latin2; meta geography.Latin2InDegrees scale(Latin2,one,grib2divider,truncateDegrees) : dump; # Latitude of the southern pole of projection diff --git a/definitions/grib2/template.3.63.def b/definitions/grib2/template.3.63.def index 443283c5c..71db1eccc 100644 --- a/definitions/grib2/template.3.63.def +++ b/definitions/grib2/template.3.63.def @@ -38,12 +38,12 @@ flags[1] projectionCentreFlag 'grib2/tables/[tablesVersion]/3.5.table' : dump; # Latin 1 - first latitude from the pole at which the secant cone cuts the sphere signed[4] Latin1 : edition_specific; -alias FirstLatitude=Latin1; +alias firstLatitude=Latin1; meta geography.Latin1InDegrees scale(Latin1,one,grib2divider,truncateDegrees) : dump; # Latin 2 - second latitude from the pole at which the secant cone cuts the sphere signed[4] Latin2 : dump; -alias SecondLatitude=Latin2; +alias secondLatitude=Latin2; meta geography.Latin2InDegrees scale(Latin2,one,grib2divider,truncateDegrees) : dump; # Latitude of the southern pole of projection From 6eef31e2dd8aed0f5e9640b42dd8c82a5e4cdbbd Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 15 Feb 2024 12:03:30 +0000 Subject: [PATCH 009/156] ECC-1770: GRIB2: Template 4.1101 has incorrect octet layout --- definitions/grib2/template.4.1100.def | 1 + definitions/grib2/template.4.1101.def | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/definitions/grib2/template.4.1100.def b/definitions/grib2/template.4.1100.def index 76ebfc467..87016a586 100644 --- a/definitions/grib2/template.4.1100.def +++ b/definitions/grib2/template.4.1100.def @@ -1,6 +1,7 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.1100, Hovmoller-type grid with no averaging or other statistical processing +# This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" diff --git a/definitions/grib2/template.4.1101.def b/definitions/grib2/template.4.1101.def index ef9e951ed..6f27693f2 100644 --- a/definitions/grib2/template.4.1101.def +++ b/definitions/grib2/template.4.1101.def @@ -2,8 +2,26 @@ # TEMPLATE 4.1101, Hovmoller-type grid with averaging or other statistical processing +# This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests. +# (Octets 35-50 are very similar to octets 43-58 of product definition template 4.8, but the meaning of some fields differs slightly) + include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" include "grib2/template.4.forecast_time.def" include "grib2/template.4.horizontal.def" -include "grib2/template.4.statistical.def" + +unsigned[4] numberOfMissingInStatisticalProcess = 0 : edition_specific; +alias totalNumberOfDataValuesMissingInStatisticalProcess=numberOfMissingInStatisticalProcess; + +codetable[1] typeOfStatisticalProcessing ('4.10.table',masterDir,localDir) : edition_specific; + +codetable[1] typeOfTimeIncrement ('4.11.table',masterDir,localDir) = 2 : edition_specific; +alias typeOfTimeIncrementBetweenSuccessiveFieldsUsedInTheStatisticalProcessing=typeOfTimeIncrement; + +codetable[1] indicatorOfUnitForTimeRange ('4.4.table',masterDir,localDir) =1 ; +unsigned[4] lengthOfTimeRange=0 ; +codetable[1] indicatorOfUnitForTimeIncrement ('4.4.table',masterDir,localDir)=255 ; +unsigned[4] timeIncrement=0 ; +alias timeIncrementBetweenSuccessiveFields=timeIncrement; + +# include "grib2/template.4.statistical.def" From d7111f0185107b11f3f876745d92bd94be73dedc Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 15 Feb 2024 12:18:36 +0000 Subject: [PATCH 010/156] ECC-1767: GRIB2: Add keys to properly compute wavelengths in section 4 optical templates --- definitions/grib2/template.4.optical.def | 9 +++++++++ tests/grib2_wave_spectra.sh | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/definitions/grib2/template.4.optical.def b/definitions/grib2/template.4.optical.def index e1f9867ca..a73181f89 100644 --- a/definitions/grib2/template.4.optical.def +++ b/definitions/grib2/template.4.optical.def @@ -8,3 +8,12 @@ signed[1] scaleFactorOfFirstWavelength : dump; signed[4] scaledValueOfFirstWavelength : dump; signed[1] scaleFactorOfSecondWavelength = missing(): can_be_missing,dump; signed[4] scaledValueOfSecondWavelength = missing(): can_be_missing,dump; + +meta firstWavelength from_scale_factor_scaled_value(scaleFactorOfFirstWavelength, scaledValueOfFirstWavelength); +meta secondWavelength from_scale_factor_scaled_value(scaleFactorOfSecondWavelength, scaledValueOfSecondWavelength); +alias firstWavelengthInMetres = firstWavelength; +alias secondWavelengthInMetres = secondWavelength; + +constant oneBillionth = 1.0 / 1000000000 : hidden; +meta firstWavelengthInNanometres divdouble(firstWavelength, oneBillionth); +meta secondWavelengthInNanometres divdouble(secondWavelength, oneBillionth); diff --git a/tests/grib2_wave_spectra.sh b/tests/grib2_wave_spectra.sh index f610a08bb..44b58add8 100755 --- a/tests/grib2_wave_spectra.sh +++ b/tests/grib2_wave_spectra.sh @@ -45,6 +45,12 @@ grib_check_key_equals $temp scaleFactorOfLowerWavePeriodLimit,scaledValueOfLower ${tools_dir}/grib_set -s tablesVersion=$latest,productDefinitionTemplateNumber=104 $sample2 $temp grib_check_key_equals $temp scaleFactorOfLowerWavePeriodLimit,scaledValueOfLowerWavePeriodLimit,perturbationNumber 'MISSING MISSING 0' +${tools_dir}/grib_set -s \ + tablesVersion=$latest,productDefinitionTemplateNumber=108,scaleFactorOfFirstWavelength=9,scaledValueOfFirstWavelength=12 \ +$sample2 $temp +grib_check_key_equals $temp firstWavelengthInNanometres '12' +grib_check_key_equals $temp firstWavelengthInMetres '1.2e-08' + # Clean up rm -f $tempSample $temp From d2e0ac57682c0b4ab291bd138174881da5c7f7d7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 15 Feb 2024 15:02:51 +0000 Subject: [PATCH 011/156] Testing: Accessors 'sum' and 'suppressed' --- tests/grib_filter.sh | 13 +++++++++++++ tests/grib_suppressed.sh | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index 9a836a898..951ea9433 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -237,6 +237,19 @@ grib_check_key_equals $tempGrib scaleFactorOfFirstFixedSurface MISSING grib_check_key_equals $tempGrib scaledValueOfFirstFixedSurface MISSING +echo "Test for the sum accessor" +# ------------------------------- +input="${samp_dir}/reduced_gg_pl_32_grib2.tmpl" +cat >$tempFilt < $tempOut + + echo "Test from_scale_factor_scaled_value" # ----------------------------------------- input="${samp_dir}/reduced_gg_pl_32_grib2.tmpl" diff --git a/tests/grib_suppressed.sh b/tests/grib_suppressed.sh index 2b8477064..39a42dbe4 100755 --- a/tests/grib_suppressed.sh +++ b/tests/grib_suppressed.sh @@ -39,6 +39,29 @@ EOF diff $tempRef $tempErr +# Try decoding as int and double too +cat > $tempFilt <$tempErr +status=$? +set -e +[ $status -ne 0 ] +grep -q "is unavailable" $tempErr + + +cat > $tempFilt <$tempErr +status=$? +set -e +[ $status -ne 0 ] +grep -q "is unavailable" $tempErr # Clean up rm -f $tempFilt $tempErr $tempRef From 8c1719dadd498ae2388e5099360b5d4b2e79100e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 15 Feb 2024 15:22:32 +0000 Subject: [PATCH 012/156] Testing: Accessor suppressed --- tests/grib_suppressed.sh | 51 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/tests/grib_suppressed.sh b/tests/grib_suppressed.sh index 39a42dbe4..046eebfb5 100755 --- a/tests/grib_suppressed.sh +++ b/tests/grib_suppressed.sh @@ -17,19 +17,6 @@ tempFilt=temp.${label}.filt tempRef=temp.${label}.ref sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl -cat > $tempFilt <$tempErr -status=$? -set -e -[ $status -ne 0 ] - -cat $tempErr - cat > $tempRef < $tempFilt + set +e + ${tools_dir}/grib_filter $tempFilt $sample2 2>$tempErr + status=$? + set -e + [ $status -ne 0 ] + cat $tempErr + diff $tempRef $tempErr +} -# Try decoding as int and double too -cat > $tempFilt <$tempErr -status=$? -set -e -[ $status -ne 0 ] -grep -q "is unavailable" $tempErr +do_tests "" +do_tests ":i" +do_tests ":d" -cat > $tempFilt <$tempErr -status=$? -set -e -[ $status -ne 0 ] -grep -q "is unavailable" $tempErr - # Clean up rm -f $tempFilt $tempErr $tempRef From 9baed622acbb5fd1126569cd3f81a661fffcd7a3 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 17 Feb 2024 19:30:26 +0000 Subject: [PATCH 013/156] Testing: Further tests for grib_util_set_spec --- tests/CMakeLists.txt | 2 + tests/grib_util_set_spec2.cc | 210 +++++++++++++++++++++++++++++++++++ tests/grib_util_set_spec2.sh | 18 +++ 3 files changed, 230 insertions(+) create mode 100644 tests/grib_util_set_spec2.cc create mode 100755 tests/grib_util_set_spec2.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 32c20a5a5..3edb8ee1e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,7 @@ list(APPEND test_c_bins gauss_sub grib_nearest_test grib_util_set_spec + grib_util_set_spec2 grib_check_param_concepts grib_local_MeteoFrance grib_2nd_order_numValues @@ -356,6 +357,7 @@ if( HAVE_BUILD_TOOLS ) endif() if( ENABLE_EXTRA_TESTS ) list(APPEND tests_extra grib_util_set_spec) + list(APPEND tests_extra grib_util_set_spec2) list(APPEND tests_extra grib_padding) list(APPEND tests_extra grib_tigge_conversions1) list(APPEND tests_extra grib_tigge_conversions2) diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc new file mode 100644 index 000000000..00f2111e3 --- /dev/null +++ b/tests/grib_util_set_spec2.cc @@ -0,0 +1,210 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +#include "grib_api_internal.h" +#include "eccodes.h" + +static void dump_it(grib_handle* h) +{ + int dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY; + grib_dump_content(h, stdout, "wmo", dump_flags, NULL); +} + +// Lambert conformal +static void test0() +{ + int err = 0; + grib_handle* finalh = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 4; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_CONFORMAL; + spec.N = 2; + + // packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; + // packing_spec.bitsPerValue = 16; + // packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; + // packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; + + finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// Lambert azimuthal +static void test1() +{ + int err = 0; + grib_handle* finalh = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 4; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_AZIMUTHAL_EQUAL_AREA; + + finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// HEALPix +static void test2() +{ + int err = 0; + grib_handle* finalh = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 0; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_HEALPIX; + spec.N = 2; + outlen = 4; + + packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; + packing_spec.bitsPerValue = 16; + packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; + packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; + + finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// Spherical harmonics +static void test3() +{ + int err = 0; + grib_handle* finalh = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2}; + int set_spec_flags = 0; + size_t outlen = 0; + + grib_handle* handle = grib_handle_new_from_samples(0, "sh_pl_grib2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_SH; + spec.truncation = 20; + outlen = 2; + + packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_SPECTRAL_SIMPLE; + packing_spec.bitsPerValue = 16; + packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; + packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; + + finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// Polar stereo +static void test4() +{ + int err = 0; + grib_handle* finalh = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 0; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_POLAR_STEREOGRAPHIC; + outlen = 4; + + finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +int main() +{ + test0(); + test1(); + test2(); + test3(); + test4(); + return 0; +} + +#if 0 +int main(int argc, char* argv[]) +{ + int i = 0, remove_local_def = 0; + int edition = 0; + char* packingType = NULL; + const char* prog = argv[0]; + char* infile_name = NULL; + char* outfile_name = NULL; + + if (argc == 1 || argc > 8) usage(prog); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-p") == 0) { + packingType = argv[i + 1]; + ++i; + } + else if (strcmp(argv[i], "-e") == 0) { + edition = atoi(argv[i + 1]); + ++i; + } + else if (strcmp(argv[i], "-r") == 0) { + remove_local_def = 1; + } + else { + /* Expect 2 filenames */ + infile_name = argv[i]; + outfile_name = argv[i + 1]; + break; + } + } +#if 0 + printf("DEBUG remove_local_def = %d\n", remove_local_def); + printf("DEBUG edition = %d\n", edition); + printf("DEBUG packingType = %s\n", packingType); + printf("DEBUG infile_name = %s\n", infile_name); + printf("DEBUG outfile_name = %s\n", outfile_name); +#endif + test_regular_ll(remove_local_def, edition, packingType, infile_name, outfile_name); + test_reduced_gg(remove_local_def, edition, packingType, infile_name, outfile_name); + /*test_grid_complex_spatial_differencing(remove_local_def, edition, packingType, infile_name, outfile_name);*/ + + return 0; +} +#endif diff --git a/tests/grib_util_set_spec2.sh b/tests/grib_util_set_spec2.sh new file mode 100755 index 000000000..6dd54373a --- /dev/null +++ b/tests/grib_util_set_spec2.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +grib_util_set_spec=${test_dir}/grib_util_set_spec2 +$EXEC $grib_util_set_spec + + +### Clean up + From 5cdd9d17cb1111605e1d5639d8261d09f1b7b859 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 17 Feb 2024 20:38:38 +0000 Subject: [PATCH 014/156] grib_util_set_spec: Support reduced latlon --- src/grib_util.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/grib_util.cc b/src/grib_util.cc index ab6283987..c559eeacb 100644 --- a/src/grib_util.cc +++ b/src/grib_util.cc @@ -897,6 +897,9 @@ static int get_grib_sample_name(grib_handle* h, long editionNumber, case GRIB_UTIL_GRID_SPEC_HEALPIX: snprintf(sample_name, sample_name_len, "GRIB%ld", editionNumber); break; + case GRIB_UTIL_GRID_SPEC_REDUCED_LL: + snprintf(sample_name, sample_name_len, "%s_sfc_grib%ld", grid_type, editionNumber); + break; default: snprintf(sample_name, sample_name_len, "%s_pl_grib%ld", grid_type, editionNumber); } From e89dfad0ba4a69fb344c8e8bb7191a63df448f62 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 17 Feb 2024 20:39:03 +0000 Subject: [PATCH 015/156] Testing: grib_util_set_spec for reduced ll --- tests/grib_util_set_spec2.cc | 127 +++++++++++++++++------------------ tests/grib_util_set_spec2.sh | 7 +- 2 files changed, 63 insertions(+), 71 deletions(-) diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc index 00f2111e3..5231ffd90 100644 --- a/tests/grib_util_set_spec2.cc +++ b/tests/grib_util_set_spec2.cc @@ -21,7 +21,6 @@ static void dump_it(grib_handle* h) static void test0() { int err = 0; - grib_handle* finalh = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; double values[4] = {1.1, 2.2, 3.3, 0.4}; @@ -29,16 +28,20 @@ static void test0() size_t outlen = 4; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); - grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_CONFORMAL; spec.N = 2; + packing_spec.extra_settings_count = 1; + packing_spec.extra_settings[0].type = GRIB_TYPE_LONG; + packing_spec.extra_settings[0].name = "tablesVersion"; + packing_spec.extra_settings[0].long_value = 32; + // packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; // packing_spec.bitsPerValue = 16; - // packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; + // packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; // packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; - finalh = grib_util_set_spec( + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(finalh); @@ -50,7 +53,6 @@ static void test0() static void test1() { int err = 0; - grib_handle* finalh = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; double values[4] = {1.1, 2.2, 3.3, 0.4}; @@ -61,7 +63,7 @@ static void test1() grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_AZIMUTHAL_EQUAL_AREA; - finalh = grib_util_set_spec( + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(finalh); @@ -73,25 +75,18 @@ static void test1() static void test2() { int err = 0; - grib_handle* finalh = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; double values[4] = {1.1, 2.2, 3.3, 0.4}; int set_spec_flags = 0; - size_t outlen = 0; + size_t outlen = 4; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_HEALPIX; spec.N = 2; - outlen = 4; - packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; - packing_spec.bitsPerValue = 16; - packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; - packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; - - finalh = grib_util_set_spec( + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(finalh); @@ -103,7 +98,6 @@ static void test2() static void test3() { int err = 0; - grib_handle* finalh = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; double values[4] = {1.1, 2.2}; @@ -121,7 +115,7 @@ static void test3() packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; - finalh = grib_util_set_spec( + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(finalh); @@ -133,7 +127,6 @@ static void test3() static void test4() { int err = 0; - grib_handle* finalh = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; double values[4] = {1.1, 2.2, 3.3, 0.4}; @@ -145,7 +138,55 @@ static void test4() spec.grid_type = GRIB_UTIL_GRID_SPEC_POLAR_STEREOGRAPHIC; outlen = 4; - finalh = grib_util_set_spec( + grib_handle* finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// Regular Gaussian +static void test5() +{ + int err = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 0; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_GG; + spec.Ni = spec.Nj = 2; + outlen = 4; + + grib_handle* finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(finalh); + Assert(err == 0); + dump_it(finalh); +} + +// Reduced LL +static void test6() +{ + int err = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 0; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_set_long(handle, "tablesVersion", 32); + spec.grid_type = GRIB_UTIL_GRID_SPEC_REDUCED_LL; + spec.Nj = 2; + outlen = 4; + + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(finalh); @@ -160,51 +201,7 @@ int main() test2(); test3(); test4(); + test5(); + test6(); return 0; } - -#if 0 -int main(int argc, char* argv[]) -{ - int i = 0, remove_local_def = 0; - int edition = 0; - char* packingType = NULL; - const char* prog = argv[0]; - char* infile_name = NULL; - char* outfile_name = NULL; - - if (argc == 1 || argc > 8) usage(prog); - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-p") == 0) { - packingType = argv[i + 1]; - ++i; - } - else if (strcmp(argv[i], "-e") == 0) { - edition = atoi(argv[i + 1]); - ++i; - } - else if (strcmp(argv[i], "-r") == 0) { - remove_local_def = 1; - } - else { - /* Expect 2 filenames */ - infile_name = argv[i]; - outfile_name = argv[i + 1]; - break; - } - } -#if 0 - printf("DEBUG remove_local_def = %d\n", remove_local_def); - printf("DEBUG edition = %d\n", edition); - printf("DEBUG packingType = %s\n", packingType); - printf("DEBUG infile_name = %s\n", infile_name); - printf("DEBUG outfile_name = %s\n", outfile_name); -#endif - test_regular_ll(remove_local_def, edition, packingType, infile_name, outfile_name); - test_reduced_gg(remove_local_def, edition, packingType, infile_name, outfile_name); - /*test_grid_complex_spatial_differencing(remove_local_def, edition, packingType, infile_name, outfile_name);*/ - - return 0; -} -#endif diff --git a/tests/grib_util_set_spec2.sh b/tests/grib_util_set_spec2.sh index 6dd54373a..95fc00c01 100755 --- a/tests/grib_util_set_spec2.sh +++ b/tests/grib_util_set_spec2.sh @@ -10,9 +10,4 @@ . ./include.ctest.sh -grib_util_set_spec=${test_dir}/grib_util_set_spec2 -$EXEC $grib_util_set_spec - - -### Clean up - +$EXEC ${test_dir}/grib_util_set_spec2 From 6a41db4730a4cc1a9835b9b0df23118cf56cccf9 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 17 Feb 2024 22:17:18 +0000 Subject: [PATCH 016/156] Testing: grib_util_set_spec cleanup --- tests/grib_util_set_spec2.cc | 92 +++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc index 5231ffd90..11e86a915 100644 --- a/tests/grib_util_set_spec2.cc +++ b/tests/grib_util_set_spec2.cc @@ -18,7 +18,7 @@ static void dump_it(grib_handle* h) } // Lambert conformal -static void test0() +static grib_handle* test0() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -27,14 +27,10 @@ static void test0() int set_spec_flags = 0; size_t outlen = 4; - grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB1"); spec.grid_type = GRIB_UTIL_GRID_SPEC_LAMBERT_CONFORMAL; - spec.N = 2; - - packing_spec.extra_settings_count = 1; - packing_spec.extra_settings[0].type = GRIB_TYPE_LONG; - packing_spec.extra_settings[0].name = "tablesVersion"; - packing_spec.extra_settings[0].long_value = 32; + spec.Ni = 2; + spec.Nj = 2; // packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE; // packing_spec.bitsPerValue = 16; @@ -44,13 +40,12 @@ static void test0() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // Lambert azimuthal -static void test1() +static grib_handle* test1() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -66,13 +61,12 @@ static void test1() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // HEALPix -static void test2() +static grib_handle* test2() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -82,20 +76,23 @@ static void test2() size_t outlen = 4; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); - grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_HEALPIX; spec.N = 2; + packing_spec.extra_settings_count = 1; + packing_spec.extra_settings[0].type = GRIB_TYPE_LONG; + packing_spec.extra_settings[0].name = "tablesVersion"; + packing_spec.extra_settings[0].long_value = 32; + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // Spherical harmonics -static void test3() +static grib_handle* test3() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -105,7 +102,6 @@ static void test3() size_t outlen = 0; grib_handle* handle = grib_handle_new_from_samples(0, "sh_pl_grib2"); - grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_SH; spec.truncation = 20; outlen = 2; @@ -118,13 +114,12 @@ static void test3() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // Polar stereo -static void test4() +static grib_handle* test4() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -141,13 +136,12 @@ static void test4() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // Regular Gaussian -static void test5() +static grib_handle* test5() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -157,7 +151,6 @@ static void test5() size_t outlen = 0; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); - grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_GG; spec.Ni = spec.Nj = 2; outlen = 4; @@ -165,13 +158,12 @@ static void test5() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; } // Reduced LL -static void test6() +static grib_handle* test6() { int err = 0; grib_util_grid_spec spec = {0,}; @@ -181,7 +173,6 @@ static void test6() size_t outlen = 0; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); - grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_REDUCED_LL; spec.Nj = 2; outlen = 4; @@ -189,19 +180,42 @@ static void test6() grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); - Assert(finalh); Assert(err == 0); - dump_it(finalh); + return finalh; +} + +// Unstructured +static grib_handle* test7() +{ + int err = 0; + grib_util_grid_spec spec = {0,}; + grib_util_packing_spec packing_spec = {0,}; + double values[4] = {1.1, 2.2, 3.3, 0.4}; + int set_spec_flags = 0; + size_t outlen = 4; + + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + spec.grid_type = GRIB_UTIL_GRID_SPEC_UNSTRUCTURED; + + grib_handle* finalh = grib_util_set_spec( + handle, &spec, &packing_spec, set_spec_flags, + values, outlen, &err); + Assert(err == 0); + return finalh; } int main() { - test0(); - test1(); - test2(); - test3(); - test4(); - test5(); - test6(); + typedef grib_handle* (*test_func)(void); + test_func funcs[] = {test0, test1, test2, test3, test4, test5, test6, test7}; + + //grib_handle* (*p[8]) (void) = {test0, test1, test2, test3, test4, test5, test6, test7}; + + const size_t num_tests = sizeof(funcs)/sizeof(funcs[0]); + for (size_t i = 0; i < num_tests; i++) { + grib_handle* result = funcs[i](); + Assert(result); + dump_it(result); + } return 0; } From 95bd0bc0066ea9bdf0b3890ef68fa865edcc4694 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 13:12:13 +0000 Subject: [PATCH 017/156] Testing: Secondary bitmaps (GRIB1) --- tests/grib_secondary_bitmap.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/grib_secondary_bitmap.sh b/tests/grib_secondary_bitmap.sh index 11af77e6b..05cfb5951 100755 --- a/tests/grib_secondary_bitmap.sh +++ b/tests/grib_secondary_bitmap.sh @@ -18,6 +18,7 @@ tempLog=temp.$label.log tempRef=temp.$label.ref # Use a GRIB2 input with a bitmap +# ---------------------------------- input=$data_dir/reduced_latlon_surface.grib2 grib_check_key_equals $input bitmapPresent 1 ${tools_dir}/grib_set -s packingType=grid_simple_matrix,NC=1,NR=1 $input $tempGribA @@ -26,10 +27,23 @@ ${tools_dir}/grib_dump -O $tempGribB ${tools_dir}/grib_dump -Dat $tempGribB # Call pack_double and unpack_double +# ---------------------------------- cat >$tempFilt<$tempFilt< Date: Sun, 18 Feb 2024 13:14:07 +0000 Subject: [PATCH 018/156] Cleanup --- definitions/boot.def | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/definitions/boot.def b/definitions/boot.def index 61a7b7be0..8111e1634 100644 --- a/definitions/boot.def +++ b/definitions/boot.def @@ -18,12 +18,12 @@ constant defaultTypeOfLevel="unknown" : hidden; gribDataQualityChecks = getenv("ECCODES_GRIB_DATA_QUALITY_CHECKS","0") : hidden; if (gribDataQualityChecks) { - template LIMITS "param_limits.def"; + template LIMITS "param_limits.def"; } # GRIBEX special boustrophedonic mode. See GRIB-472 # If the environment variable is not defined, the key will be 0 -GRIBEX_boustrophedonic = getenv("ECCODES_GRIBEX_BOUSTROPHEDONIC","0") :hidden; +GRIBEX_boustrophedonic = getenv("ECCODES_GRIBEX_BOUSTROPHEDONIC","0") :hidden; constant zero=0 : hidden; constant one=1 : hidden; @@ -61,65 +61,65 @@ transient produceLargeConstantFields = 0 : hidden; meta libraryVersion library_version() : hidden; -lookup[4] kindOfProduct (0,identifier) : hidden; +lookup[4] kindOfProduct (0,identifier) : hidden; # grib templates # `ABCD` is a number, each letter being a byte if(kindOfProduct == `GRIB`){ - lookup[1] GRIBEditionNumber (7,editionNumber) : edition_specific ; - template GRIB "grib[GRIBEditionNumber:l]/boot.def" ; + lookup[1] GRIBEditionNumber (7,editionNumber) : edition_specific; + template GRIB "grib[GRIBEditionNumber:l]/boot.def" ; } if(kindOfProduct == `BUDG` ){ - template BUDG "budg/boot.def" ; + template BUDG "budg/boot.def" ; } if(kindOfProduct == `DIAG`){ - template DIAG "diag/boot.def" ; + template DIAG "diag/boot.def" ; } if(kindOfProduct == `TIDE`){ - template TIDE "tide/boot.def" ; + template TIDE "tide/boot.def" ; } if(kindOfProduct == `BUFR`){ - template BUFR "bufr/boot.def" ; + template BUFR "bufr/boot.def" ; #constant BUFRstr="BUFR"; #ECC-742 #alias identifier=BUFRstr; } if(kindOfProduct == `CDFX`){ - template CDF "cdf/boot.def" ; - constant CDFstr="netCDF"; + template CDF "cdf/boot.def" ; + constant CDFstr="netCDF"; alias ls.identifier=CDFstr; } if(kindOfProduct == 17632522 ){ - template GTS "gts/boot.def" ; + template GTS "gts/boot.def" ; constant GTSstr="GTS"; alias ls.identifier=GTSstr; } if(kindOfProduct == `META` ){ - template METAR "metar/boot.def" ; + template METAR "metar/boot.def" ; constant METARstr="METAR"; alias identifier=METARstr; } if(kindOfProduct == `TAF ` ){ - template TAF "taf/boot.def" ; + template TAF "taf/boot.def" ; constant TAFstr="TAF"; alias ls.identifier=TAFstr; } if(kindOfProduct == 2303214662){ - template HDF5 "hdf5/boot.def" ; - constant HDF5str="HDF5"; + template HDF5 "hdf5/boot.def" ; + constant HDF5str="HDF5"; alias ls.identifier=HDF5str; } if(kindOfProduct == `WRAP`){ - template WRAP "wrap/boot.def" ; - constant WRAPstr="WRAP"; + template WRAP "wrap/boot.def" ; + constant WRAPstr="WRAP"; alias ls.identifier=WRAPstr; } From 2535d2ec0ca851559e05cad3d303d8b087861877 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 14:09:35 +0000 Subject: [PATCH 019/156] Testing: signed_bits --- tests/grib_filter.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index 951ea9433..c932cf026 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -467,6 +467,18 @@ set -e [ $status -ne 0 ] grep -q "Unable to open file" $tempOut +# Signed bits +# ----------- +cat >$tempFilt < $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] + # Setting step # ------------- From f691cd9d0c90ce699114d41db232bc9cbc405114 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 14:24:37 +0000 Subject: [PATCH 020/156] cppcheck warnings --- src/grib_accessor.cc | 117 +++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/src/grib_accessor.cc b/src/grib_accessor.cc index 62d4c5e59..0b4b7ed99 100644 --- a/src/grib_accessor.cc +++ b/src/grib_accessor.cc @@ -10,13 +10,12 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 - * Enrico Fucile ***************************************************************************/ #include "grib_accessor.h" -/* Note: A fast cut-down version of strcmp which does NOT return -1 */ -/* 0 means input strings are equal and 1 means not equal */ +// Note: A fast cut-down version of strcmp which does NOT return -1 +// 0 means input strings are equal and 1 means not equal GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) { if (*a != *b) @@ -44,7 +43,7 @@ void grib_accessor_dump(grib_accessor* a, grib_dumper* f) int grib_pack_missing(grib_accessor* a) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->pack_missing) { return c->pack_missing(a); @@ -58,7 +57,6 @@ int grib_pack_missing(grib_accessor* a) int grib_pack_zero(grib_accessor* a) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ while (c) { if (c->clear) { return c->clear(a); @@ -72,7 +70,8 @@ int grib_pack_zero(grib_accessor* a) int grib_is_missing_internal(grib_accessor* a) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + // grib_context_log(a->context, GRIB_LOG_DEBUG, + // "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->is_missing) { return c->is_missing(a); @@ -86,7 +85,7 @@ int grib_is_missing_internal(grib_accessor* a) int grib_pack_double(grib_accessor* a, const double* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->pack_double) { return c->pack_double(a, v, len); @@ -113,7 +112,7 @@ int grib_pack_float(grib_accessor* a, const float* v, size_t* len) int grib_pack_expression(grib_accessor* a, grib_expression* e) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->pack_expression) { return c->pack_expression(a, e); @@ -127,7 +126,7 @@ int grib_pack_expression(grib_accessor* a, grib_expression* e) int grib_pack_string(grib_accessor* a, const char* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (string) %s",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?v:"(null)");*/ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (string) %s",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?v:"(null)"); while (c) { if (c->pack_string) { return c->pack_string(a, v, len); @@ -141,7 +140,7 @@ int grib_pack_string(grib_accessor* a, const char* v, size_t* len) int grib_pack_string_array(grib_accessor* a, const char** v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (string) %s",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?v:"(null)");*/ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (string) %s",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?v:"(null)"); while (c) { if (c->pack_string_array) { return c->pack_string_array(a, v, len); @@ -155,7 +154,7 @@ int grib_pack_string_array(grib_accessor* a, const char** v, size_t* len) int grib_pack_long(grib_accessor* a, const long* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->pack_long) { return c->pack_long(a, v, len); @@ -169,7 +168,7 @@ int grib_pack_long(grib_accessor* a, const long* v, size_t* len) int grib_pack_bytes(grib_accessor* a, const unsigned char* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (bytes) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (bytes) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->pack_bytes) { return c->pack_bytes(a, v, len); @@ -183,7 +182,7 @@ int grib_pack_bytes(grib_accessor* a, const unsigned char* v, size_t* len) int grib_unpack_bytes(grib_accessor* a, unsigned char* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (bytes)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (bytes)",(a->parent->owner)?(a->parent->owner->name):"root", a->name); while (c) { if (c->unpack_bytes) { return c->unpack_bytes(a, v, len); @@ -210,7 +209,7 @@ int grib_unpack_double_subarray(grib_accessor* a, double* v, size_t start, size_ int grib_unpack_double(grib_accessor* a, double* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (double)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (double)",(a->parent->owner)?(a->parent->owner->name):"root", a->name); while (c) { if (c->unpack_double) { return c->unpack_double(a, v, len); @@ -225,7 +224,7 @@ int grib_unpack_float(grib_accessor* a, float* v, size_t* len) { grib_accessor_class* c = a->cclass; while (c) { - /* printf("grib_accessor.c grib_unpack_float:: c->name=%s\n",c->name); */ + //printf("grib_accessor.c grib_unpack_float:: c->name=%s\n",c->name); if (c->unpack_float) { return c->unpack_float(a, v, len); } @@ -260,20 +259,19 @@ int grib_unpack_double_element(grib_accessor* a, size_t i, double* v) } int grib_unpack_float_element(grib_accessor* a, size_t i, float* v) { - /* grib_accessor_class* c = a->cclass; - * while (c) { - * if (c->unpack_float_element) { - * return c->unpack_float_element(a, i, v); - * } - * c = c->super ? *(c->super) : NULL; - * } - */ + // grib_accessor_class* c = a->cclass; + // while (c) { + // if (c->unpack_float_element) { + // return c->unpack_float_element(a, i, v); + // } + // c = c->super ? *(c->super) : NULL; + //} + return GRIB_NOT_IMPLEMENTED; } -/* Get the values for the indices passed in. - * The length of the 'index_array' argument should be 'len' and 'val_array' should also contain at least 'len' elements - */ +// Get the values for the indices passed in. +// The length of the 'index_array' argument should be 'len' and 'val_array' should also contain at least 'len' elements int grib_unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { grib_accessor_class* c = a->cclass; @@ -288,23 +286,22 @@ int grib_unpack_double_element_set(grib_accessor* a, const size_t* index_array, } int grib_unpack_float_element_set(grib_accessor* a, const size_t* index_array, size_t len, float* val_array) { - /* - *grib_accessor_class* c = a->cclass; - *DEBUG_ASSERT(len > 0); - *while (c) { - * if (c->unpack_float_element_set) { - * return c->unpack_float_element_set(a, index_array, len, val_array); - * } - * c = c->super ? *(c->super) : NULL; - *} - */ + // grib_accessor_class* c = a->cclass; + // DEBUG_ASSERT(len > 0); + // while (c) { + // if (c->unpack_float_element_set) { + // return c->unpack_float_element_set(a, index_array, len, val_array); + // } + // c = c->super ? *(c->super) : NULL; + // } + return GRIB_NOT_IMPLEMENTED; } int grib_unpack_string(grib_accessor* a, char* v, size_t* len) { grib_accessor_class* c = a->cclass; - /* grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (string)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (string)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); while (c) { if (c->unpack_string) { return c->unpack_string(a, v, len); @@ -399,7 +396,7 @@ int grib_accessors_list_unpack_string(grib_accessors_list* al, char** val, size_ int grib_unpack_long(grib_accessor* a, long* v, size_t* len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (long)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is unpacking (long)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); while (c) { if (c->unpack_long) { return c->unpack_long(a, v, len); @@ -428,7 +425,8 @@ long grib_accessor_get_native_type(grib_accessor* a) long grib_get_next_position_offset(grib_accessor* a) { grib_accessor_class* c = NULL; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is checking next (long)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, + // "(%s)%s is checking next (long)",(a->parent->owner)?(a->parent->owner->name):"root", a->name ); if (a) c = a->cclass; @@ -533,8 +531,7 @@ int grib_accessor_notify_change(grib_accessor* a, grib_accessor* changed) return 0; } -/* For this one, ALL init are called */ - +// For this one, ALL init are called static void init_accessor(grib_accessor_class* c, grib_accessor* a, const long len, grib_arguments* args) { if (c) { @@ -550,27 +547,26 @@ void grib_init_accessor(grib_accessor* a, const long len, grib_arguments* args) init_accessor(a->cclass, a, len, args); } -/* For this one, ALL destroy are called */ - +// For this one, ALL destroy are called void grib_accessor_delete(grib_context* ct, grib_accessor* a) { grib_accessor_class* c = a->cclass; while (c) { grib_accessor_class* s = c->super ? *(c->super) : NULL; - /*printf("grib_accessor_delete: before destroy a=%p c->name=%s ==> a->name=%s\n", (void*)a, c->name, a->name);*/ + //printf("grib_accessor_delete: before destroy a=%p c->name=%s ==> a->name=%s\n", (void*)a, c->name, a->name); if (c->destroy) { c->destroy(ct, a); } c = s; } - /*printf("grib_accessor_delete before free a=%p\n", (void*)a);*/ + // printf("grib_accessor_delete before free a=%p\n", (void*)a); grib_context_free(ct, a); } grib_accessor* grib_accessor_clone(grib_accessor* a, grib_section* s, int* err) { grib_accessor_class* c = a->cclass; - grib_context* ct = a->context; + const grib_context* ct = a->context; while (c) { grib_accessor_class* super = c->super ? *(c->super) : NULL; grib_context_log(ct, GRIB_LOG_DEBUG, "clone %s ==> %s", c->name, a->name); @@ -585,7 +581,8 @@ grib_accessor* grib_accessor_clone(grib_accessor* a, grib_section* s, int* err) void grib_update_size(grib_accessor* a, size_t len) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, + // "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->update_size) { c->update_size(a, len); @@ -613,7 +610,8 @@ int grib_nearest_smaller_value(grib_accessor* a, double val, double* nearest) size_t grib_preferred_size(grib_accessor* a, int from_handle) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + // grib_context_log(a->context, GRIB_LOG_DEBUG, + // "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->preferred_size) { return c->preferred_size(a, from_handle); @@ -640,7 +638,8 @@ grib_accessor* grib_next_accessor(grib_accessor* a) void grib_resize(grib_accessor* a, size_t new_size) { grib_accessor_class* c = a->cclass; - /*grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); */ + //grib_context_log(a->context, GRIB_LOG_DEBUG, + // "(%s)%s is packing (long) %d",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); while (c) { if (c->resize) { c->resize(a, new_size); @@ -714,7 +713,7 @@ int grib_accessor_add_attribute(grib_accessor* a, grib_accessor* attr, int nest_ for (id = 0; id < MAX_ACCESSOR_ATTRIBUTES; id++) { if (aloc->attributes[id] == NULL) { - /* attr->parent=a->parent; */ + // attr->parent=a->parent; aloc->attributes[id] = attr; attr->parent_as_attribute = aloc; if (aloc->same) @@ -823,7 +822,7 @@ grib_accessors_list* grib_accessors_list_create(grib_context* c) void grib_accessors_list_push(grib_accessors_list* al, grib_accessor* a, int rank) { grib_accessors_list* last; - grib_context* c = a->context; + const grib_context* c = a->context; last = grib_accessors_list_last(al); if (last && last->accessor) { @@ -842,15 +841,13 @@ void grib_accessors_list_push(grib_accessors_list* al, grib_accessor* a, int ran grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al) { - /*grib_accessors_list* last=al;*/ - /*grib_accessors_list* next=al->next;*/ + // grib_accessors_list* last=al; + // grib_accessors_list* next=al->next; + // while(next) { + // last=next; + // next=last->next; + // } - /* - while(next) { - last=next; - next=last->next; - } - */ return al->last; } @@ -875,7 +872,7 @@ void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al) while (al) { tmp = al->next; - /*grib_accessor_delete(c, al->accessor);*/ + //grib_accessor_delete(c, al->accessor); grib_context_free(c, al); al = tmp; } From 2925ec7c91e30c4035f32537569ee81fe39bfa49 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 14:28:25 +0000 Subject: [PATCH 021/156] cppcheck warnings --- src/action_class_set_darray.cc | 5 ++--- src/action_class_set_missing.cc | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/action_class_set_darray.cc b/src/action_class_set_darray.cc index 97211a219..bbf36f1d6 100644 --- a/src/action_class_set_darray.cc +++ b/src/action_class_set_darray.cc @@ -98,15 +98,14 @@ grib_action* grib_action_create_set_darray(grib_context* context, static int execute(grib_action* a, grib_handle* h) { - grib_action_set_darray* self = (grib_action_set_darray*)a; - + const grib_action_set_darray* self = (grib_action_set_darray*)a; return grib_set_double_array(h, self->name, self->darray->v, self->darray->n); } static void dump(grib_action* act, FILE* f, int lvl) { int i = 0; - grib_action_set_darray* self = (grib_action_set_darray*)act; + const grib_action_set_darray* self = (grib_action_set_darray*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); diff --git a/src/action_class_set_missing.cc b/src/action_class_set_missing.cc index 84b5fe085..3a40038b5 100644 --- a/src/action_class_set_missing.cc +++ b/src/action_class_set_missing.cc @@ -73,8 +73,7 @@ static void init_class(grib_action_class* c) } /* END_CLASS_IMP */ -grib_action* grib_action_create_set_missing(grib_context* context, - const char* name) +grib_action* grib_action_create_set_missing(grib_context* context, const char* name) { char buf[1024]; @@ -98,15 +97,14 @@ grib_action* grib_action_create_set_missing(grib_context* context, static int execute(grib_action* a, grib_handle* h) { - grib_action_set_missing* self = (grib_action_set_missing*)a; - + const grib_action_set_missing* self = (grib_action_set_missing*)a; return grib_set_missing(h, self->name); } static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_set_missing* self = (grib_action_set_missing*)act; + int i = 0; + const grib_action_set_missing* self = (grib_action_set_missing*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); From bbc8d4790ee1e3bb867fcbd483274683f2c6a5de Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 14:35:19 +0000 Subject: [PATCH 022/156] Const correctness --- src/action_class_concept.cc | 6 +++--- src/action_class_set_sarray.cc | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/action_class_concept.cc b/src/action_class_concept.cc index 74fb25588..3f42fb9e5 100644 --- a/src/action_class_concept.cc +++ b/src/action_class_concept.cc @@ -128,7 +128,7 @@ grib_concept_value* action_concept_get_concept(grib_accessor* a) int action_concept_get_nofail(grib_accessor* a) { - grib_action_concept* self = (grib_action_concept*)a->creator; + const grib_action_concept* self = (grib_action_concept*)a->creator; return self->nofail; } @@ -397,9 +397,9 @@ int get_concept_condition_string(grib_handle* h, const char* key, const char* va grib_concept_condition* concept_condition = concept_value->conditions; if (strcmp(pValue, concept_value->name) == 0) { while (concept_condition) { - grib_expression* expression = concept_condition->expression; + //grib_expression* expression = concept_condition->expression; const char* condition_name = concept_condition->name; - Assert(expression); + //Assert(expression); if (concept_condition_expression_true(h, concept_condition, exprVal) && strcmp(condition_name, "one") != 0) { length += snprintf(result + length, 2048, "%s%s=%s", (length == 0 ? "" : ","), condition_name, exprVal); diff --git a/src/action_class_set_sarray.cc b/src/action_class_set_sarray.cc index 3b670aa87..bc51c2475 100644 --- a/src/action_class_set_sarray.cc +++ b/src/action_class_set_sarray.cc @@ -72,9 +72,7 @@ static void init_class(grib_action_class* c) } /* END_CLASS_IMP */ -grib_action* grib_action_create_set_sarray(grib_context* context, - const char* name, - grib_sarray* sarray) +grib_action* grib_action_create_set_sarray(grib_context* context, const char* name, grib_sarray* sarray) { char buf[1024]; @@ -100,14 +98,13 @@ grib_action* grib_action_create_set_sarray(grib_context* context, static int execute(grib_action* a, grib_handle* h) { grib_action_set_sarray* self = (grib_action_set_sarray*)a; - return grib_set_string_array(h, self->name, (const char**)self->sarray->v, self->sarray->n); } static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_set_sarray* self = (grib_action_set_sarray*)act; + int i = 0; + const grib_action_set_sarray* self = (grib_action_set_sarray*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); From 64f3b3c7dfe29b1e3024d47691893256defeefee Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 18 Feb 2024 15:39:32 +0000 Subject: [PATCH 023/156] Testing: JPEG and lib version tests --- tests/grib2_version.sh | 19 +++++++++++++++++-- tests/grib_jpeg.sh | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/grib2_version.sh b/tests/grib2_version.sh index 1f7cbe8b5..6e6daef42 100755 --- a/tests/grib2_version.sh +++ b/tests/grib2_version.sh @@ -17,6 +17,8 @@ if [ ! -d "$ECCODES_DEFINITION_PATH" ]; then fi temp=temp.$label.grib2 +tempFilt=temp.$label.filt +tempText=temp.$label.txt sample1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl tables_dir="$ECCODES_DEFINITION_PATH/grib2/tables" @@ -34,7 +36,6 @@ fi cd $test_dir # Check table 1.0 # Check it has the latest with description matching "Version implemented on DD MM YYYY" -tempText=temp.$label.txt ${tools_dir}/grib_set -s tablesVersion=$latest $sample2 $temp ${tools_dir}/grib_dump -O -p tablesVersion $temp > $tempText grep -q "Version implemented on" $tempText @@ -50,4 +51,18 @@ if [ "$tablesVersion" != "$latestOfficial" ]; then exit 1 fi -rm -f $temp +# Library and definitions versions +cat >$tempFilt< $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +cat $tempText +grep -q "Definition files version .* is greater than engine version" $tempText + +rm -f $tempFilt $temp $tempText diff --git a/tests/grib_jpeg.sh b/tests/grib_jpeg.sh index 69210430e..43575651c 100755 --- a/tests/grib_jpeg.sh +++ b/tests/grib_jpeg.sh @@ -164,6 +164,14 @@ if [ $HAVE_LIBJASPER -eq 0 ]; then set -e [ $status -ne 0 ] grep -q "JasPer JPEG support not enabled" $tempDump + + infile=$data_dir/sample.grib2 + set +e + ECCODES_GRIB_JPEG=jasper ${tools_dir}/grib_set -rs packingType=grid_jpeg $infile $outfile1 > $tempDump 2>&1 + status=$? + set -e + [ $status -ne 0 ] + grep -q "JasPer JPEG support not enabled" $tempDump fi # Clean up From b0f949187c6fa95e3a409c34e24aede81878b238 Mon Sep 17 00:00:00 2001 From: Sebastien Villaume Date: Mon, 19 Feb 2024 10:48:31 +0000 Subject: [PATCH 024/156] move block for stepRange in mmsf/fc to top of grib.mmsf.fc.def --- definitions/mars/grib.mmsf.fc.def | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/definitions/mars/grib.mmsf.fc.def b/definitions/mars/grib.mmsf.fc.def index 7adb27059..f1820336a 100644 --- a/definitions/mars/grib.mmsf.fc.def +++ b/definitions/mars/grib.mmsf.fc.def @@ -1,4 +1,9 @@ -alias mars.step = endStep; +if (levtype is "o2d" || levtype is "o3d") { + alias mars.step = stepRange; +} else { + 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; } @@ -18,8 +23,3 @@ if (centre == 80 && subCentre == 98 && class is "c3") { if (class is "ci") { unalias mars.method; } -if (levtype is "o2d" || levtype is "o3d") { - alias mars.step = stepRange; -} else { - alias mars.step = endStep; -} From 0dc3c273cc5065c6d6980cb610b7e40649aa9c09 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 11:26:59 +0000 Subject: [PATCH 025/156] ECC-1768: GRIB2: Issue with setting PDTN 8, stepUnits and step at the same time (Initial try) --- src/grib_accessor_class_g2step_range.cc | 5 +++++ tests/bufr_compare.sh | 25 +++++++++++++++++++++++++ tests/grib_sub_hourly.sh | 14 ++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/grib_accessor_class_g2step_range.cc b/src/grib_accessor_class_g2step_range.cc index c39601a40..685c8a29b 100644 --- a/src/grib_accessor_class_g2step_range.cc +++ b/src/grib_accessor_class_g2step_range.cc @@ -211,6 +211,11 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; + // TODO(maee): A better solution should be found + if (h->loader) { // h->loader is set only when rebuilding or reparsing + force_step_units = 255; // See ECC-1768 + } + try { std::vector steps = parse_range(val, eccodes::Unit{force_step_units}); if (steps.size() == 0) { diff --git a/tests/bufr_compare.sh b/tests/bufr_compare.sh index 882fa3293..27f0c071b 100755 --- a/tests/bufr_compare.sh +++ b/tests/bufr_compare.sh @@ -351,6 +351,31 @@ set -e [ $status -ne 0 ] grep -q "unreadable message" $fLog +###??? +f1="aaen_55.bufr" +f2="aaen_55.bufr" +set +e +${tools_dir}/bufr_compare -H -c edition $f1 $f2 > $fLog 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "options are incompatible" $fLog + +set +e +${tools_dir}/bufr_compare -a edition $f1 $f2 > $fLog 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "a option requires -c option" $fLog + + +set +e +${tools_dir}/bufr_compare nosuchfile $f1 > $fLog 2>&1 +status=$? +set -e +[ $status -ne 0 ] + + # Clean up # ------------- diff --git a/tests/grib_sub_hourly.sh b/tests/grib_sub_hourly.sh index 75b113b7e..fdd174c28 100755 --- a/tests/grib_sub_hourly.sh +++ b/tests/grib_sub_hourly.sh @@ -520,6 +520,20 @@ cat $tempFilt ${tools_dir}/grib_filter $tempFilt $data_dir/constant_field.grib2 unset ECCODES_GRIB_HOURLY_STEPS_WITH_UNITS + +# Changing the product definition template +# ---------------------------------------- +# See ECC-1768 +${tools_dir}/grib_set -s step=62m $sample_g2 $temp +${tools_dir}/grib_set -s productDefinitionTemplateNumber=8 $temp $temp2 + +${tools_dir}/grib_set -s productDefinitionTemplateNumber=8,stepUnits=s,step=0 $sample_g2 $temp +grib_check_key_equals $temp '-p stepUnits:s,startStep,productDefinitionTemplateNumber' 's 0s 8' + +${tools_dir}/grib_set -s productDefinitionTemplateNumber=8,stepUnits=m,step=60 $sample_g2 $temp +grib_check_key_equals $temp '-p stepUnits:s,productDefinitionTemplateNumber' 'h 8' + + # Bad stepUnits set +e ${tools_dir}/grib_set -s stepUnits=190 $sample_g2 $temp > $tempText 2>&1 From fa65a96e885c748517436d957eedce96d1147a54 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 11:41:47 +0000 Subject: [PATCH 026/156] Testing: Rename --- tests/CMakeLists.txt | 6 +++--- tests/{bufr_threads_ecc-604.cc => bufr_encode_pthreads.cc} | 0 tests/{bufr_threads_ecc-604.sh => bufr_encode_pthreads.sh} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename tests/{bufr_threads_ecc-604.cc => bufr_encode_pthreads.cc} (100%) rename tests/{bufr_threads_ecc-604.sh => bufr_encode_pthreads.sh} (95%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3edb8ee1e..a944a448a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -445,7 +445,7 @@ if( HAVE_BUILD_TOOLS ) TYPE SCRIPT COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_encode_pthreads.sh ) - foreach( test grib_threads_ecc-604 grib_threads_ecc-604-encode bufr_threads_ecc-604 ) + foreach( test grib_threads_ecc-604 grib_threads_ecc-604-encode bufr_encode_pthreads ) ecbuild_add_executable( TARGET ${test} NOINSTALL SOURCES ${test}.cc @@ -455,10 +455,10 @@ if( HAVE_BUILD_TOOLS ) TYPE SCRIPT TEST_DEPENDS eccodes_download_gribs COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_threads_ecc-604.sh ) - ecbuild_add_test( TARGET eccodes_t_bufr_threads_ecc-604 + ecbuild_add_test( TARGET eccodes_t_bufr_encode_pthreads TYPE SCRIPT TEST_DEPENDS eccodes_download_bufrs - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufr_threads_ecc-604.sh ) + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufr_encode_pthreads.sh ) endif() if( NOT ECCODES_ON_WINDOWS ) diff --git a/tests/bufr_threads_ecc-604.cc b/tests/bufr_encode_pthreads.cc similarity index 100% rename from tests/bufr_threads_ecc-604.cc rename to tests/bufr_encode_pthreads.cc diff --git a/tests/bufr_threads_ecc-604.sh b/tests/bufr_encode_pthreads.sh similarity index 95% rename from tests/bufr_threads_ecc-604.sh rename to tests/bufr_encode_pthreads.sh index 7b7a886a9..b6262e76d 100755 --- a/tests/bufr_threads_ecc-604.sh +++ b/tests/bufr_encode_pthreads.sh @@ -10,13 +10,13 @@ . ./include.ctest.sh -label="bufr_threads_ecc-604" +label="bufr_encode_pthreads_test" temp_dir=tempdir.${label} NUM_THREADS=3 NUM_ITER=5 OUTPUT=output -PROG="${test_dir}/bufr_threads_ecc-604" +PROG="${test_dir}/bufr_encode_pthreads" validate() { From e938f1da0cdda177bf3c4bb6ecc17fe6dd702d23 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 12:30:36 +0000 Subject: [PATCH 027/156] Testing: Rename --- tests/CMakeLists.txt | 6 +++--- tests/{grib_threads_ecc-604.cc => grib_encode_pthreads2.cc} | 0 tests/{grib_threads_ecc-604.sh => grib_encode_pthreads2.sh} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename tests/{grib_threads_ecc-604.cc => grib_encode_pthreads2.cc} (100%) rename tests/{grib_threads_ecc-604.sh => grib_encode_pthreads2.sh} (98%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a944a448a..21640b8bb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -445,16 +445,16 @@ if( HAVE_BUILD_TOOLS ) TYPE SCRIPT COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_encode_pthreads.sh ) - foreach( test grib_threads_ecc-604 grib_threads_ecc-604-encode bufr_encode_pthreads ) + foreach( test grib_encode_pthreads2 grib_threads_ecc-604-encode bufr_encode_pthreads ) ecbuild_add_executable( TARGET ${test} NOINSTALL SOURCES ${test}.cc LIBS eccodes ${CMAKE_THREAD_LIBS_INIT} ) endforeach() - ecbuild_add_test( TARGET eccodes_t_grib_threads_ecc-604 + ecbuild_add_test( TARGET eccodes_t_grib_encode_pthreads2 TYPE SCRIPT TEST_DEPENDS eccodes_download_gribs - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_threads_ecc-604.sh ) + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/grib_encode_pthreads2.sh ) ecbuild_add_test( TARGET eccodes_t_bufr_encode_pthreads TYPE SCRIPT TEST_DEPENDS eccodes_download_bufrs diff --git a/tests/grib_threads_ecc-604.cc b/tests/grib_encode_pthreads2.cc similarity index 100% rename from tests/grib_threads_ecc-604.cc rename to tests/grib_encode_pthreads2.cc diff --git a/tests/grib_threads_ecc-604.sh b/tests/grib_encode_pthreads2.sh similarity index 98% rename from tests/grib_threads_ecc-604.sh rename to tests/grib_encode_pthreads2.sh index c2d491ffb..56d894013 100755 --- a/tests/grib_threads_ecc-604.sh +++ b/tests/grib_encode_pthreads2.sh @@ -16,7 +16,7 @@ temp_dir=tempdir.${label} NUM_THREADS=3 NUM_ITER=10 OUTPUT=output -PROG="${test_dir}/grib_threads_ecc-604" +PROG="${test_dir}/grib_encode_pthreads2" validate() { From 1e24c813f56e9b0a8cb43e413a611041bf5ef5d6 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 12:37:48 +0000 Subject: [PATCH 028/156] Definitions: Formatting --- definitions/boot.def | 2 +- definitions/grib2/boot.def | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/definitions/boot.def b/definitions/boot.def index 8111e1634..bb8991382 100644 --- a/definitions/boot.def +++ b/definitions/boot.def @@ -84,7 +84,7 @@ if(kindOfProduct == `TIDE`){ if(kindOfProduct == `BUFR`){ template BUFR "bufr/boot.def" ; - #constant BUFRstr="BUFR"; #ECC-742 + #constant BUFRstr="BUFR"; #ECC-742 #alias identifier=BUFRstr; } diff --git a/definitions/grib2/boot.def b/definitions/grib2/boot.def index 61f3c000d..4ed94b503 100644 --- a/definitions/grib2/boot.def +++ b/definitions/grib2/boot.def @@ -16,9 +16,9 @@ constant tablesVersionLatest = 32 : edition_specific; constant false = 0 : hidden; constant true = 1 : hidden; constant million = 1000000 : hidden; -constant grib2divider = 1000000; -alias extraDimensionPresent=zero; -transient angleSubdivisions=grib2divider; # micro degrees +constant grib2divider = 1000000; +alias extraDimensionPresent = zero; +transient angleSubdivisions = grib2divider; # micro degrees transient forceStepUnits = 255 : hidden; meta gts_header gts_header() : no_copy,hidden,read_only; @@ -26,8 +26,8 @@ meta gts_TTAAii gts_header(20,6) : no_copy,hidden,read_only; meta gts_CCCC gts_header(27,4) : no_copy,hidden,read_only; meta gts_ddhh00 gts_header(32,6) : no_copy,hidden,read_only; -transient missingValue = 9999; -constant ieeeFloats = 1 : edition_specific; +transient missingValue = 9999; +constant ieeeFloats = 1 : edition_specific; constant isHindcast = 0; include "grib2/section.0.def" From d9dacdd3d7dbfdce21a30f063d73a540d27b7aac Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 13:34:02 +0000 Subject: [PATCH 029/156] Accessors: Do not assert on error --- definitions/grib2/template.4.optical.def | 6 +- src/CMakeLists.txt | 1 + src/grib_accessor_class.h | 1 + src/grib_accessor_class_divdouble.cc | 18 +-- src/grib_accessor_class_multdouble.cc | 133 +++++++++++++++++++ src/grib_accessor_classes_hash.cc | 157 ++++++++++++----------- src/grib_accessor_factory.h | 1 + src/grib_accessor_factory_hash_list | 1 + 8 files changed, 226 insertions(+), 92 deletions(-) create mode 100644 src/grib_accessor_class_multdouble.cc diff --git a/definitions/grib2/template.4.optical.def b/definitions/grib2/template.4.optical.def index a73181f89..385513edc 100644 --- a/definitions/grib2/template.4.optical.def +++ b/definitions/grib2/template.4.optical.def @@ -14,6 +14,6 @@ meta secondWavelength from_scale_factor_scaled_value(scaleFactorOfSecondWaveleng alias firstWavelengthInMetres = firstWavelength; alias secondWavelengthInMetres = secondWavelength; -constant oneBillionth = 1.0 / 1000000000 : hidden; -meta firstWavelengthInNanometres divdouble(firstWavelength, oneBillionth); -meta secondWavelengthInNanometres divdouble(secondWavelength, oneBillionth); +constant billion = 1000000000 : hidden; +meta firstWavelengthInNanometres multdouble(firstWavelength, billion); +meta secondWavelengthInNanometres multdouble(secondWavelength, billion); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f040434b7..97cd81dfc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,6 +80,7 @@ list( APPEND eccodes_src_files grib_accessor_class_hash_array.cc grib_accessor_class_decimal_precision.cc grib_accessor_class_divdouble.cc + grib_accessor_class_multdouble.cc grib_accessor_class_budgdate.cc grib_accessor_class_validity_date.cc grib_accessor_class_validity_time.cc diff --git a/src/grib_accessor_class.h b/src/grib_accessor_class.h index 8352a8d27..0c569decd 100644 --- a/src/grib_accessor_class.h +++ b/src/grib_accessor_class.h @@ -131,6 +131,7 @@ extern grib_accessor_class* grib_accessor_class_mars_step; extern grib_accessor_class* grib_accessor_class_md5; extern grib_accessor_class* grib_accessor_class_message; extern grib_accessor_class* grib_accessor_class_message_copy; +extern grib_accessor_class* grib_accessor_class_multdouble; extern grib_accessor_class* grib_accessor_class_nearest; extern grib_accessor_class* grib_accessor_class_non_alpha; extern grib_accessor_class* grib_accessor_class_number_of_coded_values; diff --git a/src/grib_accessor_class_divdouble.cc b/src/grib_accessor_class_divdouble.cc index e4e5442ef..f9586e9d7 100644 --- a/src/grib_accessor_class_divdouble.cc +++ b/src/grib_accessor_class_divdouble.cc @@ -7,11 +7,6 @@ * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ - -/***************************************** - * Enrico Fucile - ****************************************/ - #include "grib_api_internal.h" /* This is used by make_class.pl @@ -108,7 +103,7 @@ grib_accessor_class* grib_accessor_class_divdouble = &_grib_accessor_class_divdo static void init(grib_accessor* a, const long l, grib_arguments* c) { grib_accessor_divdouble* self = (grib_accessor_divdouble*)a; - int n = 0; + int n = 0; self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->divisor = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); @@ -116,9 +111,9 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) static int unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_divdouble* self = (grib_accessor_divdouble*)a; - int ret = GRIB_SUCCESS; - double value = 0; + const grib_accessor_divdouble* self = (grib_accessor_divdouble*)a; + int ret = GRIB_SUCCESS; + double value = 0; if (*len < 1) { *len = 1; @@ -130,8 +125,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (ret != GRIB_SUCCESS) return ret; - /* fprintf(stdout,"\nname %s %s %g/%g\n",a->name ,self->val,value,divisor);*/ - Assert(self->divisor != 0); + if (self->divisor == 0) { + return GRIB_INVALID_ARGUMENT; + } *val = value / self->divisor; *len = 1; diff --git a/src/grib_accessor_class_multdouble.cc b/src/grib_accessor_class_multdouble.cc new file mode 100644 index 000000000..920b48f53 --- /dev/null +++ b/src/grib_accessor_class_multdouble.cc @@ -0,0 +1,133 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +#include "grib_api_internal.h" +/* + This is used by make_class.pl + + START_CLASS_DEF + CLASS = accessor + SUPER = grib_accessor_class_double + IMPLEMENTS = unpack_double + IMPLEMENTS = init + MEMBERS = const char* val + MEMBERS = double multiplier + END_CLASS_DEF + + */ + +/* START_CLASS_IMP */ + +/* + +Don't edit anything between START_CLASS_IMP and END_CLASS_IMP +Instead edit values between START_CLASS_DEF and END_CLASS_DEF +or edit "accessor.class" and rerun ./make_class.pl + +*/ + +static int unpack_double(grib_accessor*, double* val, size_t* len); +static void init(grib_accessor*, const long, grib_arguments*); + +typedef struct grib_accessor_multdouble +{ + grib_accessor att; + /* Members defined in gen */ + /* Members defined in double */ + /* Members defined in multdouble */ + const char* val; + double multiplier; +} grib_accessor_multdouble; + +extern grib_accessor_class* grib_accessor_class_double; + +static grib_accessor_class _grib_accessor_class_multdouble = { + &grib_accessor_class_double, /* super */ + "multdouble", /* name */ + sizeof(grib_accessor_multdouble), /* size */ + 0, /* inited */ + 0, /* init_class */ + &init, /* init */ + 0, /* post_init */ + 0, /* destroy */ + 0, /* dump */ + 0, /* next_offset */ + 0, /* get length of string */ + 0, /* get number of values */ + 0, /* get number of bytes */ + 0, /* get offset to bytes */ + 0, /* get native type */ + 0, /* get sub_section */ + 0, /* pack_missing */ + 0, /* is_missing */ + 0, /* pack_long */ + 0, /* unpack_long */ + 0, /* pack_double */ + 0, /* pack_float */ + &unpack_double, /* unpack_double */ + 0, /* unpack_float */ + 0, /* pack_string */ + 0, /* unpack_string */ + 0, /* pack_string_array */ + 0, /* unpack_string_array */ + 0, /* pack_bytes */ + 0, /* unpack_bytes */ + 0, /* pack_expression */ + 0, /* notify_change */ + 0, /* update_size */ + 0, /* preferred_size */ + 0, /* resize */ + 0, /* nearest_smaller_value */ + 0, /* next accessor */ + 0, /* compare vs. another accessor */ + 0, /* unpack only ith value (double) */ + 0, /* unpack only ith value (float) */ + 0, /* unpack a given set of elements (double) */ + 0, /* unpack a given set of elements (float) */ + 0, /* unpack a subarray */ + 0, /* clear */ + 0, /* clone accessor */ +}; + + +grib_accessor_class* grib_accessor_class_multdouble = &_grib_accessor_class_multdouble; + +/* END_CLASS_IMP */ + +static void init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; + int n = 0; + + self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->multiplier = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); +} + +static int unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; + int ret = GRIB_SUCCESS; + double value = 0; + + if (*len < 1) { + *len = 1; + return GRIB_ARRAY_TOO_SMALL; + } + + ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); + + if (ret != GRIB_SUCCESS) + return ret; + + *val = value * self->multiplier; + + *len = 1; + return GRIB_SUCCESS; +} diff --git a/src/grib_accessor_classes_hash.cc b/src/grib_accessor_classes_hash.cc index cb9a8b437..2643a32fb 100644 --- a/src/grib_accessor_classes_hash.cc +++ b/src/grib_accessor_classes_hash.cc @@ -37,7 +37,7 @@ #line 6 "accessor_class_list.gperf" struct accessor_class_hash { char *name; grib_accessor_class **cclass;}; -#define TOTAL_KEYWORDS 204 +#define TOTAL_KEYWORDS 205 #define MIN_WORD_LENGTH 1 #define MAX_WORD_LENGTH 44 #define MIN_HASH_VALUE 1 @@ -117,21 +117,21 @@ static const struct accessor_class_hash classes[] = #line 9 "accessor_class_list.gperf" {" "}, {""}, {""}, {""}, {""}, -#line 178 "accessor_class_list.gperf" +#line 179 "accessor_class_list.gperf" {"size", &grib_accessor_class_size}, #line 12 "accessor_class_list.gperf" {"ascii", &grib_accessor_class_ascii}, -#line 175 "accessor_class_list.gperf" +#line 176 "accessor_class_list.gperf" {"signed", &grib_accessor_class_signed}, -#line 155 "accessor_class_list.gperf" +#line 156 "accessor_class_list.gperf" {"pad", &grib_accessor_class_pad}, -#line 181 "accessor_class_list.gperf" +#line 182 "accessor_class_list.gperf" {"spd", &grib_accessor_class_spd}, {""}, #line 75 "accessor_class_list.gperf" {"dirty", &grib_accessor_class_dirty}, {""}, -#line 176 "accessor_class_list.gperf" +#line 177 "accessor_class_list.gperf" {"signed_bits", &grib_accessor_class_signed_bits}, {""}, #line 66 "accessor_class_list.gperf" @@ -141,7 +141,7 @@ static const struct accessor_class_hash classes[] = {"data_simple_packing", &grib_accessor_class_data_simple_packing}, #line 68 "accessor_class_list.gperf" {"data_secondary_bitmap", &grib_accessor_class_data_secondary_bitmap}, -#line 169 "accessor_class_list.gperf" +#line 170 "accessor_class_list.gperf" {"section", &grib_accessor_class_section}, #line 43 "accessor_class_list.gperf" {"data_apply_bitmap", &grib_accessor_class_data_apply_bitmap}, @@ -155,36 +155,36 @@ static const struct accessor_class_hash classes[] = {"data_jpeg2000_packing", &grib_accessor_class_data_jpeg2000_packing}, #line 65 "accessor_class_list.gperf" {"data_png_packing", &grib_accessor_class_data_png_packing}, -#line 171 "accessor_class_list.gperf" - {"section_padding", &grib_accessor_class_section_padding}, #line 172 "accessor_class_list.gperf" + {"section_padding", &grib_accessor_class_section_padding}, +#line 173 "accessor_class_list.gperf" {"section_pointer", &grib_accessor_class_section_pointer}, #line 44 "accessor_class_list.gperf" {"data_apply_boustrophedonic", &grib_accessor_class_data_apply_boustrophedonic}, {""}, {""}, {""}, {""}, #line 80 "accessor_class_list.gperf" {"expanded_descriptors", &grib_accessor_class_expanded_descriptors}, -#line 156 "accessor_class_list.gperf" +#line 157 "accessor_class_list.gperf" {"padding", &grib_accessor_class_padding}, #line 45 "accessor_class_list.gperf" {"data_apply_boustrophedonic_bitmap", &grib_accessor_class_data_apply_boustrophedonic_bitmap}, #line 110 "accessor_class_list.gperf" {"gds_is_present", &grib_accessor_class_gds_is_present}, -#line 168 "accessor_class_list.gperf" +#line 169 "accessor_class_list.gperf" {"second_order_bits_per_value", &grib_accessor_class_second_order_bits_per_value}, -#line 170 "accessor_class_list.gperf" +#line 171 "accessor_class_list.gperf" {"section_length", &grib_accessor_class_section_length}, #line 113 "accessor_class_list.gperf" {"getenv", &grib_accessor_class_getenv}, #line 57 "accessor_class_list.gperf" {"data_g22order_packing", &grib_accessor_class_data_g22order_packing}, -#line 190 "accessor_class_list.gperf" +#line 191 "accessor_class_list.gperf" {"time", &grib_accessor_class_time}, {""}, #line 61 "accessor_class_list.gperf" {"data_g2shsimple_packing", &grib_accessor_class_data_g2shsimple_packing}, {""}, -#line 154 "accessor_class_list.gperf" +#line 155 "accessor_class_list.gperf" {"packing_type", &grib_accessor_class_packing_type}, #line 62 "accessor_class_list.gperf" {"data_g2simple_packing", &grib_accessor_class_data_g2simple_packing}, @@ -198,28 +198,28 @@ static const struct accessor_class_hash classes[] = {"g2end_step", &grib_accessor_class_g2end_step}, #line 98 "accessor_class_list.gperf" {"g2_eps", &grib_accessor_class_g2_eps}, -#line 141 "accessor_class_list.gperf" +#line 142 "accessor_class_list.gperf" {"nearest", &grib_accessor_class_nearest}, {""}, -#line 157 "accessor_class_list.gperf" +#line 158 "accessor_class_list.gperf" {"padto", &grib_accessor_class_padto}, -#line 188 "accessor_class_list.gperf" +#line 189 "accessor_class_list.gperf" {"sum", &grib_accessor_class_sum}, {""}, #line 107 "accessor_class_list.gperf" {"g2lon", &grib_accessor_class_g2lon}, -#line 202 "accessor_class_list.gperf" +#line 203 "accessor_class_list.gperf" {"uint8", &grib_accessor_class_uint8}, {""}, -#line 187 "accessor_class_list.gperf" +#line 188 "accessor_class_list.gperf" {"step_in_units", &grib_accessor_class_step_in_units}, #line 63 "accessor_class_list.gperf" {"data_g2simple_packing_with_preprocessing", &grib_accessor_class_data_g2simple_packing_with_preprocessing}, -#line 200 "accessor_class_list.gperf" +#line 201 "accessor_class_list.gperf" {"uint64", &grib_accessor_class_uint64}, #line 47 "accessor_class_list.gperf" {"data_complex_packing", &grib_accessor_class_data_complex_packing}, -#line 198 "accessor_class_list.gperf" +#line 199 "accessor_class_list.gperf" {"uint32", &grib_accessor_class_uint32}, #line 13 "accessor_class_list.gperf" {"bit", &grib_accessor_class_bit}, @@ -233,7 +233,7 @@ static const struct accessor_class_hash classes[] = {"julian_day", &grib_accessor_class_julian_day}, #line 123 "accessor_class_list.gperf" {"julian_date", &grib_accessor_class_julian_date}, -#line 142 "accessor_class_list.gperf" +#line 143 "accessor_class_list.gperf" {"non_alpha", &grib_accessor_class_non_alpha}, {""}, #line 29 "accessor_class_list.gperf" @@ -245,14 +245,14 @@ static const struct accessor_class_hash classes[] = #line 16 "accessor_class_list.gperf" {"bits_per_value", &grib_accessor_class_bits_per_value}, {""}, {""}, {""}, {""}, {""}, -#line 166 "accessor_class_list.gperf" +#line 167 "accessor_class_list.gperf" {"scale", &grib_accessor_class_scale}, {""}, -#line 184 "accessor_class_list.gperf" +#line 185 "accessor_class_list.gperf" {"statistics", &grib_accessor_class_statistics}, #line 102 "accessor_class_list.gperf" {"g2date", &grib_accessor_class_g2date}, -#line 144 "accessor_class_list.gperf" +#line 145 "accessor_class_list.gperf" {"number_of_points", &grib_accessor_class_number_of_points}, #line 100 "accessor_class_list.gperf" {"g2bitmap", &grib_accessor_class_g2bitmap}, @@ -265,13 +265,13 @@ static const struct accessor_class_hash classes[] = {"gds_not_present_bitmap", &grib_accessor_class_gds_not_present_bitmap}, #line 122 "accessor_class_list.gperf" {"iterator", &grib_accessor_class_iterator}, -#line 185 "accessor_class_list.gperf" +#line 186 "accessor_class_list.gperf" {"statistics_spectral", &grib_accessor_class_statistics_spectral}, #line 46 "accessor_class_list.gperf" {"data_ccsds_packing", &grib_accessor_class_data_ccsds_packing}, -#line 145 "accessor_class_list.gperf" +#line 146 "accessor_class_list.gperf" {"number_of_points_gaussian", &grib_accessor_class_number_of_points_gaussian}, -#line 205 "accessor_class_list.gperf" +#line 206 "accessor_class_list.gperf" {"unsigned", &grib_accessor_class_unsigned}, #line 138 "accessor_class_list.gperf" {"md5", &grib_accessor_class_md5}, @@ -280,30 +280,30 @@ static const struct accessor_class_hash classes[] = {"g2_aerosol", &grib_accessor_class_g2_aerosol}, #line 139 "accessor_class_list.gperf" {"message", &grib_accessor_class_message}, -#line 206 "accessor_class_list.gperf" +#line 207 "accessor_class_list.gperf" {"unsigned_bits", &grib_accessor_class_unsigned_bits}, -#line 173 "accessor_class_list.gperf" +#line 174 "accessor_class_list.gperf" {"select_step_template", &grib_accessor_class_select_step_template}, #line 136 "accessor_class_list.gperf" {"mars_param", &grib_accessor_class_mars_param}, -#line 203 "accessor_class_list.gperf" +#line 204 "accessor_class_list.gperf" {"unexpanded_descriptors", &grib_accessor_class_unexpanded_descriptors}, -#line 192 "accessor_class_list.gperf" +#line 193 "accessor_class_list.gperf" {"to_integer", &grib_accessor_class_to_integer}, {""}, {""}, {""}, -#line 177 "accessor_class_list.gperf" +#line 178 "accessor_class_list.gperf" {"simple_packing_error", &grib_accessor_class_simple_packing_error}, -#line 186 "accessor_class_list.gperf" +#line 187 "accessor_class_list.gperf" {"step_human_readable", &grib_accessor_class_step_human_readable}, #line 140 "accessor_class_list.gperf" {"message_copy", &grib_accessor_class_message_copy}, -#line 162 "accessor_class_list.gperf" +#line 163 "accessor_class_list.gperf" {"raw", &grib_accessor_class_raw}, {""}, {""}, -#line 201 "accessor_class_list.gperf" +#line 202 "accessor_class_list.gperf" {"uint64_little_endian", &grib_accessor_class_uint64_little_endian}, {""}, -#line 199 "accessor_class_list.gperf" +#line 200 "accessor_class_list.gperf" {"uint32_little_endian", &grib_accessor_class_uint32_little_endian}, #line 114 "accessor_class_list.gperf" {"global_gaussian", &grib_accessor_class_global_gaussian}, @@ -311,20 +311,20 @@ static const struct accessor_class_hash classes[] = #line 76 "accessor_class_list.gperf" {"divdouble", &grib_accessor_class_divdouble}, {""}, -#line 174 "accessor_class_list.gperf" +#line 175 "accessor_class_list.gperf" {"sexagesimal2decimal", &grib_accessor_class_sexagesimal2decimal}, #line 99 "accessor_class_list.gperf" {"g2_mars_labeling", &grib_accessor_class_g2_mars_labeling}, #line 78 "accessor_class_list.gperf" {"element", &grib_accessor_class_element}, -#line 159 "accessor_class_list.gperf" +#line 160 "accessor_class_list.gperf" {"padtomultiple", &grib_accessor_class_padtomultiple}, #line 127 "accessor_class_list.gperf" {"latitudes", &grib_accessor_class_latitudes}, -#line 163 "accessor_class_list.gperf" +#line 164 "accessor_class_list.gperf" {"rdbtime_guess_date", &grib_accessor_class_rdbtime_guess_date}, {""}, {""}, {""}, -#line 193 "accessor_class_list.gperf" +#line 194 "accessor_class_list.gperf" {"to_string", &grib_accessor_class_to_string}, #line 132 "accessor_class_list.gperf" {"long", &grib_accessor_class_long}, @@ -348,20 +348,20 @@ static const struct accessor_class_hash classes[] = {""}, #line 28 "accessor_class_list.gperf" {"bufrdc_expanded_descriptors", &grib_accessor_class_bufrdc_expanded_descriptors}, -#line 160 "accessor_class_list.gperf" +#line 161 "accessor_class_list.gperf" {"position", &grib_accessor_class_position}, {""}, {""}, {""}, #line 17 "accessor_class_list.gperf" {"blob", &grib_accessor_class_blob}, #line 109 "accessor_class_list.gperf" {"gaussian_grid_name", &grib_accessor_class_gaussian_grid_name}, -#line 196 "accessor_class_list.gperf" +#line 197 "accessor_class_list.gperf" {"trim", &grib_accessor_class_trim}, {""}, {""}, #line 119 "accessor_class_list.gperf" {"ibmfloat", &grib_accessor_class_ibmfloat}, {""}, {""}, -#line 194 "accessor_class_list.gperf" +#line 195 "accessor_class_list.gperf" {"transient", &grib_accessor_class_transient}, #line 55 "accessor_class_list.gperf" {"data_g1shsimple_packing", &grib_accessor_class_data_g1shsimple_packing}, @@ -370,15 +370,15 @@ static const struct accessor_class_hash classes[] = {"data_g1simple_packing", &grib_accessor_class_data_g1simple_packing}, #line 49 "accessor_class_list.gperf" {"data_g1complex_packing", &grib_accessor_class_data_g1complex_packing}, -#line 165 "accessor_class_list.gperf" +#line 166 "accessor_class_list.gperf" {"round", &grib_accessor_class_round}, -#line 195 "accessor_class_list.gperf" +#line 196 "accessor_class_list.gperf" {"transient_darray", &grib_accessor_class_transient_darray}, #line 18 "accessor_class_list.gperf" {"budgdate", &grib_accessor_class_budgdate}, -#line 209 "accessor_class_list.gperf" +#line 210 "accessor_class_list.gperf" {"values", &grib_accessor_class_values}, -#line 143 "accessor_class_list.gperf" +#line 144 "accessor_class_list.gperf" {"number_of_coded_values", &grib_accessor_class_number_of_coded_values}, #line 126 "accessor_class_list.gperf" {"label", &grib_accessor_class_label}, @@ -386,30 +386,30 @@ static const struct accessor_class_hash classes[] = #line 38 "accessor_class_list.gperf" {"concept", &grib_accessor_class_concept}, {""}, -#line 182 "accessor_class_list.gperf" +#line 183 "accessor_class_list.gperf" {"spectral_truncation", &grib_accessor_class_spectral_truncation}, {""}, {""}, #line 83 "accessor_class_list.gperf" {"g1_message_length", &grib_accessor_class_g1_message_length}, -#line 183 "accessor_class_list.gperf" +#line 184 "accessor_class_list.gperf" {"sprintf", &grib_accessor_class_sprintf}, -#line 189 "accessor_class_list.gperf" +#line 190 "accessor_class_list.gperf" {"suppressed", &grib_accessor_class_suppressed}, {""}, -#line 212 "accessor_class_list.gperf" +#line 213 "accessor_class_list.gperf" {"when", &grib_accessor_class_when}, {""}, {""}, -#line 179 "accessor_class_list.gperf" +#line 180 "accessor_class_list.gperf" {"smart_table", &grib_accessor_class_smart_table}, {""}, #line 39 "accessor_class_list.gperf" {"constant", &grib_accessor_class_constant}, {""}, {""}, -#line 161 "accessor_class_list.gperf" +#line 162 "accessor_class_list.gperf" {"proj_string", &grib_accessor_class_proj_string}, -#line 149 "accessor_class_list.gperf" +#line 150 "accessor_class_list.gperf" {"octet_number", &grib_accessor_class_octet_number}, -#line 180 "accessor_class_list.gperf" +#line 181 "accessor_class_list.gperf" {"smart_table_column", &grib_accessor_class_smart_table_column}, {""}, #line 135 "accessor_class_list.gperf" @@ -426,7 +426,7 @@ static const struct accessor_class_hash classes[] = {"data_sh_unpacked", &grib_accessor_class_data_sh_unpacked}, #line 27 "accessor_class_list.gperf" {"bufr_string_values", &grib_accessor_class_bufr_string_values}, -#line 197 "accessor_class_list.gperf" +#line 198 "accessor_class_list.gperf" {"uint16", &grib_accessor_class_uint16}, {""}, {""}, #line 71 "accessor_class_list.gperf" @@ -439,26 +439,27 @@ static const struct accessor_class_hash classes[] = {""}, #line 54 "accessor_class_list.gperf" {"data_g1secondary_bitmap", &grib_accessor_class_data_g1secondary_bitmap}, -#line 191 "accessor_class_list.gperf" +#line 192 "accessor_class_list.gperf" {"to_double", &grib_accessor_class_to_double}, #line 101 "accessor_class_list.gperf" {"g2bitmap_present", &grib_accessor_class_g2bitmap_present}, #line 120 "accessor_class_list.gperf" {"ieeefloat", &grib_accessor_class_ieeefloat}, -#line 150 "accessor_class_list.gperf" +#line 151 "accessor_class_list.gperf" {"offset_file", &grib_accessor_class_offset_file}, -#line 207 "accessor_class_list.gperf" - {"validity_date", &grib_accessor_class_validity_date}, #line 208 "accessor_class_list.gperf" + {"validity_date", &grib_accessor_class_validity_date}, +#line 209 "accessor_class_list.gperf" {"validity_time", &grib_accessor_class_validity_time}, {""}, #line 130 "accessor_class_list.gperf" {"library_version", &grib_accessor_class_library_version}, -#line 211 "accessor_class_list.gperf" +#line 212 "accessor_class_list.gperf" {"vector", &grib_accessor_class_vector}, #line 84 "accessor_class_list.gperf" {"g1_section4_length", &grib_accessor_class_g1_section4_length}, - {""}, +#line 141 "accessor_class_list.gperf" + {"multdouble", &grib_accessor_class_multdouble}, #line 52 "accessor_class_list.gperf" {"data_g1second_order_general_packing", &grib_accessor_class_data_g1second_order_general_packing}, {""}, {""}, @@ -467,7 +468,7 @@ static const struct accessor_class_hash classes[] = {""}, #line 24 "accessor_class_list.gperf" {"bufr_extract_subsets", &grib_accessor_class_bufr_extract_subsets}, -#line 158 "accessor_class_list.gperf" +#line 159 "accessor_class_list.gperf" {"padtoeven", &grib_accessor_class_padtoeven}, #line 50 "accessor_class_list.gperf" {"data_g1second_order_constant_width_packing", &grib_accessor_class_data_g1second_order_constant_width_packing}, @@ -483,7 +484,7 @@ static const struct accessor_class_hash classes[] = #line 21 "accessor_class_list.gperf" {"bufr_elements_table", &grib_accessor_class_bufr_elements_table}, {""}, {""}, {""}, {""}, -#line 153 "accessor_class_list.gperf" +#line 154 "accessor_class_list.gperf" {"pack_bufr_values", &grib_accessor_class_pack_bufr_values}, #line 35 "accessor_class_list.gperf" {"codetable", &grib_accessor_class_codetable}, @@ -495,7 +496,7 @@ static const struct accessor_class_hash classes[] = {""}, #line 88 "accessor_class_list.gperf" {"g1end_of_interval_monthly", &grib_accessor_class_g1end_of_interval_monthly}, -#line 146 "accessor_class_list.gperf" +#line 147 "accessor_class_list.gperf" {"number_of_values", &grib_accessor_class_number_of_values}, {""}, #line 116 "accessor_class_list.gperf" @@ -503,26 +504,26 @@ static const struct accessor_class_hash classes[] = {""}, #line 33 "accessor_class_list.gperf" {"closest_date", &grib_accessor_class_closest_date}, -#line 152 "accessor_class_list.gperf" +#line 153 "accessor_class_list.gperf" {"optimal_step_units", &grib_accessor_class_optimal_step_units}, {""}, -#line 210 "accessor_class_list.gperf" +#line 211 "accessor_class_list.gperf" {"variable", &grib_accessor_class_variable}, #line 133 "accessor_class_list.gperf" {"long_vector", &grib_accessor_class_long_vector}, -#line 167 "accessor_class_list.gperf" +#line 168 "accessor_class_list.gperf" {"scale_values", &grib_accessor_class_scale_values}, {""}, {""}, {""}, #line 128 "accessor_class_list.gperf" {"latlon_increment", &grib_accessor_class_latlon_increment}, {""}, {""}, {""}, -#line 147 "accessor_class_list.gperf" +#line 148 "accessor_class_list.gperf" {"number_of_values_data_raw_packing", &grib_accessor_class_number_of_values_data_raw_packing}, {""}, #line 79 "accessor_class_list.gperf" {"evaluate", &grib_accessor_class_evaluate}, {""}, {""}, {""}, {""}, {""}, -#line 151 "accessor_class_list.gperf" +#line 152 "accessor_class_list.gperf" {"offset_values", &grib_accessor_class_offset_values}, #line 69 "accessor_class_list.gperf" {"data_sh_packed", &grib_accessor_class_data_sh_packed}, @@ -535,7 +536,7 @@ static const struct accessor_class_hash classes[] = {""}, {""}, #line 41 "accessor_class_list.gperf" {"count_missing", &grib_accessor_class_count_missing}, -#line 204 "accessor_class_list.gperf" +#line 205 "accessor_class_list.gperf" {"unpack_bufr_values", &grib_accessor_class_unpack_bufr_values}, {""}, {""}, #line 121 "accessor_class_list.gperf" @@ -569,7 +570,7 @@ static const struct accessor_class_hash classes[] = #line 31 "accessor_class_list.gperf" {"change_scanning_direction", &grib_accessor_class_change_scanning_direction}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 148 "accessor_class_list.gperf" +#line 149 "accessor_class_list.gperf" {"octahedral_gaussian", &grib_accessor_class_octahedral_gaussian}, #line 10 "accessor_class_list.gperf" {"abstract_long_vector", &grib_accessor_class_abstract_long_vector}, @@ -600,7 +601,7 @@ static const struct accessor_class_hash classes[] = #line 87 "accessor_class_list.gperf" {"g1day_of_the_year_date", &grib_accessor_class_g1day_of_the_year_date}, {""}, {""}, {""}, {""}, {""}, -#line 164 "accessor_class_list.gperf" +#line 165 "accessor_class_list.gperf" {"reference_value_error", &grib_accessor_class_reference_value_error}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, @@ -621,11 +622,11 @@ static const struct accessor_class_hash classes[] = }; static const struct accessor_class_hash* grib_accessor_classes_hash(const char *str, size_t len) -{ - unsigned int key = grib_accessor_classes_get_id (str, len); + { + unsigned int key = grib_accessor_classes_get_id (str, len); #ifdef DEBUG - { + { const char *s; Assert( len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH ); Assert( key <= MAX_HASH_VALUE ); @@ -634,5 +635,5 @@ static const struct accessor_class_hash* grib_accessor_classes_hash(const char * } #endif - return &classes[key]; + return &classes[key]; } diff --git a/src/grib_accessor_factory.h b/src/grib_accessor_factory.h index 00112e240..2f889a0c6 100644 --- a/src/grib_accessor_factory.h +++ b/src/grib_accessor_factory.h @@ -130,6 +130,7 @@ { "md5", &grib_accessor_class_md5, }, { "message", &grib_accessor_class_message, }, { "message_copy", &grib_accessor_class_message_copy, }, +{ "multdouble", &grib_accessor_class_multdouble, }, { "nearest", &grib_accessor_class_nearest, }, { "non_alpha", &grib_accessor_class_non_alpha, }, { "number_of_coded_values", &grib_accessor_class_number_of_coded_values, }, diff --git a/src/grib_accessor_factory_hash_list b/src/grib_accessor_factory_hash_list index 54627c6ad..1f7687f38 100644 --- a/src/grib_accessor_factory_hash_list +++ b/src/grib_accessor_factory_hash_list @@ -131,6 +131,7 @@ mars_step, &grib_accessor_class_mars_step md5, &grib_accessor_class_md5 message, &grib_accessor_class_message message_copy, &grib_accessor_class_message_copy +multdouble, &grib_accessor_class_multdouble nearest, &grib_accessor_class_nearest non_alpha, &grib_accessor_class_non_alpha number_of_coded_values, &grib_accessor_class_number_of_coded_values From fcd51754fc8848c97f39b0ac15b4bf273d796ee7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 13:34:38 +0000 Subject: [PATCH 030/156] Accessor: multdouble --- definitions/grib1/mars_labeling.4.def | 22 +++++++++---------- .../grib2/template.3.shape_of_the_earth.def | 6 ++--- .../grib3/template.3.shape_of_the_earth.def | 6 ++--- src/grib_accessor_class_multdouble.cc | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/definitions/grib1/mars_labeling.4.def b/definitions/grib1/mars_labeling.4.def index d75df1341..e0984d22b 100644 --- a/definitions/grib1/mars_labeling.4.def +++ b/definitions/grib1/mars_labeling.4.def @@ -89,7 +89,7 @@ if (horizontalCoordinateDefinition == 0) { { meta coordinateIndexNumber evaluate(coordinate4Flag+coordinate3Flag); -# levelist latitude longitude + # levelist latitude longitude if (coordinateIndexNumber== 3) { meta marsLatitude divdouble( coordinate1Start,1000000); meta marsLongitude divdouble( coordinate2Start,1000000); @@ -145,15 +145,15 @@ if (horizontalCoordinateDefinition == 0) { alias mars.range = marsRange; } } -# product - alias mars.product = coordAveragingTims; -# date - if (marsType == TYPE_OR && averaging1Flag == P_INST) { - #remove mars.date; - alias mars.date = verificationDate; - #remove mars.step; - constant stepZero = 0; - alias mars.step =stepZero; - } + # product + alias mars.product = coordAveragingTims; + # date + if (marsType == TYPE_OR && averaging1Flag == P_INST) { + #remove mars.date; + alias mars.date = verificationDate; + #remove mars.step; + constant stepZero = 0; + alias mars.step =stepZero; + } } } diff --git a/definitions/grib2/template.3.shape_of_the_earth.def b/definitions/grib2/template.3.shape_of_the_earth.def index fcee8e659..ae21ef48a 100644 --- a/definitions/grib2/template.3.shape_of_the_earth.def +++ b/definitions/grib2/template.3.shape_of_the_earth.def @@ -73,12 +73,12 @@ _if (shapeOfTheEarth == 3){ # ECC-979 # The 'scale' accessor works with integers so rounds its first argument # which is not what we want because the inputs are doubles with decimal - # expansions. So use the trick of dividing by 0.001 to multiply by 1000 + # expansions. # # meta earthMajorAxisInMetres scale(earthMajorAxis, thousand, one, zero); # meta earthMinorAxisInMetres scale(earthMinorAxis, thousand, one, zero); - meta earthMajorAxisInMetres divdouble(earthMajorAxis, 0.001); - meta earthMinorAxisInMetres divdouble(earthMinorAxis, 0.001); + meta earthMajorAxisInMetres multdouble(earthMajorAxis, 1000); + meta earthMinorAxisInMetres multdouble(earthMinorAxis, 1000); } _if (shapeOfTheEarth == 7){ # Major and minor axes specified (in m) by data producer diff --git a/definitions/grib3/template.3.shape_of_the_earth.def b/definitions/grib3/template.3.shape_of_the_earth.def index 2ff2dcdf0..434459ec9 100644 --- a/definitions/grib3/template.3.shape_of_the_earth.def +++ b/definitions/grib3/template.3.shape_of_the_earth.def @@ -73,12 +73,12 @@ _if (shapeOfTheEarth == 3){ # ECC-979 # The 'scale' accessor works with integers so rounds its first argument # which is not what we want because the inputs are doubles with decimal - # expansions. So use the trick of dividing by 0.001 to multiply by 1000 + # expansions. # # meta earthMajorAxisInMetres scale(earthMajorAxis, thousand, one, zero); # meta earthMinorAxisInMetres scale(earthMinorAxis, thousand, one, zero); - meta earthMajorAxisInMetres divdouble(earthMajorAxis, 0.001); - meta earthMinorAxisInMetres divdouble(earthMinorAxis, 0.001); + meta earthMajorAxisInMetres multdouble(earthMajorAxis, 1000); + meta earthMinorAxisInMetres multdouble(earthMinorAxis, 1000); } _if (shapeOfTheEarth == 7){ # Major and minor axes specified (in m) by data producer diff --git a/src/grib_accessor_class_multdouble.cc b/src/grib_accessor_class_multdouble.cc index 920b48f53..437031852 100644 --- a/src/grib_accessor_class_multdouble.cc +++ b/src/grib_accessor_class_multdouble.cc @@ -112,7 +112,7 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) static int unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; + const grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; int ret = GRIB_SUCCESS; double value = 0; From b85b85348bc346bc6abaf1436d6f13714bfb634e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 14:43:23 +0000 Subject: [PATCH 031/156] Accessors: Refactoring --- src/grib_accessor_class_divdouble.cc | 6 ------ src/grib_accessor_class_multdouble.cc | 6 ------ tools/grib_options.cc | 2 +- tools/grib_tools.cc | 2 +- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/grib_accessor_class_divdouble.cc b/src/grib_accessor_class_divdouble.cc index f9586e9d7..8ab86e22e 100644 --- a/src/grib_accessor_class_divdouble.cc +++ b/src/grib_accessor_class_divdouble.cc @@ -115,13 +115,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) int ret = GRIB_SUCCESS; double value = 0; - if (*len < 1) { - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); - if (ret != GRIB_SUCCESS) return ret; diff --git a/src/grib_accessor_class_multdouble.cc b/src/grib_accessor_class_multdouble.cc index 437031852..ac5771627 100644 --- a/src/grib_accessor_class_multdouble.cc +++ b/src/grib_accessor_class_multdouble.cc @@ -116,13 +116,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) int ret = GRIB_SUCCESS; double value = 0; - if (*len < 1) { - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); - if (ret != GRIB_SUCCESS) return ret; diff --git a/tools/grib_options.cc b/tools/grib_options.cc index 3d792ca4e..f9ef49400 100644 --- a/tools/grib_options.cc +++ b/tools/grib_options.cc @@ -256,7 +256,7 @@ int grib_process_runtime_options(grib_context* context, int argc, char** argv, g #ifndef ECCODES_ON_WINDOWS /* Check at compile time to ensure our file offset is at least 64 bits */ - COMPILE_TIME_ASSERT(sizeof(options->infile_offset) >= 8); + static_assert(sizeof(options->infile_offset) >= 8); #endif has_output = grib_options_on("U"); diff --git a/tools/grib_tools.cc b/tools/grib_tools.cc index 7a79fd718..2124bc0ab 100644 --- a/tools/grib_tools.cc +++ b/tools/grib_tools.cc @@ -340,7 +340,7 @@ static int grib_tool_without_orderby(grib_runtime_options* options) if (options->infile_offset) { #ifndef ECCODES_ON_WINDOWS /* Check at compile time to ensure our file offset is at least 64 bits */ - COMPILE_TIME_ASSERT(sizeof(options->infile_offset) >= 8); + static_assert(sizeof(options->infile_offset) >= 8); #endif err = fseeko(infile->file, options->infile_offset, SEEK_SET); if (err) { From 9cde3aaef7e4967e06f8527bae551dd40c3c7911 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 14:44:29 +0000 Subject: [PATCH 032/156] Macros: No need for COMPILE_TIME_ASSERT; just use the C++ static_assert --- src/grib_api_internal.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index cea8a7de1..0b516c99b 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -171,20 +171,6 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type); if (!(a)) codes_assertion_failed(#a, __FILE__, __LINE__); \ } while (0) -#ifdef __gnu_hurd__ -#define COMPILE_TIME_ASSERT(condition) \ - extern int compile_time_assert[!!(condition)-1] -#else -/* Compile time assertion - Thanks to Ralf Holly */ -#define COMPILE_TIME_ASSERT(condition) \ - do { \ - enum \ - { \ - assert_static__ = 1 / (condition) \ - }; \ - } while (0) -#endif - #ifdef DEBUG #define DEBUG_ASSERT(a) Assert(a) #define DEBUG_ASSERT_ACCESS(array, index, size) \ From af517c94a8439734ef74179b7436b04b8b5ac970 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 14:44:59 +0000 Subject: [PATCH 033/156] Fix compiler warnings --- src/grib_dumper_class_serialize.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/grib_dumper_class_serialize.cc b/src/grib_dumper_class_serialize.cc index 163a01f6b..6dc4d5c87 100644 --- a/src/grib_dumper_class_serialize.cc +++ b/src/grib_dumper_class_serialize.cc @@ -408,11 +408,10 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { - const char* secstr = "section"; - int len = 0; + const char* secstr = "section"; grib_dumper_serialize* self = (grib_dumper_serialize*)d; - len = strlen(secstr); + size_t len = strlen(secstr); if (a->name[0] == '_') { grib_dump_accessors_block(d, block); From 4f3da1926000fe11f30a46569e9d5174d02c5e05 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 14:53:07 +0000 Subject: [PATCH 034/156] Fix compiler warnings --- src/grib_accessor_class_expanded_descriptors.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/grib_accessor_class_expanded_descriptors.cc index 5b7002bf8..d515e4dcb 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/grib_accessor_class_expanded_descriptors.cc @@ -223,7 +223,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ * Its max size is X (from FXY) which is 6 bits so no need for malloc */ bufr_descriptor* ur[65] = {0,}; bufr_descriptor* urc = NULL; - int idx; + size_t idx = 0; bufr_descriptor* u0 = NULL; grib_context* c = a->context; bufr_descriptor* us = NULL; From 54f385b89722c639598ca7f4dd40f0bce873c922 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 14:56:27 +0000 Subject: [PATCH 035/156] Fix compiler warnings --- src/grib_nearest.cc | 4 ++-- src/grib_trie_with_rank.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/grib_nearest.cc b/src/grib_nearest.cc index 1367daaf3..d440771f7 100644 --- a/src/grib_nearest.cc +++ b/src/grib_nearest.cc @@ -341,8 +341,8 @@ int grib_nearest_find_generic( double lat1 = 0, lat2 = 0; /* inlat will be between these */ const double LAT_DELTA = 10.0; /* in degrees */ - *out_lons_count = nvalues; /* Maybe overestimate but safe */ - *out_lats_count = nvalues; + *out_lons_count = (int)nvalues; /* Maybe overestimate but safe */ + *out_lats_count = (int)nvalues; if (*out_lats) grib_context_free(nearest->context, *out_lats); diff --git a/src/grib_trie_with_rank.cc b/src/grib_trie_with_rank.cc index d999f9f1f..8b74b6ca6 100644 --- a/src/grib_trie_with_rank.cc +++ b/src/grib_trie_with_rank.cc @@ -485,7 +485,7 @@ int grib_trie_with_rank_insert(grib_trie_with_rank* t, const char* key, void* da grib_oarray_push(t->context, t->objs, data); /* grib_trie_with_rank_insert_in_list(t,data); */ GRIB_MUTEX_UNLOCK(&mutex); - return t->objs->n; + return (int)t->objs->n; } /* From 5918bee6453b4d93cbb56e5012c1804318d85e0a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 17:14:32 +0000 Subject: [PATCH 036/156] Fix compiler warnings --- src/grib_nearest_class_latlon_reduced.cc | 2 +- src/grib_nearest_class_reduced.cc | 2 +- src/grib_nearest_class_regular.cc | 2 +- tests/grib_nearest_test.cc | 7 +++---- tools/grib_histogram.cc | 3 ++- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/grib_nearest_class_latlon_reduced.cc b/src/grib_nearest_class_latlon_reduced.cc index 992b29f2e..e38978188 100644 --- a/src/grib_nearest_class_latlon_reduced.cc +++ b/src/grib_nearest_class_latlon_reduced.cc @@ -409,7 +409,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, if (values) { /* ECC-499 */ grib_get_double_element_internal(h, self->values_key, self->k[kk], &(values[kk])); } - indexes[kk] = self->k[kk]; + indexes[kk] = (int)self->k[kk]; kk++; } } diff --git a/src/grib_nearest_class_reduced.cc b/src/grib_nearest_class_reduced.cc index 603c1a441..f17d3b4e3 100644 --- a/src/grib_nearest_class_reduced.cc +++ b/src/grib_nearest_class_reduced.cc @@ -490,7 +490,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_reduced: Unable to compute index. Value too large"); return GRIB_OUT_OF_RANGE; } else { - indexes[kk] = self->k[kk]; + indexes[kk] = (int)self->k[kk]; } kk++; } diff --git a/src/grib_nearest_class_regular.cc b/src/grib_nearest_class_regular.cc index 4e007ce7a..7ff90e38f 100644 --- a/src/grib_nearest_class_regular.cc +++ b/src/grib_nearest_class_regular.cc @@ -351,7 +351,7 @@ static int find(grib_nearest* nearest, grib_handle* h, grib_context_log(h->context, GRIB_LOG_ERROR, "grib_nearest_regular: Unable to compute index. Value too large"); return GRIB_OUT_OF_RANGE; } else { - indexes[kk] = self->k[kk]; + indexes[kk] = (int)self->k[kk]; } kk++; } diff --git a/tests/grib_nearest_test.cc b/tests/grib_nearest_test.cc index 5731f6bb2..24b76f457 100644 --- a/tests/grib_nearest_test.cc +++ b/tests/grib_nearest_test.cc @@ -31,10 +31,9 @@ int main(int argc, char** argv) { int err = 0; long step = 0; - size_t nfiles = 0; - size_t i = 0, j = 0; - codes_fieldset* set = NULL; - const size_t max_numfiles = 100; + int nfiles = 0, i = 0, j = 0; + codes_fieldset* set = NULL; + const int max_numfiles = 100; codes_handle* h = NULL; char param[20] = {0,}; size_t len = 20; diff --git a/tools/grib_histogram.cc b/tools/grib_histogram.cc index 08ce17f89..90a7e8532 100644 --- a/tools/grib_histogram.cc +++ b/tools/grib_histogram.cc @@ -58,10 +58,11 @@ int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* fi */ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) { - size_t i, j, err = 0; + size_t i, j; size_t last_size = 0; long missingValuesPresent; double delta; + int err = 0; double* values = NULL; size_t size; From 141e2acc0d2cdc50a8f5915a023d86732fca2953 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 22:08:24 +0000 Subject: [PATCH 037/156] Dead code removal --- src/eccodes_prototypes.h | 1 - src/grib_expression.cc | 75 ++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index b072d5191..3537fc05f 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1311,7 +1311,6 @@ const char* grib_expression_get_name(grib_expression* g); void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f); void grib_expression_free(grib_context* ctx, grib_expression* g); void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer); -int grib_expression_set_value(grib_handle* h, grib_expression* g, grib_values* v); grib_arguments* grib_arguments_new(grib_context* c, grib_expression* g, grib_arguments* n); void grib_arguments_free(grib_context* c, grib_arguments* g); void grib_arguments_print(grib_context* c, grib_arguments* g, grib_handle* f); diff --git a/src/grib_expression.cc b/src/grib_expression.cc index c3cd36305..4c1109640 100644 --- a/src/grib_expression.cc +++ b/src/grib_expression.cc @@ -19,8 +19,7 @@ int grib_expression_native_type(grib_handle* h, grib_expression* g) c = c->super ? *(c->super) : NULL; } if (g->cclass) - grib_context_log(h->context, GRIB_LOG_ERROR, "No native_type() in %s", g->cclass->name); - Assert(1 == 0); + grib_context_log(h->context, GRIB_LOG_FATAL, "%s: No native_type() in %s", __func__, g->cclass->name); return 0; } @@ -55,7 +54,7 @@ const char* grib_expression_evaluate_string(grib_handle* h, grib_expression* g, c = c->super ? *(c->super) : NULL; } if (g->cclass) - grib_context_log(h->context, GRIB_LOG_ERROR, "No evaluate_string() in %s", g->cclass->name); + grib_context_log(h->context, GRIB_LOG_ERROR, "%s: No evaluate_string() in %s", __func__, g->cclass->name); *err = GRIB_INVALID_TYPE; return 0; @@ -69,8 +68,9 @@ const char* grib_expression_get_name(grib_expression* g) return c->get_name(g); c = c->super ? *(c->super) : NULL; } - if (g->cclass) printf("No expression_get_name() in %s\n", g->cclass->name); - Assert(1 == 0); + if (g->cclass) { + grib_context_log(grib_context_get_default(), GRIB_LOG_FATAL, "%s: No get_name() in %s", __func__, g->cclass->name); + } return 0; } @@ -84,7 +84,6 @@ void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f } c = c->super ? *(c->super) : NULL; } - Assert(1 == 0); } void grib_expression_free(grib_context* ctx, grib_expression* g) @@ -110,43 +109,37 @@ void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer) } c = c->super ? *(c->super) : NULL; } - Assert(1 == 0); } -/*----------------------------------------*/ -int grib_expression_set_value(grib_handle* h, grib_expression* g, grib_values* v) -{ - char buffer[1024]; - int ret = 0; - size_t size = sizeof(buffer); - - switch (v->type = grib_expression_native_type(h, g)) { - case GRIB_TYPE_LONG: - return grib_expression_evaluate_long(h, g, &v->long_value); - break; - - case GRIB_TYPE_DOUBLE: - return grib_expression_evaluate_double(h, g, &v->double_value); - break; - - case GRIB_TYPE_STRING: - v->string_value = grib_expression_evaluate_string(h, g, buffer, &size, &ret); - if (ret != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, - "grib_expression_set_value: unable to evaluate %s as string", - grib_expression_get_name(g)); - return ret; - } - Assert(v->string_value != buffer); - Assert(v->string_value); - break; - - default: - Assert(1 == 0); - break; - } - return 0; -} +// int grib_expression_set_value(grib_handle* h, grib_expression* g, grib_values* v) +// { +// char buffer[1024]; +// int ret = 0; +// size_t size = sizeof(buffer); +// switch (v->type = grib_expression_native_type(h, g)) { +// case GRIB_TYPE_LONG: +// return grib_expression_evaluate_long(h, g, &v->long_value); +// break; +// case GRIB_TYPE_DOUBLE: +// return grib_expression_evaluate_double(h, g, &v->double_value); +// break; +// case GRIB_TYPE_STRING: +// v->string_value = grib_expression_evaluate_string(h, g, buffer, &size, &ret); +// if (ret != GRIB_SUCCESS) { +// grib_context_log(h->context, GRIB_LOG_ERROR, +// "grib_expression_set_value: unable to evaluate %s as string", +// grib_expression_get_name(g)); +// return ret; +// } +// Assert(v->string_value != buffer); +// Assert(v->string_value); +// break; +// default: +// Assert(!"grib_expression_set_value"); +// break; +// } +// return 0; +// } /*----------------------------------------*/ grib_arguments* grib_arguments_new(grib_context* c, grib_expression* g, grib_arguments* n) From 2a7bf810c5e2b4ce46ce4bf034c36ef1a5bfe0c8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 22:08:47 +0000 Subject: [PATCH 038/156] Error messages --- src/grib_accessor_class_non_alpha.cc | 2 -- src/grib_handle.cc | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/grib_accessor_class_non_alpha.cc b/src/grib_accessor_class_non_alpha.cc index f324257fe..821f2311f 100644 --- a/src/grib_accessor_class_non_alpha.cc +++ b/src/grib_accessor_class_non_alpha.cc @@ -190,7 +190,6 @@ static int unpack_long(grib_accessor* a, long* v, size_t* len) *v = strtol(val, &last, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); return GRIB_SUCCESS; } @@ -204,7 +203,6 @@ static int unpack_double(grib_accessor* a, double* v, size_t* len) *v = strtod(val, &last); if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); return GRIB_SUCCESS; } diff --git a/src/grib_handle.cc b/src/grib_handle.cc index 8a7719234..e1c361eba 100644 --- a/src/grib_handle.cc +++ b/src/grib_handle.cc @@ -375,7 +375,7 @@ grib_handle* grib_handle_clone_headers_only(const grib_handle* h) const int sections_to_copy = GRIB_SECTION_PRODUCT | GRIB_SECTION_LOCAL | GRIB_SECTION_GRID; result = grib_util_sections_copy((grib_handle*)h, h_sample, sections_to_copy, &err); if (!result || err) { - grib_context_log(c, GRIB_LOG_ERROR, "Failed to create headers_only clone: Unable to copy sections"); + grib_context_log(c, GRIB_LOG_ERROR, "%s failed: Unable to copy sections (%s)", __func__, grib_get_error_message(err)); grib_handle_delete(h_sample); return NULL; } From 24bf6f18465b2826a9950dd3635efcad36ff5ff5 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Feb 2024 22:09:03 +0000 Subject: [PATCH 039/156] Testing: Octahedral --- tests/grib_octahedral.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/grib_octahedral.sh b/tests/grib_octahedral.sh index 967eecc1a..6ed838d99 100755 --- a/tests/grib_octahedral.sh +++ b/tests/grib_octahedral.sh @@ -33,4 +33,12 @@ if [ $HAVE_EXTRA_TESTS -eq 1 ]; then [ "$numlines" = "6599681" ] # 1 + numberOfDataPoints fi +# Regular Gaussian (no pl array) +input=${data_dir}/regular_gaussian_model_level.grib2 +grib_check_key_equals $input isOctahedral 0 + +result=$( $tools_dir/grib_get -s Ni=missing -p isOctahedral $input ) +[ $result -eq 0 ] + +# Clean up rm -f $temp From c6bc2dc027e362519139dd880ad78c4ca4ad84ea Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 20 Feb 2024 13:57:38 +0000 Subject: [PATCH 040/156] Testing: Consistent naming --- tests/bufr_ecc-1028.sh | 8 ++++---- tests/bufr_extract_headers.cc | 26 -------------------------- tests/grib_grid_healpix.sh | 18 +++++++++--------- tests/grib_grid_lambert_conformal.sh | 12 ++++++------ tests/grib_grid_mercator.sh | 8 ++++---- tests/grib_grid_polar_stereographic.sh | 6 +++--- tests/grib_grid_space_view.sh | 12 ++++++------ tests/grib_second_order.sh | 20 ++++++++++---------- 8 files changed, 42 insertions(+), 68 deletions(-) diff --git a/tests/bufr_ecc-1028.sh b/tests/bufr_ecc-1028.sh index a68b1c43c..36016648a 100755 --- a/tests/bufr_ecc-1028.sh +++ b/tests/bufr_ecc-1028.sh @@ -11,15 +11,15 @@ . ./include.ctest.sh set -u label="bufr_ecc-1028_test" -tempFilter=temp.$label.filt +tempFilt=temp.$label.filt tempError=temp.$label.err sample_bufr4=$ECCODES_SAMPLES_PATH/BUFR4.tmpl # Incorrect replication. Encoding should fail -echo "set unexpandedDescriptors={ 101000, 31002 }; write;" > $tempFilter +echo "set unexpandedDescriptors={ 101000, 31002 }; write;" > $tempFilt set +e -${tools_dir}/bufr_filter $tempFilter $sample_bufr4 2>$tempError +${tools_dir}/bufr_filter $tempFilt $sample_bufr4 2>$tempError status=$? set -e [ $status -ne 0 ] @@ -27,4 +27,4 @@ set -e grep -q "Delayed replication: 101000: expected 1 but only found 0 elements" $tempError -rm -f $tempFilter $tempError +rm -f $tempFilt $tempError diff --git a/tests/bufr_extract_headers.cc b/tests/bufr_extract_headers.cc index a963a32f0..aacc7f1bc 100644 --- a/tests/bufr_extract_headers.cc +++ b/tests/bufr_extract_headers.cc @@ -13,31 +13,6 @@ #include #define MAX_KEYS 100 -#if 0 -int main(int argc, char* argv[]) -{ - char *filename; - int err = 0; - int num_messages = 0, i =0; - off_t* offsets = NULL; - codes_context* c = codes_context_get_default(); - const int strict_mode = 1; - - /* Usage: prog file */ - assert(argc == 2); - - filename = argv[1]; - err = codes_extract_offsets_malloc(c, filename, PRODUCT_GRIB, &offsets, &num_messages, strict_mode); - assert(!err); - - for (i = 0; i < num_messages; ++i) { - printf("Message #%d: %lu\n", i, offsets[i]); - } - free(offsets); - return 0; -} -#endif -#if 1 int main(int argc, char* argv[]) { char *filename, *keys; @@ -85,4 +60,3 @@ int main(int argc, char* argv[]) return 0; } -#endif diff --git a/tests/grib_grid_healpix.sh b/tests/grib_grid_healpix.sh index 82ee2b257..9b3560693 100755 --- a/tests/grib_grid_healpix.sh +++ b/tests/grib_grid_healpix.sh @@ -11,7 +11,7 @@ # Define a common label for all the tmp files label="grib_healpix_test" -tempFilter="temp.${label}.filt" +tempFilt="temp.${label}.filt" tempGrib="temp.${label}.grib" tempLog="temp.${label}.log" @@ -20,7 +20,7 @@ input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl latest=`${tools_dir}/grib_get -p tablesVersionLatest $input` # Create a filter -cat > $tempFilter < $tempFilt < $tempFilter <&2 exit 1 @@ -47,7 +47,7 @@ ${tools_dir}/grib_ls -jn geography $tempGrib # Geoiterator # ------------- rm -f $tempGrib -cat > $tempFilter < $tempFilt < $tempFilter < $tempFilter < $tempFilt < $tempFilter < $tempFilter < $tempFilt < $tempFilter <&2 exit 1 @@ -49,7 +49,7 @@ ${tools_dir}/grib_ls -l 50,0 $tempGrib # Oblate earth # -------------- -cat > $tempFilter < $tempFilt < $tempFilter <&2 exit 1 @@ -83,4 +83,4 @@ ${tools_dir}/grib_ls -l 40.44,353.56 $tempGrib # Clean up -rm -f $tempFilter $tempGrib $tempOut +rm -f $tempFilt $tempGrib $tempOut diff --git a/tests/grib_grid_mercator.sh b/tests/grib_grid_mercator.sh index 5846b08a8..4ba2d43d6 100755 --- a/tests/grib_grid_mercator.sh +++ b/tests/grib_grid_mercator.sh @@ -12,7 +12,7 @@ # Define a common label for all the tmp files label="grib_mercator_test" tempOut="temp.${label}.out" -tempFilter="temp.${label}.filt" +tempFilt="temp.${label}.filt" input=${data_dir}/mercator.grib2 grib_check_key_equals $input "gridType" "mercator" @@ -22,17 +22,17 @@ numlines=`wc -l $tempOut | awk '{print $1}'` # Check other iterator-related keys -cat > $tempFilter < $tempFilt < $tempOut grep -q "Point chosen #1 index=618" $tempOut # Clean up -rm -f $tempFilter $tempOut +rm -f $tempFilt $tempOut diff --git a/tests/grib_grid_polar_stereographic.sh b/tests/grib_grid_polar_stereographic.sh index 251dd0095..b8758000b 100755 --- a/tests/grib_grid_polar_stereographic.sh +++ b/tests/grib_grid_polar_stereographic.sh @@ -11,7 +11,7 @@ # Define a common label for all the tmp files label="grib_polar_stereographic_test" -tempFilter="temp.${label}.filt" +tempFilt="temp.${label}.filt" tempGrib="temp.${label}.grib" tempOut="temp.${label}.out" @@ -19,7 +19,7 @@ input=$ECCODES_SAMPLES_PATH/polar_stereographic_pl_grib2.tmpl # Invoke Geoiterator ${tools_dir}/grib_get_data $input > $tempOut - +# Nearest ${tools_dir}/grib_ls -l 60,0 $input # Scanning mode @@ -27,4 +27,4 @@ ${tools_dir}/grib_get_data -s iScansNegatively=1 $input > $tempOut # Clean up -rm -f $tempFilter $tempGrib $tempOut +rm -f $tempFilt $tempGrib $tempOut diff --git a/tests/grib_grid_space_view.sh b/tests/grib_grid_space_view.sh index 5b987cd53..71b1759cf 100755 --- a/tests/grib_grid_space_view.sh +++ b/tests/grib_grid_space_view.sh @@ -11,7 +11,7 @@ # Define a common label for all the tmp files label="grib_space_view_test" -tempFilter="temp.${label}.filt" +tempFilt="temp.${label}.filt" tempGrib1="temp.${label}.grib1" tempGrib2="temp.${label}.grib2" tempOut="temp.${label}.out" @@ -20,7 +20,7 @@ tempOut="temp.${label}.out" # GRIB2 # ----------- input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl -cat > $tempFilter < $tempFilt < $tempFilter <&2 exit 1 @@ -66,7 +66,7 @@ rm -f $tempGrib2 $tempOut # GRIB1 # ----------- input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl -cat > $tempFilter < $tempFilt < $tempFilter < $tempOut ${tools_dir}/grib_set -s edition=2 $tempGrib1 $tempGrib2 @@ -85,4 +85,4 @@ ${tools_dir}/grib_compare -e -b param $tempGrib1 $tempGrib2 # Clean up -rm -f $tempFilter $tempGrib1 $tempGrib2 $tempOut +rm -f $tempFilt $tempGrib1 $tempGrib2 $tempOut diff --git a/tests/grib_second_order.sh b/tests/grib_second_order.sh index 37bc89cd5..1dc6092df 100755 --- a/tests/grib_second_order.sh +++ b/tests/grib_second_order.sh @@ -20,7 +20,7 @@ cd ${data_dir} encoding=1 simple_no_bitmap=simple.grib simple_bitmap=simple_bitmap.grib -test_filter=temp.$label.filter +tempFilt=temp.$label.filter files_no_bitmap="gen_ext.grib \ gen_ext_boust.grib \ @@ -41,11 +41,11 @@ simple_bitmap.grib" no_packing="gen.grib|row.grib|gen_bitmap.grib|constant_width_bitmap.grib|constant_width_boust_bitmap.grib" test_data() { - ${tools_dir}/grib_filter $test_filter $simple > $simple.data + ${tools_dir}/grib_filter $tempFilt $simple > $simple.data for f in $files do - ${tools_dir}/grib_filter $test_filter $f > $f.data + ${tools_dir}/grib_filter $tempFilt $f > $f.data diff $simple.data $f.data > /dev/null ${tools_dir}/grib_compare -cvalues $f $simple echo $f decoding test passed > $REDIRECT @@ -55,7 +55,7 @@ test_data() { then rm -f $f.copied ${tools_dir}/grib_copy -r $f $f.copied - ${tools_dir}/grib_filter $test_filter $f.copied > $f.copied.data + ${tools_dir}/grib_filter $tempFilt $f.copied > $f.copied.data diff $simple.data $f.copied.data > /dev/null ${tools_dir}/grib_compare -cvalues $f.copied $simple echo $f encoding test passed > $REDIRECT @@ -67,7 +67,7 @@ test_data() { } -cat > $test_filter< $tempFilt< $test_filter< $tempFilt<$tempText grib_check_key_equals $temp3 packingType,accuracy 'grid_simple 24' grep -q "Packing not changed" $tempText # Three coded values: Now we can change to 2nd order -cat > $test_filter< $tempFilt< Date: Tue, 20 Feb 2024 19:18:08 +0000 Subject: [PATCH 041/156] Definitions: countOfGroupLengths not used --- definitions/grib2/template.7.50001.def | 6 ++---- definitions/grib2/template.7.50002.def | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/definitions/grib2/template.7.50001.def b/definitions/grib2/template.7.50001.def index 18bc0ca32..882379f36 100644 --- a/definitions/grib2/template.7.50001.def +++ b/definitions/grib2/template.7.50001.def @@ -6,13 +6,13 @@ if (bitsPerValue) { meta groupWidths unsigned_bits(widthOfWidths,numberOfGroups) : read_only; meta groupLengths unsigned_bits(widthOfLengths,numberOfGroups) : read_only; meta firstOrderValues unsigned_bits(widthOfFirstOrderValues,numberOfGroups) : read_only; - meta countOfGroupLengths sum(groupLengths); + # meta countOfGroupLengths sum(groupLengths); } transient halfByte=0; position offsetBeforeData; -if(bitmapPresent) { +if(bitmapPresent) { meta codedValues data_g1second_order_general_extended_packing( #simple_packing args section7Length, @@ -49,7 +49,6 @@ if(bitmapPresent) { widthOfSPD, orderOfSPD, numberOfPoints - ): read_only; alias data.packedValues = codedValues; @@ -91,7 +90,6 @@ if(bitmapPresent) { widthOfSPD, orderOfSPD, numberOfPoints - ) : dump; alias codedValues=values; alias data.packedValues = values; diff --git a/definitions/grib2/template.7.50002.def b/definitions/grib2/template.7.50002.def index be47b0604..7ca21e92a 100644 --- a/definitions/grib2/template.7.50002.def +++ b/definitions/grib2/template.7.50002.def @@ -5,12 +5,12 @@ meta groupWidths unsigned_bits(widthOfWidths,numberOfGroups) : read_only; meta groupLengths unsigned_bits(widthOfLengths,numberOfGroups) : read_only; meta firstOrderValues unsigned_bits(widthOfFirstOrderValues,numberOfGroups) : read_only; -meta countOfGroupLengths sum(groupLengths); +# meta countOfGroupLengths sum(groupLengths); transient halfByte=0; position offsetBeforeData; -if(bitmapPresent) { +if(bitmapPresent) { meta codedValues data_g1second_order_general_extended_packing( #simple_packing args section7Length, @@ -47,7 +47,6 @@ if(bitmapPresent) { widthOfSPD, orderOfSPD, numberOfPoints - ): read_only; alias data.packedValues = codedValues; @@ -96,8 +95,7 @@ if(bitmapPresent) { widthOfSPD, orderOfSPD, numberOfPoints - - ) : dump; + ) : dump; meta values data_apply_boustrophedonic(codedValues,numberOfRows,numberOfColumns,numberOfPoints,pl) : dump; @@ -138,7 +136,6 @@ if(bitmapPresent) { widthOfSPD, orderOfSPD, numberOfPoints - ) : dump; alias codedValues=values; } From c84361c9f1f13d190872457302f8e67e3b6a7ec6 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 20 Feb 2024 19:18:28 +0000 Subject: [PATCH 042/156] Testing: bufr_compare options --- tests/bufr_compare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bufr_compare.sh b/tests/bufr_compare.sh index 27f0c071b..de19abc1c 100755 --- a/tests/bufr_compare.sh +++ b/tests/bufr_compare.sh @@ -351,7 +351,8 @@ set -e [ $status -ne 0 ] grep -q "unreadable message" $fLog -###??? +# Options +# ---------- f1="aaen_55.bufr" f2="aaen_55.bufr" set +e @@ -368,7 +369,6 @@ set -e [ $status -ne 0 ] grep -q "a option requires -c option" $fLog - set +e ${tools_dir}/bufr_compare nosuchfile $f1 > $fLog 2>&1 status=$? From 5eb158decf4b61946505c1b9d13444207cfc7dd0 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 21 Feb 2024 10:26:35 +0000 Subject: [PATCH 043/156] Const correctness and cppcheck warnings --- src/grib_expression_class_accessor.cc | 14 ++++++------- src/grib_expression_class_column.cc | 8 +------ src/grib_expression_class_constant.cc | 10 ++------- src/grib_expression_class_double.cc | 14 ++++++------- src/grib_expression_class_functor.cc | 6 +++--- src/grib_expression_class_is_in_dict.cc | 20 +++++++++--------- src/grib_expression_class_is_in_list.cc | 24 +++++++++------------ src/grib_expression_class_is_integer.cc | 12 +++++------ src/grib_expression_class_length.cc | 28 ++++++++++++------------- src/grib_expression_class_long.cc | 14 ++++++------- src/grib_expression_class_string.cc | 6 +++--- src/grib_expression_class_sub_string.cc | 6 +++--- 12 files changed, 73 insertions(+), 89 deletions(-) diff --git a/src/grib_expression_class_accessor.cc b/src/grib_expression_class_accessor.cc index e806a3e1a..67ffbea9a 100644 --- a/src/grib_expression_class_accessor.cc +++ b/src/grib_expression_class_accessor.cc @@ -92,25 +92,25 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_accessor* e = (grib_expression_accessor*)g; + const grib_expression_accessor* e = (grib_expression_accessor*)g; return e->name; } static int evaluate_long(grib_expression* g, grib_handle* h, long* result) { - grib_expression_accessor* e = (grib_expression_accessor*)g; + const grib_expression_accessor* e = (grib_expression_accessor*)g; return grib_get_long_internal(h, e->name, result); } static int evaluate_double(grib_expression* g, grib_handle* h, double* result) { - grib_expression_accessor* e = (grib_expression_accessor*)g; + const grib_expression_accessor* e = (grib_expression_accessor*)g; return grib_get_double_internal(h, e->name, result); } static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) { - grib_expression_accessor* e = (grib_expression_accessor*)g; + const grib_expression_accessor* e = (grib_expression_accessor*)g; char mybuf[1024] = {0,}; long start = e->start; if (e->length > sizeof(mybuf)) { @@ -141,7 +141,7 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_accessor* e = (grib_expression_accessor*)g; + const grib_expression_accessor* e = (grib_expression_accessor*)g; printf("access('%s", e->name); if (f) { long s = 0; @@ -159,8 +159,8 @@ static void destroy(grib_context* c, grib_expression* g) static void add_dependency(grib_expression* g, grib_accessor* observer) { - grib_expression_accessor* e = (grib_expression_accessor*)g; - grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); + const grib_expression_accessor* e = (grib_expression_accessor*)g; + grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); if (!observed) { /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ diff --git a/src/grib_expression_class_column.cc b/src/grib_expression_class_column.cc index b683b93a5..fefdaca0a 100644 --- a/src/grib_expression_class_column.cc +++ b/src/grib_expression_class_column.cc @@ -8,11 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - #include "grib_api_internal.h" /* @@ -89,7 +84,7 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_column* e = (grib_expression_column*)g; + const grib_expression_column* e = (grib_expression_column*)g; return e->name; } @@ -131,7 +126,6 @@ static void destroy(grib_context* c, grib_expression* g) grib_context_free_persistent(c, e->name); } - grib_expression* new_column_expression(grib_context* c, const char* name) { grib_expression_column* e = grib_context_malloc_clear_persistent(c, sizeof(grib_expression_column)); diff --git a/src/grib_expression_class_constant.cc b/src/grib_expression_class_constant.cc index 7bd817678..e669a6049 100644 --- a/src/grib_expression_class_constant.cc +++ b/src/grib_expression_class_constant.cc @@ -8,11 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - #include "grib_api_internal.h" /* @@ -85,13 +80,13 @@ static void init_class(grib_expression_class* c) static long evaluate(grib_expression* g, grib_handle* h) { - grib_expression_constant* e = (grib_expression_constant*)g; + const grib_expression_constant* e = (grib_expression_constant*)g; return e->value; } static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_constant* e = (grib_expression_constant*)g; + const grib_expression_constant* e = (grib_expression_constant*)g; printf("constant(%ld)", e->value); } @@ -100,7 +95,6 @@ static void destroy(grib_context* c, grib_expression* g) /* grib_expression_constant* e = (grib_expression_constant*)g; */ } - static void add_dependency(grib_expression* g, grib_accessor* observer) { /* grib_expression_constant* e = (grib_expression_constant*)g; */ diff --git a/src/grib_expression_class_double.cc b/src/grib_expression_class_double.cc index f904c887e..0c0f87a16 100644 --- a/src/grib_expression_class_double.cc +++ b/src/grib_expression_class_double.cc @@ -84,21 +84,21 @@ static void init_class(grib_expression_class* c) static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) { - grib_expression_double* e = (grib_expression_double*)g; - *lres = e->value; + const grib_expression_double* e = (grib_expression_double*)g; + *lres = e->value; return GRIB_SUCCESS; } static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) { - grib_expression_double* e = (grib_expression_double*)g; - *dres = e->value; + const grib_expression_double* e = (grib_expression_double*)g; + *dres = e->value; return GRIB_SUCCESS; } static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_double* e = (grib_expression_double*)g; + const grib_expression_double* e = (grib_expression_double*)g; printf("double(%g)", e->value); } @@ -115,8 +115,8 @@ static void add_dependency(grib_expression* g, grib_accessor* observer) grib_expression* new_double_expression(grib_context* c, double value) { grib_expression_double* e = (grib_expression_double*)grib_context_malloc_clear_persistent(c, sizeof(grib_expression_double)); - e->base.cclass = grib_expression_class_double; - e->value = value; + e->base.cclass = grib_expression_class_double; + e->value = value; return (grib_expression*)e; } diff --git a/src/grib_expression_class_functor.cc b/src/grib_expression_class_functor.cc index 89c4d8a6a..16153620d 100644 --- a/src/grib_expression_class_functor.cc +++ b/src/grib_expression_class_functor.cc @@ -134,7 +134,7 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) const char* p = grib_arguments_get_name(h, e->args, 0); if (p) { - grib_accessor* a = grib_find_accessor(h, p); + const grib_accessor* a = grib_find_accessor(h, p); *lres = a != NULL ? 1 : 0; return GRIB_SUCCESS; } @@ -149,7 +149,7 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) // 2. Cannot deal with string values const char* p = grib_arguments_get_name(h, e->args, 0); if (p) { - char* env = getenv(p); + const char* env = getenv(p); if (env) { long lval = 0; if (string_to_long(env, &lval, 1) == GRIB_SUCCESS) { @@ -177,7 +177,7 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_functor* e = (grib_expression_functor*)g; + const grib_expression_functor* e = (grib_expression_functor*)g; printf("%s(", e->name); // grib_expression_print(c,e->args,f); printf(")"); diff --git a/src/grib_expression_class_is_in_dict.cc b/src/grib_expression_class_is_in_dict.cc index a2ad355ab..27856cc2d 100644 --- a/src/grib_expression_class_is_in_dict.cc +++ b/src/grib_expression_class_is_in_dict.cc @@ -94,10 +94,10 @@ static grib_trie* load_dictionary(grib_context* c, grib_expression* e, int* err) char* filename = NULL; char line[1024] = {0,}; char key[1024] = {0,}; - char* list = 0; + char* list = 0; grib_trie* dictionary = NULL; - FILE* f = NULL; - int i = 0; + FILE* f = NULL; + int i = 0; *err = GRIB_SUCCESS; @@ -148,15 +148,15 @@ static grib_trie* load_dictionary(grib_context* c, grib_expression* e, int* err) static const char* get_name(grib_expression* g) { - grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; + const grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; return e->key; } static int evaluate_long(grib_expression* g, grib_handle* h, long* result) { - grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; - int err = 0; - char mybuf[1024] = {0,}; + const grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; + int err = 0; + char mybuf[1024] = {0,}; size_t size = 1024; grib_trie* dict = load_dictionary(h->context, g, &err); @@ -213,7 +213,7 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; + const grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; printf("access('%s", e->key); if (f) { long s = 0; @@ -239,8 +239,8 @@ static int native_type(grib_expression* g, grib_handle* h) static void add_dependency(grib_expression* g, grib_accessor* observer) { - grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; - grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->key); + const grib_expression_is_in_dict* e = (grib_expression_is_in_dict*)g; + grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->key); if (!observed) { /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ diff --git a/src/grib_expression_class_is_in_list.cc b/src/grib_expression_class_is_in_list.cc index 0d61cf82c..46310bcd3 100644 --- a/src/grib_expression_class_is_in_list.cc +++ b/src/grib_expression_class_is_in_list.cc @@ -147,15 +147,15 @@ static grib_trie* load_list(grib_context* c, grib_expression* e, int* err) static const char* get_name(grib_expression* g) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; return e->name; } static int evaluate_long(grib_expression* g, grib_handle* h, long* result) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - int err = 0; - char mybuf[1024] = {0,}; + const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + int err = 0; + char mybuf[1024] = {0,}; size_t size = 1024; grib_trie* list = load_list(h->context, g, &err); @@ -178,24 +178,20 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* result) // int err = 0; // char mybuf[1024] = {0,}; // size_t size = 1024; - // grib_trie* list = load_list(h->context, g, &err); - // if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS) // return err; - // if (grib_trie_get(list, mybuf)) // *result = 1; // else // *result = 0; - // return err; } static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - char mybuf[1024] = {0,}; + const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + char mybuf[1024] = {0,}; size_t sizebuf = 1024; long result; @@ -216,7 +212,7 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; printf("access('%s", e->name); if (f) { long s = 0; @@ -232,8 +228,8 @@ static void destroy(grib_context* c, grib_expression* g) static void add_dependency(grib_expression* g, grib_accessor* observer) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); + const grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); if (!observed) { /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ @@ -257,7 +253,7 @@ grib_expression* new_is_in_list_expression(grib_context* c, const char* name, co static int native_type(grib_expression* g, grib_handle* h) { grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - int type = 0; + int type = 0; int err; if ((err = grib_get_native_type(h, e->name, &type)) != GRIB_SUCCESS) grib_context_log(h->context, GRIB_LOG_ERROR, diff --git a/src/grib_expression_class_is_integer.cc b/src/grib_expression_class_is_integer.cc index 03554ece7..460170e6e 100644 --- a/src/grib_expression_class_is_integer.cc +++ b/src/grib_expression_class_is_integer.cc @@ -92,15 +92,15 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; + const grib_expression_is_integer* e = (grib_expression_is_integer*)g; return e->name; } static int evaluate_long(grib_expression* g, grib_handle* h, long* result) { grib_expression_is_integer* e = (grib_expression_is_integer*)g; - int err = 0; - char mybuf[1024] = {0,}; + int err = 0; + char mybuf[1024] = {0,}; size_t size = 1024; char* p = 0; long val = 0; @@ -127,10 +127,10 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* result) static int evaluate_double(grib_expression* g, grib_handle* h, double* result) { - int err = 0; + int err = 0; long lresult = 0; - err = evaluate_long(g, h, &lresult); + err = evaluate_long(g, h, &lresult); *result = lresult; return err; } @@ -174,7 +174,7 @@ static void destroy(grib_context* c, grib_expression* g) static void add_dependency(grib_expression* g, grib_accessor* observer) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; + const grib_expression_is_integer* e = (grib_expression_is_integer*)g; grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); if (!observed) { diff --git a/src/grib_expression_class_length.cc b/src/grib_expression_class_length.cc index c685f2186..23ac0f591 100644 --- a/src/grib_expression_class_length.cc +++ b/src/grib_expression_class_length.cc @@ -92,15 +92,15 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_length* e = (grib_expression_length*)g; + const grib_expression_length* e = (grib_expression_length*)g; return e->name; } static int evaluate_long(grib_expression* g, grib_handle* h, long* result) { - grib_expression_length* e = (grib_expression_length*)g; - int err = 0; - char mybuf[1024] = {0,}; + const grib_expression_length* e = (grib_expression_length*)g; + int err = 0; + char mybuf[1024] = {0,}; size_t size = 1024; if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS) return err; @@ -111,10 +111,10 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* result) static int evaluate_double(grib_expression* g, grib_handle* h, double* result) { - grib_expression_length* e = (grib_expression_length*)g; - char mybuf[1024] = {0,}; + const grib_expression_length* e = (grib_expression_length*)g; + char mybuf[1024] = {0,}; size_t size = 1024; - int err = 0; + int err = 0; if ((err = grib_get_string_internal(h, e->name, mybuf, &size)) != GRIB_SUCCESS) return err; @@ -124,8 +124,8 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* result) static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) { - grib_expression_length* e = (grib_expression_length*)g; - char mybuf[1024] = {0,}; + const grib_expression_length* e = (grib_expression_length*)g; + char mybuf[1024] = {0,}; Assert(buf); if ((*err = grib_get_string_internal(h, e->name, mybuf, size)) != GRIB_SUCCESS) return NULL; @@ -136,7 +136,7 @@ static string evaluate_string(grib_expression* g, grib_handle* h, char* buf, siz static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_length* e = (grib_expression_length*)g; + const grib_expression_length* e = (grib_expression_length*)g; printf("access('%s", e->name); if (f) { long s = 0; @@ -154,8 +154,8 @@ static void destroy(grib_context* c, grib_expression* g) static void add_dependency(grib_expression* g, grib_accessor* observer) { - grib_expression_length* e = (grib_expression_length*)g; - grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); + const grib_expression_length* e = (grib_expression_length*)g; + grib_accessor* observed = grib_find_accessor(grib_handle_of_accessor(observer), e->name); if (!observed) { /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ @@ -170,8 +170,8 @@ static void add_dependency(grib_expression* g, grib_accessor* observer) grib_expression* new_length_expression(grib_context* c, const char* name) { grib_expression_length* e = (grib_expression_length*)grib_context_malloc_clear_persistent(c, sizeof(grib_expression_length)); - e->base.cclass = grib_expression_class_length; - e->name = grib_context_strdup_persistent(c, name); + e->base.cclass = grib_expression_class_length; + e->name = grib_context_strdup_persistent(c, name); return (grib_expression*)e; } diff --git a/src/grib_expression_class_long.cc b/src/grib_expression_class_long.cc index 481e143c8..e2c43b9ce 100644 --- a/src/grib_expression_class_long.cc +++ b/src/grib_expression_class_long.cc @@ -84,21 +84,21 @@ static void init_class(grib_expression_class* c) static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) { - grib_expression_long* e = (grib_expression_long*)g; - *lres = e->value; + const grib_expression_long* e = (grib_expression_long*)g; + *lres = e->value; return GRIB_SUCCESS; } static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) { - grib_expression_long* e = (grib_expression_long*)g; - *dres = e->value; + const grib_expression_long* e = (grib_expression_long*)g; + *dres = e->value; return GRIB_SUCCESS; } static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_long* e = (grib_expression_long*)g; + const grib_expression_long* e = (grib_expression_long*)g; printf("long(%ld)", e->value); } @@ -115,8 +115,8 @@ static void add_dependency(grib_expression* g, grib_accessor* observer) grib_expression* new_long_expression(grib_context* c, long value) { grib_expression_long* e = (grib_expression_long*)grib_context_malloc_clear_persistent(c, sizeof(grib_expression_long)); - e->base.cclass = grib_expression_class_long; - e->value = value; + e->base.cclass = grib_expression_class_long; + e->value = value; return (grib_expression*)e; } diff --git a/src/grib_expression_class_string.cc b/src/grib_expression_class_string.cc index 1d6734c4c..962afeaf8 100644 --- a/src/grib_expression_class_string.cc +++ b/src/grib_expression_class_string.cc @@ -82,14 +82,14 @@ static void init_class(grib_expression_class* c) static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) { - grib_expression_string* e = (grib_expression_string*)g; - *err = 0; + const grib_expression_string* e = (grib_expression_string*)g; + *err = 0; return e->value; } static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_string* e = (grib_expression_string*)g; + const grib_expression_string* e = (grib_expression_string*)g; printf("string('%s')", e->value); } diff --git a/src/grib_expression_class_sub_string.cc b/src/grib_expression_class_sub_string.cc index 0a53638bc..988a5d0ba 100644 --- a/src/grib_expression_class_sub_string.cc +++ b/src/grib_expression_class_sub_string.cc @@ -82,14 +82,14 @@ static void init_class(grib_expression_class* c) static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) { - grib_expression_sub_string* e = (grib_expression_sub_string*)g; - *err = 0; + const grib_expression_sub_string* e = (grib_expression_sub_string*)g; + *err = 0; return e->value; } static void print(grib_context* c, grib_expression* g, grib_handle* f) { - grib_expression_sub_string* e = (grib_expression_sub_string*)g; + const grib_expression_sub_string* e = (grib_expression_sub_string*)g; printf("string('%s')", e->value); } From 474f50aa6ff78db5fd7f8577e4077a9a5fa00673 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 21 Feb 2024 13:14:14 +0000 Subject: [PATCH 044/156] ECC-1768: Add no_copy attribute to stepUnits --- definitions/grib2/stepUnits.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/definitions/grib2/stepUnits.def b/definitions/grib2/stepUnits.def index cffc236be..684aa1f72 100644 --- a/definitions/grib2/stepUnits.def +++ b/definitions/grib2/stepUnits.def @@ -4,7 +4,7 @@ # 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) : transient,dump; +meta stepUnits optimal_step_units(forecastTime,indicatorOfUnitOfTimeRange,lengthOfTimeRange,indicatorOfUnitForTimeRange) : dump,no_copy; transient startStepUnit = 255 : hidden; # 255 means MISSING. See code table 4.4 transient endStepUnit = 255 : hidden; # The lowercase version is to unify it with the helper key in the MARS language From 44065534d49d402bb4a74d6ea608afd60c2dc99a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 21 Feb 2024 13:15:29 +0000 Subject: [PATCH 045/156] ECC-1751: GRIB2: Consolidate parameters with fixed statistical processing ranges (S2S changes) --- definitions/grib2/localConcepts/s2s/cfVarName.def | 7 +++++++ definitions/grib2/localConcepts/s2s/name.def | 7 +++++++ definitions/grib2/localConcepts/s2s/paramId.def | 7 +++++++ definitions/grib2/localConcepts/s2s/shortName.def | 7 +++++++ definitions/grib2/localConcepts/s2s/units.def | 7 +++++++ 5 files changed, 35 insertions(+) diff --git a/definitions/grib2/localConcepts/s2s/cfVarName.def b/definitions/grib2/localConcepts/s2s/cfVarName.def index 13a346191..156261d3c 100644 --- a/definitions/grib2/localConcepts/s2s/cfVarName.def +++ b/definitions/grib2/localConcepts/s2s/cfVarName.def @@ -182,4 +182,11 @@ scaledValueOfSecondFixedSurface = missing() ; scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; + } +#Snow depth water equivalent +'sd' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 60 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/s2s/name.def b/definitions/grib2/localConcepts/s2s/name.def index 67dd7608e..cc091e047 100644 --- a/definitions/grib2/localConcepts/s2s/name.def +++ b/definitions/grib2/localConcepts/s2s/name.def @@ -182,4 +182,11 @@ scaledValueOfSecondFixedSurface = missing() ; scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; + } +#Snow depth water equivalent +'Snow depth water equivalent' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 60 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/s2s/paramId.def b/definitions/grib2/localConcepts/s2s/paramId.def index 1156927c0..8db27e06d 100644 --- a/definitions/grib2/localConcepts/s2s/paramId.def +++ b/definitions/grib2/localConcepts/s2s/paramId.def @@ -182,4 +182,11 @@ scaledValueOfSecondFixedSurface = missing() ; scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; + } +#Snow depth water equivalent +'228141' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 60 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/s2s/shortName.def b/definitions/grib2/localConcepts/s2s/shortName.def index 824ef22e7..025f7fe6f 100644 --- a/definitions/grib2/localConcepts/s2s/shortName.def +++ b/definitions/grib2/localConcepts/s2s/shortName.def @@ -182,4 +182,11 @@ scaledValueOfSecondFixedSurface = missing() ; scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; + } +#Snow depth water equivalent +'sd' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 60 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/s2s/units.def b/definitions/grib2/localConcepts/s2s/units.def index 4b7e30d55..17ff29efa 100644 --- a/definitions/grib2/localConcepts/s2s/units.def +++ b/definitions/grib2/localConcepts/s2s/units.def @@ -182,4 +182,11 @@ scaledValueOfSecondFixedSurface = missing() ; scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; + } +#Snow depth water equivalent +'kg m**-2' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 60 ; + typeOfStatisticalProcessing = 0 ; } From a5bb4e186570554315deb43d60971bc246868a15 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 21 Feb 2024 13:32:43 +0000 Subject: [PATCH 046/156] ECC-1768: Remove "loader" workaround --- src/grib_accessor_class_g2step_range.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/grib_accessor_class_g2step_range.cc b/src/grib_accessor_class_g2step_range.cc index 685c8a29b..c39601a40 100644 --- a/src/grib_accessor_class_g2step_range.cc +++ b/src/grib_accessor_class_g2step_range.cc @@ -211,11 +211,6 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; - // TODO(maee): A better solution should be found - if (h->loader) { // h->loader is set only when rebuilding or reparsing - force_step_units = 255; // See ECC-1768 - } - try { std::vector steps = parse_range(val, eccodes::Unit{force_step_units}); if (steps.size() == 0) { From 705cee4b920e7bc63f467f30323da84f83e72923 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 21 Feb 2024 15:11:19 +0000 Subject: [PATCH 047/156] Comments re no_copy flag --- definitions/grib2/stepUnits.def | 1 + src/{ => deprecated}/grib_expression_class_column.cc | 0 src/{ => deprecated}/grib_expression_class_constant.cc | 0 3 files changed, 1 insertion(+) rename src/{ => deprecated}/grib_expression_class_column.cc (100%) rename src/{ => deprecated}/grib_expression_class_constant.cc (100%) diff --git a/definitions/grib2/stepUnits.def b/definitions/grib2/stepUnits.def index 684aa1f72..d1beeb517 100644 --- a/definitions/grib2/stepUnits.def +++ b/definitions/grib2/stepUnits.def @@ -4,6 +4,7 @@ # template_nofail default_step_units "grib2/localConcepts/[centre:s]/default_step_units.def"; # codetable[1] stepUnits 'stepUnits.table' = defaultStepUnits : transient,dump,no_copy; +# See ECC-1768 re why no_copy is needed meta stepUnits optimal_step_units(forecastTime,indicatorOfUnitOfTimeRange,lengthOfTimeRange,indicatorOfUnitForTimeRange) : dump,no_copy; transient startStepUnit = 255 : hidden; # 255 means MISSING. See code table 4.4 transient endStepUnit = 255 : hidden; diff --git a/src/grib_expression_class_column.cc b/src/deprecated/grib_expression_class_column.cc similarity index 100% rename from src/grib_expression_class_column.cc rename to src/deprecated/grib_expression_class_column.cc diff --git a/src/grib_expression_class_constant.cc b/src/deprecated/grib_expression_class_constant.cc similarity index 100% rename from src/grib_expression_class_constant.cc rename to src/deprecated/grib_expression_class_constant.cc From 5b223d2effe74d8ad996ee5ff6a94d69e6cbfb4b Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 21 Feb 2024 15:11:38 +0000 Subject: [PATCH 048/156] Const correctness and cppcheck warnings --- src/grib_accessor_class_bufr_data_element.cc | 84 ++++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/grib_accessor_class_bufr_data_element.cc b/src/grib_accessor_class_bufr_data_element.cc index 1e98e17d9..3301eb10f 100644 --- a/src/grib_accessor_class_bufr_data_element.cc +++ b/src/grib_accessor_class_bufr_data_element.cc @@ -191,61 +191,61 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) void accessor_bufr_data_element_set_index(grib_accessor* a, long index) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->index = index; + self->index = index; } void accessor_bufr_data_element_set_type(grib_accessor* a, int type) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->type = type; + self->type = type; } void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->numberOfSubsets = numberOfSubsets; + self->numberOfSubsets = numberOfSubsets; } void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->subsetNumber = subsetNumber; + self->subsetNumber = subsetNumber; } void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->compressedData = compressedData; + self->compressedData = compressedData; } void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->descriptors = descriptors; + self->descriptors = descriptors; } void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->numericValues = numericValues; + self->numericValues = numericValues; } void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->stringValues = stringValues; + self->stringValues = stringValues; } void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->elementsDescriptorsIndex = elementsDescriptorsIndex; + self->elementsDescriptorsIndex = elementsDescriptorsIndex; } static void init(grib_accessor* a, const long len, grib_arguments* params) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - a->length = 0; + a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_BUFR_DATA; /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ self->cname = NULL; @@ -272,8 +272,8 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = 0, i, idx; - long count = 0; + int ret = 0, idx = 0; + size_t count = 0, i = 0; grib_context* c = a->context; if (self->compressedData) { @@ -289,7 +289,7 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len) else { DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); *len = 1; } @@ -308,7 +308,7 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len) if (self->compressedData) { idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - if (*len != 1 && *len != self->numberOfSubsets) { + if (*len != 1 && *len != (size_t)self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld strings provided but expected %ld (=number of subsets)", self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[idx]]->shortName, *len, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; @@ -323,7 +323,7 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len) } else { //ECC-1623 - if (*len != self->numberOfSubsets) { + if (*len != (size_t)self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %zu strings provided but expected %ld (=number of subsets)", a->name, *len, self->numberOfSubsets); @@ -343,8 +343,8 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len) static int unpack_string(grib_accessor* a, char* val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - char* str = NULL; - char* p = 0; + char* str = NULL; + char* p = 0; size_t slen = 0; double dval = 0; size_t dlen = 1; @@ -413,8 +413,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS, idx = 0; - char* s = NULL; + int ret = GRIB_SUCCESS, idx = 0; + char* s = NULL; grib_context* c = a->context; if (self->compressedData) { @@ -426,7 +426,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */ grib_sarray_delete(c, self->stringValues->v[idx]); self->stringValues->v[idx] = grib_sarray_new(c, 1, 1); - s = grib_context_strdup(c, val); + s = grib_context_strdup(c, val); grib_sarray_push(c, self->stringValues->v[idx], s); return ret; @@ -435,7 +435,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long count = 0, i = 0; value_count(a, &count); @@ -494,12 +494,12 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; int ret = GRIB_SUCCESS; - long count = 1, i = 0; + size_t count = 1, i = 0; grib_context* c = a->context; if (self->compressedData) { count = *len; - if (count != 1 && count != self->numberOfSubsets) { + if (count != 1 && count != (size_t)self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld doubles provided but expected %ld (=number of subsets)", self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; @@ -514,7 +514,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } else { self->numericValues->v[self->subsetNumber]->v[self->index] = val[0]; - *len = 1; + *len = 1; } return ret; @@ -523,14 +523,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) static int pack_long(grib_accessor* a, const long* val, size_t* len) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = 0, i; - long count = 1; - grib_context* c = a->context; + int ret = 0; + size_t count = 1, i = 0; + grib_context* c = a->context; if (self->compressedData) { count = *len; - if (count != 1 && count != self->numberOfSubsets) { - grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld integers provided but expected %ld (=number of subsets)", + if (count != 1 && count != (size_t)self->numberOfSubsets) { + grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %zu integers provided but expected %ld (=number of subsets)", self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; } @@ -544,7 +544,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) } else { self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; - *len = 1; + *len = 1; } return ret; @@ -552,7 +552,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) static int value_count(grib_accessor* a, long* count) { - int ret = 0, type = 0, idx = 0; + int ret = 0, type = 0, idx = 0; size_t size = 0; grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; @@ -581,8 +581,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) { /* ECC-415 */ grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; - long count = 0; + int ret = GRIB_SUCCESS; + long count = 0; value_count(a, &count); if (idx >= (size_t)count) { @@ -601,7 +601,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) static int get_native_type(grib_accessor* a) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_TYPE_DOUBLE; + int ret = GRIB_TYPE_DOUBLE; DEBUG_ASSERT(self); switch (self->type) { case BUFR_DESCRIPTOR_TYPE_STRING: @@ -627,7 +627,7 @@ static int get_native_type(grib_accessor* a) static void destroy(grib_context* ct, grib_accessor* a) { grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int i = 0; + int i = 0; if (self->cname) grib_context_free(ct, self->cname); /* ECC-765 */ while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { @@ -650,14 +650,14 @@ static int is_missing(grib_accessor* a) grib_context* c = a->context; if (ktype == GRIB_TYPE_LONG) { - long* values = NULL; - long value = 0; + long* values = NULL; + long value = 0; value_count(a, &count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = grib_unpack_long(a, values, &size2); } else { err = grib_unpack_long(a, &value, &size2); @@ -677,14 +677,14 @@ static int is_missing(grib_accessor* a) } } else if (ktype == GRIB_TYPE_DOUBLE) { - double value = 0; - double* values = NULL; + double value = 0; + double* values = NULL; value_count(a, &count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = grib_unpack_double(a, values, &size2); } else { err = grib_unpack_double(a, &value, &size2); @@ -705,7 +705,7 @@ static int is_missing(grib_accessor* a) } } else if (ktype == GRIB_TYPE_STRING) { - char** values = NULL; + char** values = NULL; value_count(a, &count); size = count; if (size > 1) { From e434cdc19eadc91adacb9ba929b57ed14764cd81 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 21 Feb 2024 15:17:13 +0000 Subject: [PATCH 049/156] Dead code removal --- src/{ => deprecated}/grib_concept_index.cc | 0 .../grib_expression_class_constant.cc | 8 +-- .../grib_loader_from_array.cc | 0 src/grib_api_internal.h | 58 +++++++++---------- src/grib_expression_class.h | 2 - src/grib_expression_factory.h | 2 - 6 files changed, 28 insertions(+), 42 deletions(-) rename src/{ => deprecated}/grib_concept_index.cc (100%) rename src/{ => deprecated}/grib_loader_from_array.cc (100%) diff --git a/src/grib_concept_index.cc b/src/deprecated/grib_concept_index.cc similarity index 100% rename from src/grib_concept_index.cc rename to src/deprecated/grib_concept_index.cc diff --git a/src/deprecated/grib_expression_class_constant.cc b/src/deprecated/grib_expression_class_constant.cc index e669a6049..bedacd013 100644 --- a/src/deprecated/grib_expression_class_constant.cc +++ b/src/deprecated/grib_expression_class_constant.cc @@ -17,7 +17,7 @@ CLASS = expression IMPLEMENTS = destroy IMPLEMENTS = native_type - IMPLEMENTS = evaluate;print + IMPLEMENTS = print IMPLEMENTS = add_dependency MEMBERS = long value END_CLASS_DEF @@ -78,12 +78,6 @@ static void init_class(grib_expression_class* c) } /* END_CLASS_IMP */ -static long evaluate(grib_expression* g, grib_handle* h) -{ - const grib_expression_constant* e = (grib_expression_constant*)g; - return e->value; -} - static void print(grib_context* c, grib_expression* g, grib_handle* f) { const grib_expression_constant* e = (grib_expression_constant*)g; diff --git a/src/grib_loader_from_array.cc b/src/deprecated/grib_loader_from_array.cc similarity index 100% rename from src/grib_loader_from_array.cc rename to src/deprecated/grib_loader_from_array.cc diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 0b516c99b..3e7370f36 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1225,41 +1225,37 @@ struct grib_fieldset /* concept index structures */ -typedef struct grib_concept_index_key grib_concept_index_key; -typedef struct grib_concept_index grib_concept_index; -typedef struct grib_conditions_tree grib_conditions_tree; -typedef struct grib_concept_entry grib_concept_entry; -typedef struct grib_concept_key grib_concept_key; +//typedef struct grib_concept_index_key grib_concept_index_key; +//typedef struct grib_concept_index grib_concept_index; +//typedef struct grib_conditions_tree grib_conditions_tree; +//typedef struct grib_concept_entry grib_concept_entry; +//typedef struct grib_concept_key grib_concept_key; -struct grib_concept_index_entry -{ - char* name; - char* value; - int type; - grib_concept_entry* next; -}; +// struct grib_concept_index_entry { +// char* name; +// char* value; +// int type; +// grib_concept_entry* next; +// }; -struct grib_concept_index_key -{ - char* name; - int type; - grib_concept_key* next; -}; +// struct grib_concept_index_key { +// char* name; +// int type; +// grib_concept_key* next; +// }; -struct grib_concept_index -{ - grib_context* context; - grib_concept_key* keys; - grib_conditions_tree* conditions; -}; +// struct grib_concept_index { +// grib_context* context; +// grib_concept_key* keys; +// grib_conditions_tree* conditions; +// }; -struct grib_conditions_tree -{ - char* value; - void* object; - grib_conditions_tree* next; - grib_conditions_tree* next_key; -}; +// struct grib_conditions_tree { +// char* value; +// void* object; +// grib_conditions_tree* next; +// grib_conditions_tree* next_key; +// }; /* support for in-memory definition and tables */ diff --git a/src/grib_expression_class.h b/src/grib_expression_class.h index 6856b1b06..8660a7864 100644 --- a/src/grib_expression_class.h +++ b/src/grib_expression_class.h @@ -1,8 +1,6 @@ /* This file is automatically generated by ./make_class.pl, do not edit */ extern grib_expression_class* grib_expression_class_accessor; extern grib_expression_class* grib_expression_class_binop; -extern grib_expression_class* grib_expression_class_column; -extern grib_expression_class* grib_expression_class_constant; extern grib_expression_class* grib_expression_class_double; extern grib_expression_class* grib_expression_class_functor; extern grib_expression_class* grib_expression_class_is_in_dict; diff --git a/src/grib_expression_factory.h b/src/grib_expression_factory.h index 0f5cd83bb..7cacd3ac1 100644 --- a/src/grib_expression_factory.h +++ b/src/grib_expression_factory.h @@ -1,8 +1,6 @@ /* This file is automatically generated by ./make_class.pl, do not edit */ { "accessor", &grib_expression_class_accessor, }, { "binop", &grib_expression_class_binop, }, -{ "column", &grib_expression_class_column, }, -{ "constant", &grib_expression_class_constant, }, { "double", &grib_expression_class_double, }, { "functor", &grib_expression_class_functor, }, { "is_in_dict", &grib_expression_class_is_in_dict, }, From 304a2be6a0a61c08eff56d5fcfee61420bc233f8 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Thu, 22 Feb 2024 08:21:58 +0000 Subject: [PATCH 050/156] ECC-1771: Fix static member initialisation --- src/step_unit.cc | 6 ++---- src/step_unit.h | 17 +++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/step_unit.cc b/src/step_unit.cc index bd192a6e7..a842430f2 100644 --- a/src/step_unit.cc +++ b/src/step_unit.cc @@ -12,8 +12,6 @@ namespace eccodes { -Unit::Map Unit::map_{}; - std::vector Unit::grib_selected_units = { Unit::Value::SECOND, Unit::Value::MINUTE, @@ -39,7 +37,7 @@ std::vector Unit::complete_unit_order_ = { }; template <> long Unit::value() const { - return map_.unit_to_long(internal_value_); + return get_converter().unit_to_long(internal_value_); } template <> Unit::Value Unit::value() const { @@ -47,7 +45,7 @@ template <> Unit::Value Unit::value() const { } template <> std::string Unit::value() const { - return map_.unit_to_name(internal_value_); + return get_converter().unit_to_name(internal_value_); } } // namespace eccodes diff --git a/src/step_unit.h b/src/step_unit.h index bd078f403..0d6bc4e4e 100644 --- a/src/step_unit.h +++ b/src/step_unit.h @@ -68,7 +68,7 @@ public: explicit Unit(const std::string& unit_value) { try { - internal_value_ = map_.name_to_unit(unit_value); + internal_value_ = get_converter().name_to_unit(unit_value); } catch (std::exception& e) { throw std::runtime_error(std::string{"Unit not found "} + e.what()); } @@ -76,15 +76,15 @@ public: explicit Unit(long unit_value) { try { - internal_value_ = map_.long_to_unit(unit_value); + internal_value_ = get_converter().long_to_unit(unit_value); } catch (std::exception& e) { throw std::runtime_error(std::string{"Unit not found "} + e.what()); } } - bool operator>(const Unit& other) const {return map_.unit_to_duration(internal_value_) > map_.unit_to_duration(other.internal_value_);} - bool operator==(const Value value) const {return map_.unit_to_duration(internal_value_) == map_.unit_to_duration(value);} - bool operator==(const Unit& unit) const {return map_.unit_to_duration(internal_value_) == map_.unit_to_duration(unit.internal_value_);} + bool operator>(const Unit& other) const {return get_converter().unit_to_duration(internal_value_) > get_converter().unit_to_duration(other.internal_value_);} + bool operator==(const Value value) const {return get_converter().unit_to_duration(internal_value_) == get_converter().unit_to_duration(value);} + bool operator==(const Unit& unit) const {return get_converter().unit_to_duration(internal_value_) == get_converter().unit_to_duration(unit.internal_value_);} bool operator!=(const Unit& unit) const {return !(*this == unit);} bool operator!=(const Value value) const {return !(*this == value);} @@ -177,13 +177,14 @@ private: Value internal_value_; - static Map map_; public: - static Map& get_converter() {return map_;} + static Map& get_converter() { + static Map map_; + return map_; + } }; - template Seconds to_seconds(long value, const Unit& unit) { Seconds seconds; From c7a67156d38db6424f3b7dbe484ee63074c2d16b Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 15:52:32 +0000 Subject: [PATCH 051/156] Dead code removal --- src/grib_api_internal.h | 122 +++++++++++++--------------------------- 1 file changed, 39 insertions(+), 83 deletions(-) diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 3e7370f36..7f0398065 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -258,8 +258,7 @@ typedef struct string_feed string_feed; typedef struct codes_condition codes_condition; -/* typedef void (*dynamic_key_proc) (const char*, void*) -*/ +/* typedef void (*dynamic_key_proc) (const char*, void*) */ typedef void (*nearest_init_class_proc)(grib_nearest_class*); typedef int (*nearest_init_proc)(grib_nearest* i, grib_handle*, grib_arguments*); @@ -369,14 +368,12 @@ struct second_order_packed /** * an grib_compression * Structure supporting the packing and unpacking procedures -* -* @see grib_action_create_data */ struct grib_packer { const char* name; - grib_pack_proc pack; /** < packing procedure */ - grib_unpack_proc unpack; /** < unpacking procedure */ + grib_pack_proc pack; /** < packing procedure */ + grib_unpack_proc unpack; /** < unpacking procedure */ }; /* --------------- */ @@ -394,7 +391,7 @@ struct grib_loader }; /** -* an action +* An action * Structure supporting the creation of accessor, resulting of a statement during a definition file parsing * * @see grib_action_class @@ -437,7 +434,7 @@ typedef grib_action* (*action_reparse_proc)(grib_action* a, grib_accessor*, int* typedef int (*action_execute_proc)(grib_action* a, grib_handle*); /** -* an action_class +* An action_class * Structure supporting the specific behaviour of an action * * @see grib_action @@ -464,22 +461,22 @@ struct grib_action_class }; /** -* a buffer +* A buffer * Structure containing the data of a message */ struct grib_buffer { - int property; /** < property parameter of buffer */ - int validity; /** < validity parameter of buffer */ - int growable; /** < buffer can be grown */ - size_t length; /** < Buffer length */ - size_t ulength; /** < length used of the buffer */ - size_t ulength_bits; /** < length used of the buffer in bits */ - unsigned char* data; /** < the data byte array */ + int property; /** < property parameter of buffer */ + int validity; /** < validity parameter of buffer */ + int growable; /** < buffer can be grown */ + size_t length; /** < Buffer length */ + size_t ulength; /** < length used of the buffer */ + size_t ulength_bits; /** < length used of the buffer in bits */ + unsigned char* data; /** < the data byte array */ }; /** -* an Accessor +* An accessor * Structure supporting each single data unit and allowing its access * @see grib_accessor_class */ @@ -500,18 +497,18 @@ struct grib_virtual_value struct grib_accessor { - const char* name; /** < name of the accessor */ - const char* name_space; /** < namespace to which the accessor belongs */ + const char* name; /** < name of the accessor */ + const char* name_space; /** < namespace to which the accessor belongs */ grib_context* context; grib_handle* h; - grib_action* creator; /** < action that created the accessor */ - long length; /** < byte length of the accessor */ - long offset; /** < offset of the data in the buffer */ - grib_section* parent; /** < section to which the accessor is attached */ - grib_accessor* next; /** < next accessor in list */ - grib_accessor* previous; /** < next accessor in list */ - grib_accessor_class* cclass; /** < behaviour of the accessor */ - unsigned long flags; /** < Various flags */ + grib_action* creator; /** < action that created the accessor */ + long length; /** < byte length of the accessor */ + long offset; /** < offset of the data in the buffer */ + grib_section* parent; /** < section to which the accessor is attached */ + grib_accessor* next; /** < next accessor in list */ + grib_accessor* previous; /** < next accessor in list */ + grib_accessor_class* cclass; /** < behaviour of the accessor */ + unsigned long flags; /** < Various flags */ grib_section* sub_section; const char* all_names[MAX_ACCESSOR_NAMES]; /** < name of the accessor */ @@ -547,7 +544,7 @@ struct grib_accessor #define GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION (1 << 19) /** -* a section accessor +* A section accessor * Structure supporting hierarchical naming of the accessors * @see grib_accessor */ @@ -555,9 +552,9 @@ struct grib_section { grib_accessor* owner; grib_handle* h; /** < Handles of all accessors and buffer */ - grib_accessor* aclength; /** < block of the length of the block */ - grib_block_of_accessors* block; /** < block */ - grib_action* branch; /** < branch that created the block */ + grib_accessor* aclength; /** < block of the length of the block */ + grib_block_of_accessors* block; /** < block */ + grib_action* branch; /** < branch that created the block */ size_t length; size_t padding; }; @@ -640,18 +637,18 @@ struct grib_dumper_class struct grib_iterator { - grib_arguments* args; /** args of iterator */ + grib_arguments* args; /** args of iterator */ grib_handle* h; - long e; /** current element */ - size_t nv; /** number of values */ - double* data; /** data values */ + long e; /** current element */ + size_t nv; /** number of values */ + double* data; /** data values */ grib_iterator_class* cclass; unsigned long flags; }; struct grib_nearest { - grib_arguments* args; /** args of iterator */ + grib_arguments* args; /** args of iterator */ grib_handle* h; grib_context* context; double* values; @@ -823,8 +820,8 @@ void codes_assertion_failed(const char* message, const char* file, int line); struct grib_handle { - grib_context* context; /** < context attached to this handle */ - grib_buffer* buffer; /** < buffer attached to the handle */ + grib_context* context; /** < context attached to this handle */ + grib_buffer* buffer; /** < buffer attached to the handle */ grib_section* root; /** the root section*/ grib_section* rules; /** the rules section*/ grib_dependency* dependencies; /** List of dependencies */ @@ -853,13 +850,12 @@ struct grib_handle /* For GRIB2 multi-field messages */ struct grib_multi_handle { - grib_context* context; /** < context attached to this handle */ - grib_buffer* buffer; /** < buffer attached to the handle */ + grib_context* context; /** < context attached to this handle */ + grib_buffer* buffer; /** < buffer attached to the handle */ size_t offset; size_t length; }; - struct grib_accessor_class { grib_accessor_class** super; @@ -1094,7 +1090,6 @@ struct grib_expression_class expression_init_proc init; expression_destroy_proc destroy; - expression_print_proc print; expression_add_dependency_proc add_dependency; @@ -1106,7 +1101,6 @@ struct grib_expression_class expression_evaluate_string_proc evaluate_string; }; - struct grib_arguments { struct grib_arguments* next; @@ -1223,40 +1217,6 @@ struct grib_fieldset grib_field** fields; }; -/* concept index structures */ - -//typedef struct grib_concept_index_key grib_concept_index_key; -//typedef struct grib_concept_index grib_concept_index; -//typedef struct grib_conditions_tree grib_conditions_tree; -//typedef struct grib_concept_entry grib_concept_entry; -//typedef struct grib_concept_key grib_concept_key; - -// struct grib_concept_index_entry { -// char* name; -// char* value; -// int type; -// grib_concept_entry* next; -// }; - -// struct grib_concept_index_key { -// char* name; -// int type; -// grib_concept_key* next; -// }; - -// struct grib_concept_index { -// grib_context* context; -// grib_concept_key* keys; -// grib_conditions_tree* conditions; -// }; - -// struct grib_conditions_tree { -// char* value; -// void* object; -// grib_conditions_tree* next; -// grib_conditions_tree* next_key; -// }; - /* support for in-memory definition and tables */ extern int codes_memfs_exists(const char* path); @@ -1297,7 +1257,6 @@ struct grib_field_list grib_field_list* next; }; - struct grib_index { grib_context* context; @@ -1384,10 +1343,8 @@ struct bufr_keys_iterator grib_trie* seen; }; -/* ----------*/ -/* md5 */ +/* --------- md5 --------*/ typedef unsigned long cvs_uint32; - struct cvs_MD5Context { cvs_uint32 buf[4]; @@ -1421,7 +1378,6 @@ struct grib_case }; /* ----------*/ - typedef struct code_table_entry { char* abbreviation; @@ -1440,7 +1396,7 @@ struct grib_codetable typedef struct grib_smart_table_entry { - /*int code;*/ + /*int code;*/ char* abbreviation; char* column[MAX_SMART_TABLE_COLUMNS]; } grib_smart_table_entry; From 5eaa3aa84c5a5db6dd6abe5dfc33ac12d2efa67b Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 15:52:42 +0000 Subject: [PATCH 052/156] grib_concept_index --- src/deprecated/grib_concept_index.cc | 73 ++++++++++++++++++---------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/deprecated/grib_concept_index.cc b/src/deprecated/grib_concept_index.cc index 9cb8f0d1d..8ca1794a4 100644 --- a/src/deprecated/grib_concept_index.cc +++ b/src/deprecated/grib_concept_index.cc @@ -1,30 +1,49 @@ -/* - * (C) Copyright 2005- ECMWF. - * - * This software is licensed under the terms of the Apache Licence Version 2.0 - * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. - * - * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by - * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. - */ - -/* - * Description: concept index - * - */ - #include "grib_api_internal.h" +typedef struct grib_concept_index_keys grib_concept_index_keys; +typedef struct grib_concept_index grib_concept_index; +typedef struct grib_conditions_tree grib_conditions_tree; +typedef struct grib_concept_index_entry grib_concept_index_entry; +typedef struct grib_concept_index_keys grib_concept_index_keys; + +struct grib_concept_index_entry { + char* name; + char* value; + int type; + grib_concept_index_entry* next; +}; + +struct grib_concept_index_keys { + char* name; + int type; + grib_concept_index_keys* next; +}; + +struct grib_concept_index { + grib_context* context; + grib_concept_index_keys* keys; + grib_conditions_tree* conditions; +}; + +struct grib_conditions_tree { + char* value; + void* object; + grib_conditions_tree* next; + grib_conditions_tree* next_key; +}; + + static grib_concept_index_entry* index_entry_new(grib_context* c, grib_concept_index_keys* keys) { grib_concept_index_entry* entry = NULL; + grib_concept_index_entry* e; Assert(keys); if (!c) c = grib_context_get_default(); - entry = grib_context_malloc_clear(c, sizeof(grib_concept_index_entry)); + entry = (grib_concept_index_entry*)grib_context_malloc_clear(c, sizeof(grib_concept_index_entry)); if (!entry) grib_context_log(c, GRIB_LOG_FATAL, "grib_concept_index_entry unable to allocate"); e = entry; @@ -32,7 +51,7 @@ static grib_concept_index_entry* index_entry_new(grib_context* c, grib_concept_i while (keys && keys->name) { e->name = grib_context_strdup(c, keys->name); e->type = keys->type; - e->next = grib_context_malloc_clear(c, sizeof(grib_concept_index_entry)); + e->next = (grib_concept_index_entry*)grib_context_malloc_clear(c, sizeof(grib_concept_index_entry)); if (!e->next) grib_context_log(c, GRIB_LOG_FATAL, "grib_concept_index_entry unable to allocate"); @@ -65,17 +84,17 @@ static int index_insert_entry(grib_concept_index* index, grib_concept_index_entr while (keys->name) { if (!cur) { - cur = grib_context_malloc_clear_persistent(index->context, sizeof(grib_conditions_tree)); + cur = (grib_conditions_tree*)grib_context_malloc_clear_persistent(index->context, sizeof(grib_conditions_tree)); if (!cur) grib_context_log(index->context, GRIB_LOG_FATAL, "index_insert_entry unable to allocate"); prev->next = cur; } - value = entry->value ? entry->value : "*"; + char* value = entry->value ? entry->value : (char*)"*"; while (cur && (!cur->value || (found = !strcmp(cur->value, value)) == 0)) cur = cur->next; if (!found) { - cur->next = grib_context_malloc_clear_persistent(index->context, sizeof(grib_conditions_tree)); + cur->next = (grib_conditions_tree*)grib_context_malloc_clear_persistent(index->context, sizeof(grib_conditions_tree)); Assert(cur->next); cur = cur->next; } @@ -103,6 +122,9 @@ static void index_add_conditions(grib_concept_index* index, grib_concept_conditi char s[512] = {0,}; grib_concept_index_entry* e; grib_concept_index_entry* entry = index_entry_new(index->context, index->keys); + long lres; + double dres; + int err = 0; while (c) { size_t size = 512; @@ -136,7 +158,7 @@ static void index_add_conditions(grib_concept_index* index, grib_concept_conditi e->value = grib_context_strdup(index->context, s); if (!e->name) { e->name = grib_context_strdup(index->context, c->name); - e->next = grib_context_malloc_clear_persistent(index->context, sizeof(grib_concept_index_entry)); + e->next = (grib_concept_index_entry*)grib_context_malloc_clear_persistent(index->context, sizeof(grib_concept_index_entry)); if (!e->next) grib_context_log(index->context, GRIB_LOG_FATAL, "index_add_conditions unable to allocate"); } @@ -156,14 +178,13 @@ grib_concept_index* grib_concept_index_new_from_concept(grib_context* c, grib_co if (!c) c = grib_context_get_default(); - index = grib_context_malloc_clear_persistent(c, sizeof(grib_concept_index)); - index->keys = grib_context_malloc_clear_persistent(c, sizeof(grib_concept_index_key)); - index->conditions = grib_context_malloc_clear_persistent(c, sizeof(grib_conditions_tree)); - index->conditions = grib_context_malloc_clear_persistent(c, sizeof(grib_conditions_tree)); + index = (grib_concept_index*)grib_context_malloc_clear_persistent(c, sizeof(grib_concept_index)); + index->keys = (grib_concept_index_keys*)grib_context_malloc_clear_persistent(c, sizeof(grib_concept_index_keys)); + index->conditions = (grib_conditions_tree*)grib_context_malloc_clear_persistent(c, sizeof(grib_conditions_tree)); index->context = c; while (concept) { - index_add_conditions(index, concept->conditions, err); + index_add_conditions(index, concept->conditions); concept = concept->next; } From 4872b51e110824474452b8aeb7e96afd13eb2ce2 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 16:27:05 +0000 Subject: [PATCH 053/156] GitHub nightly: netcdf4 module --- .github/ci-nightly-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ci-nightly-test.sh b/.github/ci-nightly-test.sh index d0b206c7c..4eb4a54a9 100644 --- a/.github/ci-nightly-test.sh +++ b/.github/ci-nightly-test.sh @@ -8,7 +8,7 @@ module unload ecmwf-toolbox module load cdo/new module load numdiff module load nccmp -module load netcdf4/new +module load netcdf4 module load gnuparallel/new module load python3 From a0e3cc1a8f23b424ad1f2a746ba0f504c19855d5 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 16:31:27 +0000 Subject: [PATCH 054/156] GitHub nightly: netcdf4 module fix --- .github/ci-hpc-config.yml | 2 +- .github/workflows/reusable-ci-hpc.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ci-hpc-config.yml b/.github/ci-hpc-config.yml index 801481f83..3ae75ea37 100644 --- a/.github/ci-hpc-config.yml +++ b/.github/ci-hpc-config.yml @@ -3,7 +3,7 @@ build: - ecbuild - ninja - aec - - netcdf4/new + - netcdf4 parallel: 64 cmake_options: - -DENABLE_EXTRA_TESTS=1 diff --git a/.github/workflows/reusable-ci-hpc.yml b/.github/workflows/reusable-ci-hpc.yml index 793f26ebe..1176afc9d 100644 --- a/.github/workflows/reusable-ci-hpc.yml +++ b/.github/workflows/reusable-ci-hpc.yml @@ -23,7 +23,7 @@ jobs: ecbuild ninja aec - netcdf4/new + netcdf4 --parallel: 64 --cmake-options: | -DENABLE_EXTRA_TESTS=1 From 7b36814d1136cbbe4e2157e4d2288da8f34f9cbd Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 17:36:39 +0000 Subject: [PATCH 055/156] Testing: codes_get_string for different products --- src/grib_accessor_class_message.cc | 2 +- tests/codes_get_string.cc | 13 +++++++++---- tests/codes_get_string.sh | 14 +++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/grib_accessor_class_message.cc b/src/grib_accessor_class_message.cc index 8dd580d3e..6c5587b22 100644 --- a/src/grib_accessor_class_message.cc +++ b/src/grib_accessor_class_message.cc @@ -142,7 +142,7 @@ static int value_count(grib_accessor* a, long* count) static int unpack_string(grib_accessor* a, char* val, size_t* len) { long i = 0; - size_t l = a->length + 1; + size_t l = string_length(a) + 1; grib_handle* h = grib_handle_of_accessor(a); if (*len < l) { diff --git a/tests/codes_get_string.cc b/tests/codes_get_string.cc index d0cf15192..db98de25e 100644 --- a/tests/codes_get_string.cc +++ b/tests/codes_get_string.cc @@ -18,15 +18,20 @@ int main(int argc, char* argv[]) size_t len = 0; int err = 0; - assert(argc == 3); + assert(argc == 4); - const char* infile = argv[1]; + const char* prod = argv[1]; + const char* infile = argv[2]; FILE* in = fopen(infile, "rb"); assert(in); - char* key = argv[2]; + char* key = argv[3]; char kvalue[2] = {0,}; // deliberately short + ProductKind productKind = PRODUCT_GRIB; + if (strcmp(prod, "BUFR")==0) productKind = PRODUCT_BUFR; + if (strcmp(prod, "GTS")==0) productKind = PRODUCT_GTS; + if (strcmp(prod, "ANY")==0) productKind = PRODUCT_ANY; - h = codes_handle_new_from_file(NULL, in, PRODUCT_ANY, &err); + h = codes_handle_new_from_file(NULL, in, productKind, &err); assert(h); assert(!err); diff --git a/tests/codes_get_string.sh b/tests/codes_get_string.sh index 011224253..a42ef9f97 100755 --- a/tests/codes_get_string.sh +++ b/tests/codes_get_string.sh @@ -15,29 +15,33 @@ tempGrib=temp.$label.grib tempText=temp.$label.txt input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl -$EXEC ${test_dir}/codes_get_string $input dataDate +$EXEC ${test_dir}/codes_get_string GRIB $input dataDate ${tools_dir}/grib_set -s marsType=s3,marsStream=mpic $input $tempGrib -$EXEC ${test_dir}/codes_get_string $tempGrib dayOfTheYearDate # 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB $tempGrib dayOfTheYearDate # 2> $tempText input=$data_dir/reduced_latlon_surface.grib2 keys="identifier projString bitmap class year gridDefinitionDescription time validityTime packingType md5Headers parameterUnits" for k in $keys; do - $EXEC ${test_dir}/codes_get_string $input $k 2> $tempText + $EXEC ${test_dir}/codes_get_string GRIB $input $k 2> $tempText grep -q "Buffer too small" $tempText done input=$ECCODES_SAMPLES_PATH/reduced_gg_ml_grib2.tmpl -$EXEC ${test_dir}/codes_get_string "$input" gridName 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB "$input" gridName 2> $tempText grep -q "Buffer too small" $tempText # shortName = swh input=$data_dir/reduced_latlon_surface.grib1 -$EXEC ${test_dir}/codes_get_string "$input" shortName 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB "$input" shortName 2> $tempText grep -q "Buffer too small" $tempText +input=$data_dir/gts/EGRR20150317121020_00493212.DAT +$EXEC ${test_dir}/codes_get_string GTS "$input" theMessage 2> $tempText +grep -q "Buffer too small" $tempText +# Clean up rm -f $tempText From adc912850bf6de6d4e5db0d8b6cb2cf389cf721d Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 19:33:02 +0000 Subject: [PATCH 056/156] Testing: Variables like constants and transients --- src/grib_accessor_class_variable.cc | 6 ++++++ tests/codes_compare_keys.sh | 4 ++++ tests/codes_get_string.sh | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/grib_accessor_class_variable.cc b/src/grib_accessor_class_variable.cc index 9d12e04cf..6a39d34df 100644 --- a/src/grib_accessor_class_variable.cc +++ b/src/grib_accessor_class_variable.cc @@ -126,6 +126,12 @@ grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variab /* END_CLASS_IMP */ +// +// This accessor is used for: +// constant +// transient +// + #define MAX_VARIABLE_STRING_LENGTH 255 static void init(grib_accessor* a, const long length, grib_arguments* args) diff --git a/tests/codes_compare_keys.sh b/tests/codes_compare_keys.sh index 9a2a39aef..1a678ede8 100755 --- a/tests/codes_compare_keys.sh +++ b/tests/codes_compare_keys.sh @@ -68,6 +68,9 @@ diff $tempRef $tempLog sample_spectral=$ECCODES_SAMPLES_PATH/sh_ml_grib2.tmpl ${test_dir}/codes_compare_keys $sample_spectral $sample_spectral enorm,avg +# Do some constant and transient keys +${test_dir}/codes_compare_keys $sample_spectral $sample_spectral marsDir,truncateLaplacian + # Local definitions # ---------------------- @@ -82,6 +85,7 @@ status=$? set -e [ $status -ne 0 ] grep -q "2 differences" $tempLog + rm -f $tempGribA $tempGribB diff --git a/tests/codes_get_string.sh b/tests/codes_get_string.sh index a42ef9f97..188c81a3e 100755 --- a/tests/codes_get_string.sh +++ b/tests/codes_get_string.sh @@ -22,7 +22,7 @@ $EXEC ${test_dir}/codes_get_string GRIB $tempGrib dayOfTheYearDate # 2> $tempTex input=$data_dir/reduced_latlon_surface.grib2 -keys="identifier projString bitmap class year gridDefinitionDescription +keys="hundred identifier projString bitmap class year gridDefinitionDescription time validityTime packingType md5Headers parameterUnits" for k in $keys; do $EXEC ${test_dir}/codes_get_string GRIB $input $k 2> $tempText From 0e0f204d82f80d2094d3d4d1e405776465b78b1a Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 20:41:03 +0000 Subject: [PATCH 057/156] Const correctness and cppcheck warnings --- src/grib_accessor_class_variable.cc | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/grib_accessor_class_variable.cc b/src/grib_accessor_class_variable.cc index 6a39d34df..13b31706b 100644 --- a/src/grib_accessor_class_variable.cc +++ b/src/grib_accessor_class_variable.cc @@ -186,7 +186,7 @@ void accessor_variable_set_type(grib_accessor* a, int type) static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; switch (self->type) { case GRIB_TYPE_DOUBLE: grib_dump_double(dumper, a, NULL); @@ -261,7 +261,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) static int unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); @@ -275,7 +275,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) static int unpack_float(grib_accessor* a, float* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); @@ -289,7 +289,7 @@ static int unpack_float(grib_accessor* a, float* val, size_t* len) static int unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); @@ -303,7 +303,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) static int get_native_type(grib_accessor* a) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; return self->type; } @@ -356,7 +356,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) static int pack_string(grib_accessor* a, const char* val, size_t* len) { grib_accessor_variable* self = (grib_accessor_variable*)a; - grib_context* c = a->context; + const grib_context* c = a->context; grib_context_free(c, self->cval); self->cval = grib_context_strdup(c, val); @@ -375,7 +375,7 @@ static int value_count(grib_accessor* a, long* count) static size_t string_length(grib_accessor* a) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable* self = (grib_accessor_variable*)a; if (self->type == GRIB_TYPE_STRING) return strlen(self->cval); else @@ -389,7 +389,7 @@ static long byte_count(grib_accessor* a) static int compare(grib_accessor* a, grib_accessor* b) { - int retval = 0; + int retval = GRIB_SUCCESS; double* aval = 0; double* bval = 0; @@ -418,10 +418,9 @@ static int compare(grib_accessor* a, grib_accessor* b) grib_unpack_double(b, bval, &blen); retval = GRIB_SUCCESS; - while (alen != 0) { - if (*bval != *aval) - retval = GRIB_DOUBLE_VALUE_MISMATCH; - alen--; + retval = GRIB_SUCCESS; + for (size_t i=0; icontext, aval); @@ -432,13 +431,13 @@ static int compare(grib_accessor* a, grib_accessor* b) static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) { - grib_accessor* the_clone = NULL; - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor* the_clone = NULL; + const grib_accessor_variable* self = (grib_accessor_variable*)a; grib_accessor_variable* variableAccessor = NULL; - grib_action creator = {0,}; - creator.op = (char*)"variable"; + grib_action creator = {0,}; + creator.op = (char*)"variable"; creator.name_space = (char*)""; - creator.set = 0; + creator.set = 0; creator.name = grib_context_strdup(a->context, a->name); the_clone = grib_accessor_factory(s, &creator, 0, NULL); From b8a92c83d91d5659bc9f1add21a7972315d32103 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Feb 2024 11:21:58 +0000 Subject: [PATCH 058/156] ECC-1685: GRIB2: Correct local ECMWF table entries (code 194) --- definitions/grib2/tables/local/ecmf/1/4.2.0.1.table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/definitions/grib2/tables/local/ecmf/1/4.2.0.1.table b/definitions/grib2/tables/local/ecmf/1/4.2.0.1.table index 5e02901a1..1ee04a741 100644 --- a/definitions/grib2/tables/local/ecmf/1/4.2.0.1.table +++ b/definitions/grib2/tables/local/ecmf/1/4.2.0.1.table @@ -1,7 +1,7 @@ # Code table 4.2 - discipline=0 category=1 for ECMWF 192 192 Snow evaporation rate (kg m-2 s-1) 193 193 Total precipitation rate (m s-1) -194 194 Accumulated freezing rain (m) +194 194 Freezing rain precipitation rate (m s-1) 195 195 Convective precipitation rate (m s-1) 196 196 Large-scale precipitation rate (m s-1) 197 197 Snow evaporation rate (m of water equivalent s-1) From 74c78e1d3dcbcd0f84965afa66539d8c80cf2c63 Mon Sep 17 00:00:00 2001 From: Sebastien Villaume Date: Fri, 23 Feb 2024 11:55:51 +0000 Subject: [PATCH 059/156] ECC-1774 adding MARS system keyword for mmsf/fc and msmm/fcmean --- definitions/mars/grib.mmsf.fc.def | 1 + definitions/mars/grib.msmm.fcmean.def | 1 + 2 files changed, 2 insertions(+) diff --git a/definitions/mars/grib.mmsf.fc.def b/definitions/mars/grib.mmsf.fc.def index f1820336a..c002f9d76 100644 --- a/definitions/mars/grib.mmsf.fc.def +++ b/definitions/mars/grib.mmsf.fc.def @@ -8,6 +8,7 @@ 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; } alias mars.number = perturbationNumber; alias mars.method = methodNumber; diff --git a/definitions/mars/grib.msmm.fcmean.def b/definitions/mars/grib.msmm.fcmean.def index 800a49134..a13ca9918 100644 --- a/definitions/mars/grib.msmm.fcmean.def +++ b/definitions/mars/grib.msmm.fcmean.def @@ -10,6 +10,7 @@ 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; } # See ECC-624 if (centre == 80 && subCentre == 98 && class is "c3") { From e1eba0471a3548a67187e45f4136aeb3e2007ad3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Feb 2024 14:28:08 +0000 Subject: [PATCH 060/156] Dead code removal --- src/action_class_hash_array.cc | 47 ++++++++++++++++------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/action_class_hash_array.cc b/src/action_class_hash_array.cc index b01077870..609e763f2 100644 --- a/src/action_class_hash_array.cc +++ b/src/action_class_hash_array.cc @@ -168,13 +168,14 @@ grib_action* grib_action_create_hash_array(grib_context* context, a->hash_array = hash_array; if (hash_array) { - grib_hash_array_value* ha = hash_array; - grib_trie* index = grib_trie_new(context); - while (ha) { - ha->index = index; - grib_trie_insert_no_replace(index, ha->name, ha); - ha = ha->next; - } + grib_context_log(context, GRIB_LOG_FATAL, "%s: 'hash_array_list' not implemented", __func__); + // grib_hash_array_value* ha = hash_array; + // grib_trie* index = grib_trie_new(context); + // while (ha) { + // ha->index = index; + // grib_trie_insert_no_replace(index, ha->name, ha); + // ha = ha->next; + // } } act->name = grib_context_strdup_persistent(context, name); @@ -185,17 +186,12 @@ grib_action* grib_action_create_hash_array(grib_context* context, static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - - for (i = 0; i < lvl; i++) - grib_context_print(act->context, f, " "); - - printf("hash_array(%s) { ", act->name); - printf("\n"); - - for (i = 0; i < lvl; i++) - grib_context_print(act->context, f, " "); - printf("}\n"); + // for (int i = 0; i < lvl; i++) + // grib_context_print(act->context, f, " "); + // printf("hash_array(%s) { \n", act->name); + // for (int i = 0; i < lvl; i++) + // grib_context_print(act->context, f, " "); + // printf("}\n"); } @@ -204,13 +200,14 @@ static void destroy(grib_context* context, grib_action* act) grib_action_hash_array* self = (grib_action_hash_array*)act; grib_hash_array_value* v = self->hash_array; - if (v) - grib_trie_delete(v->index); - while (v) { - grib_hash_array_value* n = v->next; - grib_hash_array_value_delete(context, v); - v = n; - } + Assert(!v); // not implemented + // if (v) + // grib_trie_delete(v->index); + // while (v) { + // grib_hash_array_value* n = v->next; + // grib_hash_array_value_delete(context, v); + // v = n; + // } grib_context_free_persistent(context, self->masterDir); grib_context_free_persistent(context, self->localDir); From 94a306485496187717bb75acb2500608fe642bf3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Feb 2024 14:28:21 +0000 Subject: [PATCH 061/156] Debug messages --- src/grib_context.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/grib_context.cc b/src/grib_context.cc index 0c1921138..859f1087c 100644 --- a/src/grib_context.cc +++ b/src/grib_context.cc @@ -535,11 +535,10 @@ grib_context* grib_context_get_default() } #endif - grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Definitions path: %s", - default_grib_context.grib_definition_files_path); - grib_context_log(&default_grib_context, GRIB_LOG_DEBUG, "Samples path: %s", - default_grib_context.grib_samples_path); - + if (default_grib_context.debug) { + fprintf(stderr, "ECCODES DEBUG Definitions path: %s\n", default_grib_context.grib_definition_files_path); + fprintf(stderr, "ECCODES DEBUG Samples path: %s\n", default_grib_context.grib_samples_path); + } default_grib_context.keys_count = 0; default_grib_context.keys = grib_hash_keys_new(&(default_grib_context), &(default_grib_context.keys_count)); From 27b7b44eb7235a835fde1de54721a867abfe7c7e Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Feb 2024 15:25:39 +0000 Subject: [PATCH 062/156] Dead code removal --- src/eccodes_prototypes.h | 1 - src/grib_hash_array.cc | 32 ++++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 3537fc05f..1513b01df 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -172,7 +172,6 @@ void grib_concept_condition_delete(grib_context* c, grib_concept_condition* v); /* grib_hash_array.cc*/ grib_hash_array_value* grib_integer_hash_array_value_new(grib_context* c, const char* name, grib_iarray* array); -void grib_hash_array_value_delete(grib_context* c, grib_hash_array_value* v); /* grib_bufr_descriptor.cc*/ bufr_descriptor* grib_bufr_descriptor_new(grib_accessor* tables_accessor, int code, int silent, int* err); diff --git a/src/grib_hash_array.cc b/src/grib_hash_array.cc index 54ba4294f..ec556c904 100644 --- a/src/grib_hash_array.cc +++ b/src/grib_hash_array.cc @@ -30,19 +30,19 @@ grib_hash_array_value* grib_integer_hash_array_value_new(grib_context* c, const // return v; // } -void grib_hash_array_value_delete(grib_context* c, grib_hash_array_value* v) -{ - switch (v->type) { - case GRIB_HASH_ARRAY_TYPE_INTEGER: - grib_iarray_delete(v->iarray); - break; - case GRIB_HASH_ARRAY_TYPE_DOUBLE: - grib_darray_delete(c, v->darray); - break; - default: - grib_context_log(c, GRIB_LOG_ERROR, - "wrong type in grib_hash_array_value_delete"); - } - grib_context_free_persistent(c, v->name); - grib_context_free_persistent(c, v); -} +// void grib_hash_array_value_delete(grib_context* c, grib_hash_array_value* v) +// { +// switch (v->type) { +// case GRIB_HASH_ARRAY_TYPE_INTEGER: +// grib_iarray_delete(v->iarray); +// break; +// case GRIB_HASH_ARRAY_TYPE_DOUBLE: +// grib_darray_delete(c, v->darray); +// break; +// default: +// grib_context_log(c, GRIB_LOG_ERROR, +// "wrong type in grib_hash_array_value_delete"); +// } +// grib_context_free_persistent(c, v->name); +// grib_context_free_persistent(c, v); +// } From be75fa1a7806313c95e10e7a6989c584cf2db823 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Feb 2024 15:58:16 +0000 Subject: [PATCH 063/156] Expressions: Dead code removal --- src/expression.class | 30 +++++++-------------- src/grib_api_internal.h | 1 - src/grib_expression_class_accessor.cc | 27 ++++++------------- src/grib_expression_class_binop.cc | 23 +++++----------- src/grib_expression_class_double.cc | 23 +++++----------- src/grib_expression_class_functor.cc | 21 ++++----------- src/grib_expression_class_is_in_dict.cc | 25 +++++------------ src/grib_expression_class_is_in_list.cc | 27 ++++++------------- src/grib_expression_class_is_integer.cc | 27 ++++++------------- src/grib_expression_class_length.cc | 27 ++++++------------- src/grib_expression_class_logical_and.cc | 24 +++++------------ src/grib_expression_class_logical_or.cc | 24 +++++------------ src/grib_expression_class_long.cc | 23 +++++----------- src/grib_expression_class_string.cc | 21 ++++----------- src/grib_expression_class_string_compare.cc | 23 +++++----------- src/grib_expression_class_sub_string.cc | 21 ++++----------- src/grib_expression_class_true.cc | 23 +++++----------- src/grib_expression_class_unop.cc | 23 +++++----------- 18 files changed, 111 insertions(+), 302 deletions(-) diff --git a/src/expression.class b/src/expression.class index 9c11d39db..64c9a2e70 100644 --- a/src/expression.class +++ b/src/expression.class @@ -1,20 +1,14 @@ typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void init(grib_expression* e); -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void init(grib_expression* e); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_NAME{ grib_expression base; @@ -28,7 +22,6 @@ static grib_expression_class _grib_expression_class_NAME = { "NAME", /* name */ sizeof(grib_expression_NAME),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ &init, /* constructor */ &destroy, /* destructor */ &print, @@ -44,8 +37,3 @@ grib_expression_class* grib_expression_class_NAME = &_grib_expression_class_NAME ADD_TO_FILE grib_expression_class.h extern grib_expression_class* grib_expression_class_NAME; ADD_TO_FILE grib_expression_factory.h { "NAME", &grib_expression_class_NAME, }, - -static void init_class(grib_expression_class* c) -{ -INIT -} diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 7f0398065..e54b76615 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -1086,7 +1086,6 @@ struct grib_expression_class size_t size; int inited; - expression_class_init_proc init_class; expression_init_proc init; expression_destroy_proc destroy; diff --git a/src/grib_expression_class_accessor.cc b/src/grib_expression_class_accessor.cc index 67ffbea9a..39fe4f109 100644 --- a/src/grib_expression_class_accessor.cc +++ b/src/grib_expression_class_accessor.cc @@ -41,20 +41,14 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_accessor{ grib_expression base; @@ -70,7 +64,6 @@ static grib_expression_class _grib_expression_class_accessor = { "accessor", /* name */ sizeof(grib_expression_accessor),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -84,10 +77,6 @@ static grib_expression_class _grib_expression_class_accessor = { grib_expression_class* grib_expression_class_accessor = &_grib_expression_class_accessor; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static const char* get_name(grib_expression* g) diff --git a/src/grib_expression_class_binop.cc b/src/grib_expression_class_binop.cc index e95bebbd3..328bb2ac4 100644 --- a/src/grib_expression_class_binop.cc +++ b/src/grib_expression_class_binop.cc @@ -41,18 +41,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_binop{ grib_expression base; @@ -70,7 +64,6 @@ static grib_expression_class _grib_expression_class_binop = { "binop", /* name */ sizeof(grib_expression_binop),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -84,10 +77,6 @@ static grib_expression_class _grib_expression_class_binop = { grib_expression_class* grib_expression_class_binop = &_grib_expression_class_binop; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_double.cc b/src/grib_expression_class_double.cc index 0c0f87a16..89747194b 100644 --- a/src/grib_expression_class_double.cc +++ b/src/grib_expression_class_double.cc @@ -37,18 +37,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_double{ grib_expression base; @@ -62,7 +56,6 @@ static grib_expression_class _grib_expression_class_double = { "double", /* name */ sizeof(grib_expression_double),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -76,10 +69,6 @@ static grib_expression_class _grib_expression_class_double = { grib_expression_class* grib_expression_class_double = &_grib_expression_class_double; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_functor.cc b/src/grib_expression_class_functor.cc index 16153620d..4664def10 100644 --- a/src/grib_expression_class_functor.cc +++ b/src/grib_expression_class_functor.cc @@ -37,17 +37,11 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); typedef struct grib_expression_functor{ grib_expression base; @@ -62,7 +56,6 @@ static grib_expression_class _grib_expression_class_functor = { "functor", /* name */ sizeof(grib_expression_functor),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -76,10 +69,6 @@ static grib_expression_class _grib_expression_class_functor = { grib_expression_class* grib_expression_class_functor = &_grib_expression_class_functor; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_is_in_dict.cc b/src/grib_expression_class_is_in_dict.cc index 27856cc2d..142287cdc 100644 --- a/src/grib_expression_class_is_in_dict.cc +++ b/src/grib_expression_class_is_in_dict.cc @@ -39,19 +39,13 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_is_in_dict{ grib_expression base; @@ -66,7 +60,6 @@ static grib_expression_class _grib_expression_class_is_in_dict = { "is_in_dict", /* name */ sizeof(grib_expression_is_in_dict),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ 0, /* destructor */ &print, @@ -80,10 +73,6 @@ static grib_expression_class _grib_expression_class_is_in_dict = { grib_expression_class* grib_expression_class_is_in_dict = &_grib_expression_class_is_in_dict; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ diff --git a/src/grib_expression_class_is_in_list.cc b/src/grib_expression_class_is_in_list.cc index 46310bcd3..f5339c309 100644 --- a/src/grib_expression_class_is_in_list.cc +++ b/src/grib_expression_class_is_in_list.cc @@ -40,20 +40,14 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_is_in_list{ grib_expression base; @@ -68,7 +62,6 @@ static grib_expression_class _grib_expression_class_is_in_list = { "is_in_list", /* name */ sizeof(grib_expression_is_in_list),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -82,10 +75,6 @@ static grib_expression_class _grib_expression_class_is_in_list = { grib_expression_class* grib_expression_class_is_in_list = &_grib_expression_class_is_in_list; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ diff --git a/src/grib_expression_class_is_integer.cc b/src/grib_expression_class_is_integer.cc index 460170e6e..e79f6c32c 100644 --- a/src/grib_expression_class_is_integer.cc +++ b/src/grib_expression_class_is_integer.cc @@ -41,20 +41,14 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_is_integer{ grib_expression base; @@ -70,7 +64,6 @@ static grib_expression_class _grib_expression_class_is_integer = { "is_integer", /* name */ sizeof(grib_expression_is_integer),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -84,10 +77,6 @@ static grib_expression_class _grib_expression_class_is_integer = { grib_expression_class* grib_expression_class_is_integer = &_grib_expression_class_is_integer; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static const char* get_name(grib_expression* g) diff --git a/src/grib_expression_class_length.cc b/src/grib_expression_class_length.cc index 23ac0f591..c9e967c77 100644 --- a/src/grib_expression_class_length.cc +++ b/src/grib_expression_class_length.cc @@ -41,20 +41,14 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); -static string get_name(grib_expression* e); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static string get_name(grib_expression* e); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_length{ grib_expression base; @@ -70,7 +64,6 @@ static grib_expression_class _grib_expression_class_length = { "length", /* name */ sizeof(grib_expression_length),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -84,10 +77,6 @@ static grib_expression_class _grib_expression_class_length = { grib_expression_class* grib_expression_class_length = &_grib_expression_class_length; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static const char* get_name(grib_expression* g) diff --git a/src/grib_expression_class_logical_and.cc b/src/grib_expression_class_logical_and.cc index 5cf98db69..9a25e54c1 100644 --- a/src/grib_expression_class_logical_and.cc +++ b/src/grib_expression_class_logical_and.cc @@ -15,7 +15,6 @@ START_CLASS_DEF CLASS = expression - IMPLEMENTS = init_class IMPLEMENTS = destroy IMPLEMENTS = native_type IMPLEMENTS = evaluate_long @@ -39,18 +38,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_logical_and{ grib_expression base; @@ -65,7 +58,6 @@ static grib_expression_class _grib_expression_class_logical_and = { "logical_and", /* name */ sizeof(grib_expression_logical_and),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -79,10 +71,6 @@ static grib_expression_class _grib_expression_class_logical_and = { grib_expression_class* grib_expression_class_logical_and = &_grib_expression_class_logical_and; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_logical_or.cc b/src/grib_expression_class_logical_or.cc index 75c2a6520..212ff3084 100644 --- a/src/grib_expression_class_logical_or.cc +++ b/src/grib_expression_class_logical_or.cc @@ -15,7 +15,6 @@ START_CLASS_DEF CLASS = expression - IMPLEMENTS = init_class IMPLEMENTS = destroy IMPLEMENTS = native_type IMPLEMENTS = evaluate_long @@ -39,18 +38,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_logical_or{ grib_expression base; @@ -65,7 +58,6 @@ static grib_expression_class _grib_expression_class_logical_or = { "logical_or", /* name */ sizeof(grib_expression_logical_or),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -79,10 +71,6 @@ static grib_expression_class _grib_expression_class_logical_or = { grib_expression_class* grib_expression_class_logical_or = &_grib_expression_class_logical_or; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_long.cc b/src/grib_expression_class_long.cc index e2c43b9ce..3b61a83d1 100644 --- a/src/grib_expression_class_long.cc +++ b/src/grib_expression_class_long.cc @@ -37,18 +37,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_long{ grib_expression base; @@ -62,7 +56,6 @@ static grib_expression_class _grib_expression_class_long = { "long", /* name */ sizeof(grib_expression_long),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -76,10 +69,6 @@ static grib_expression_class _grib_expression_class_long = { grib_expression_class* grib_expression_class_long = &_grib_expression_class_long; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_string.cc b/src/grib_expression_class_string.cc index 962afeaf8..79d42e247 100644 --- a/src/grib_expression_class_string.cc +++ b/src/grib_expression_class_string.cc @@ -36,17 +36,11 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_string{ grib_expression base; @@ -60,7 +54,6 @@ static grib_expression_class _grib_expression_class_string = { "string", /* name */ sizeof(grib_expression_string),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -74,10 +67,6 @@ static grib_expression_class _grib_expression_class_string = { grib_expression_class* grib_expression_class_string = &_grib_expression_class_string; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) diff --git a/src/grib_expression_class_string_compare.cc b/src/grib_expression_class_string_compare.cc index 1c6202b23..421669aca 100644 --- a/src/grib_expression_class_string_compare.cc +++ b/src/grib_expression_class_string_compare.cc @@ -38,18 +38,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_string_compare{ grib_expression base; @@ -64,7 +58,6 @@ static grib_expression_class _grib_expression_class_string_compare = { "string_compare", /* name */ sizeof(grib_expression_string_compare),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -78,10 +71,6 @@ static grib_expression_class _grib_expression_class_string_compare = { grib_expression_class* grib_expression_class_string_compare = &_grib_expression_class_string_compare; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ /* Note: A fast cut-down version of strcmp which does NOT return -1 */ diff --git a/src/grib_expression_class_sub_string.cc b/src/grib_expression_class_sub_string.cc index 988a5d0ba..a5a0da732 100644 --- a/src/grib_expression_class_sub_string.cc +++ b/src/grib_expression_class_sub_string.cc @@ -36,17 +36,11 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static string evaluate_string(grib_expression*,grib_handle*,char*,size_t*,int*); typedef struct grib_expression_sub_string{ grib_expression base; @@ -60,7 +54,6 @@ static grib_expression_class _grib_expression_class_sub_string = { "sub_string", /* name */ sizeof(grib_expression_sub_string),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -74,10 +67,6 @@ static grib_expression_class _grib_expression_class_sub_string = { grib_expression_class* grib_expression_class_sub_string = &_grib_expression_class_sub_string; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static const char* evaluate_string(grib_expression* g, grib_handle* h, char* buf, size_t* size, int* err) diff --git a/src/grib_expression_class_true.cc b/src/grib_expression_class_true.cc index a57ce9c60..6b418cb2c 100644 --- a/src/grib_expression_class_true.cc +++ b/src/grib_expression_class_true.cc @@ -36,18 +36,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_true{ grib_expression base; @@ -60,7 +54,6 @@ static grib_expression_class _grib_expression_class_true = { "true", /* name */ sizeof(grib_expression_true),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -74,10 +67,6 @@ static grib_expression_class _grib_expression_class_true = { grib_expression_class* grib_expression_class_true = &_grib_expression_class_true; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) diff --git a/src/grib_expression_class_unop.cc b/src/grib_expression_class_unop.cc index 2abd4dbc9..1f4d6f9d0 100644 --- a/src/grib_expression_class_unop.cc +++ b/src/grib_expression_class_unop.cc @@ -39,18 +39,12 @@ or edit "expression.class" and rerun ./make_class.pl typedef const char* string; /* to keep make_class.pl happy */ - -static void init_class (grib_expression_class*); - -static void destroy(grib_context*,grib_expression* e); - -static void print(grib_context*,grib_expression*,grib_handle*); -static void add_dependency(grib_expression* e, grib_accessor* observer); - -static int native_type(grib_expression*,grib_handle*); - -static int evaluate_long(grib_expression*,grib_handle*,long*); -static int evaluate_double(grib_expression*,grib_handle*,double*); +static void destroy(grib_context*,grib_expression* e); +static void print(grib_context*,grib_expression*,grib_handle*); +static void add_dependency(grib_expression* e, grib_accessor* observer); +static int native_type(grib_expression*,grib_handle*); +static int evaluate_long(grib_expression*,grib_handle*,long*); +static int evaluate_double(grib_expression*,grib_handle*,double*); typedef struct grib_expression_unop{ grib_expression base; @@ -66,7 +60,6 @@ static grib_expression_class _grib_expression_class_unop = { "unop", /* name */ sizeof(grib_expression_unop),/* size of instance */ 0, /* inited */ - &init_class, /* init_class */ 0, /* constructor */ &destroy, /* destructor */ &print, @@ -80,10 +73,6 @@ static grib_expression_class _grib_expression_class_unop = { grib_expression_class* grib_expression_class_unop = &_grib_expression_class_unop; - -static void init_class(grib_expression_class* c) -{ -} /* END_CLASS_IMP */ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) From fad6fa43065c241e4b069df16628f058e54bb8d2 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 18:24:16 +0000 Subject: [PATCH 064/156] Testing: Coverage --- examples/C/grib_multi.c | 6 +++--- tests/grib_util_set_spec2.cc | 2 +- tests/unit_tests.cc | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/C/grib_multi.c b/examples/C/grib_multi.c index 24479075d..617c30a71 100644 --- a/examples/C/grib_multi.c +++ b/examples/C/grib_multi.c @@ -30,12 +30,12 @@ int main(int argc, char** argv) codes_handle* h = NULL; int mcount = 0; + /* turn off support for GRIB2 multi-field messages */ + codes_grib_multi_support_off(NULL); + /* turn on support for GRIB2 multi-field messages */ codes_grib_multi_support_on(NULL); - /* turn off support for GRIB2 multi-field messages */ - /* codes_multi_support_off(NULL); */ - in = fopen(filename, "rb"); if (!in) { fprintf(stderr, "Error: unable to open file %s\n", filename); diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc index 11e86a915..5a0b69264 100644 --- a/tests/grib_util_set_spec2.cc +++ b/tests/grib_util_set_spec2.cc @@ -37,7 +37,7 @@ static grib_handle* test0() // packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES; // packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; - grib_handle* finalh = grib_util_set_spec( + grib_handle* finalh = codes_grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); Assert(err == 0); diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index 539b03873..12e18bd97 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -41,12 +41,23 @@ static void check_float_representation(const double val, const double expected, compare_doubles(out, expected, tolerance); } +static void test_get_package_name() +{ + printf("Running %s ...\n", __func__); + + const char* pn = codes_get_package_name(); + Assert(pn != NULL); + Assert(strlen(pn) > 1); + printf("Package name = %s\n", pn); +} + static void test_get_git_sha1() { printf("Running %s ...\n", __func__); - const char* sha1 = grib_get_git_sha1(); + const char* sha1 = codes_get_git_sha1(); Assert(sha1 != NULL); + printf("Git SHA1 = %s\n", sha1); } static void test_get_build_date() @@ -650,7 +661,7 @@ void test_codes_get_product_name() void test_codes_get_type_name() { printf("Running %s ...\n", __func__); - Assert( STR_EQUAL("long", grib_get_type_name(GRIB_TYPE_LONG)) ); + Assert( STR_EQUAL("long", codes_get_type_name(GRIB_TYPE_LONG)) ); Assert( STR_EQUAL("string", grib_get_type_name(GRIB_TYPE_STRING)) ); Assert( STR_EQUAL("double", grib_get_type_name(GRIB_TYPE_DOUBLE)) ); Assert( STR_EQUAL("bytes", grib_get_type_name(GRIB_TYPE_BYTES)) ); @@ -728,6 +739,7 @@ int main(int argc, char** argv) test_parse_keyval_string(); test_get_git_sha1(); + test_get_package_name(); test_get_build_date(); test_gribex_mode(); test_gts_header_mode(); From 82bc4615ba7ff91d3571c411c81558f785e1b83c Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 19:17:45 +0000 Subject: [PATCH 065/156] Testing: Expressions/functions --- src/eccodes_prototypes.h | 2 -- src/functions.cc | 24 +++++-------- src/grib_accessor_class_group.cc | 60 +++++++++++++------------------- tests/grib_filter.sh | 9 +++++ 4 files changed, 43 insertions(+), 52 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 1513b01df..993074e1d 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1379,8 +1379,6 @@ long grib_op_eq(long a, long b); long grib_op_ne(long a, long b); long grib_op_lt(long a, long b); long grib_op_gt(long a, long b); -long grib_op_and(long a, long b); -long grib_op_or(long a, long b); long grib_op_ge(long a, long b); long grib_op_le(long a, long b); long grib_op_bit(long a, long b); diff --git a/src/functions.cc b/src/functions.cc index 9680d07bd..6c6bba770 100644 --- a/src/functions.cc +++ b/src/functions.cc @@ -27,14 +27,14 @@ long grib_op_gt(long a, long b) { return a > b; } -long grib_op_and(long a, long b) -{ - return a && b; -} -long grib_op_or(long a, long b) -{ - return a || b; -} +// long grib_op_and(long a, long b) +// { +// return a && b; +// } +// long grib_op_or(long a, long b) +// { +// return a || b; +// } long grib_op_ge(long a, long b) { return a >= b; @@ -43,7 +43,6 @@ long grib_op_le(long a, long b) { return a <= b; } - long grib_op_bit(long a, long b) { return a & (1 << b); @@ -52,7 +51,6 @@ long grib_op_bitoff(long a, long b) { return !grib_op_bit(a, b); } - long grib_op_not(long a) { return !a; @@ -61,15 +59,14 @@ long grib_op_neg(long a) { return -a; } - double grib_op_neg_d(double a) { return -a; } +// Note: This is actually 'a' to the power 'b' long grib_op_pow(long a, long b) { - /* Note: This is actually 'a' to the power 'b' */ return codes_power(b, a); } @@ -93,7 +90,6 @@ long grib_op_modulo(long a, long b) { return a % b; } - double grib_op_mul_d(double a, double b) { return a * b; @@ -102,7 +98,6 @@ double grib_op_div_d(double a, double b) { return a / b; } - double grib_op_add_d(double a, double b) { return a + b; @@ -111,7 +106,6 @@ double grib_op_sub_d(double a, double b) { return a - b; } - double grib_op_eq_d(double a, double b) { return a == b; diff --git a/src/grib_accessor_class_group.cc b/src/grib_accessor_class_group.cc index a64362968..df2118bff 100644 --- a/src/grib_accessor_class_group.cc +++ b/src/grib_accessor_class_group.cc @@ -238,42 +238,32 @@ static int unpack_double(grib_accessor* a, double* v, size_t* len) static int compare(grib_accessor* a, grib_accessor* b) { - int retval = 0; - char* aval = 0; - char* bval = 0; - int err = 0; + grib_context_log(a->context, GRIB_LOG_ERROR, "%s:%s not implemented", __func__, a->name); + return GRIB_NOT_IMPLEMENTED; - size_t alen = 0; - size_t blen = 0; - long count = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); - bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - - grib_unpack_string(a, aval, &alen); - grib_unpack_string(b, bval, &blen); - - retval = GRIB_SUCCESS; - if (strcmp(aval, bval)) - retval = GRIB_STRING_VALUE_MISMATCH; - - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); - - return retval; + // int retval = 0; + // char* aval = 0; + // char* bval = 0; + // int err = 0; + // size_t alen = 0; + // size_t blen = 0; + // long count = 0; + // err = grib_value_count(a, &count); + // if (err) return err; + // alen = count; + // err = grib_value_count(b, &count); + // if (err) return err; + // blen = count; + // if (alen != blen) return GRIB_COUNT_MISMATCH; + // aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); + // bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); + // grib_unpack_string(a, aval, &alen); + // grib_unpack_string(b, bval, &blen); + // retval = GRIB_SUCCESS; + // if (strcmp(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; + // grib_context_free(a->context, aval); + // grib_context_free(b->context, bval); + // return retval; } static long next_offset(grib_accessor* a) diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index c932cf026..c8c632f1c 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -491,6 +491,15 @@ echo 'set endStep = 12; write;' | ${tools_dir}/grib_filter -o $tempGrib - $input grib_check_key_equals $tempGrib step 12 grib_check_key_equals $tempGrib forecastTime 12 +# Functions: grib_op_ne_d +# ------------------------ +input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl +cat >$tempFilt < Date: Sat, 24 Feb 2024 20:15:57 +0000 Subject: [PATCH 066/156] Dead code removal --- src/action_class_remove.cc | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/action_class_remove.cc b/src/action_class_remove.cc index 26ab6760b..40f5079a7 100644 --- a/src/action_class_remove.cc +++ b/src/action_class_remove.cc @@ -111,17 +111,13 @@ static void remove_accessor(grib_accessor* a) a->next->previous = a->previous; grib_accessor_delete(s->h->context, a); - - return; } static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) { grib_action_remove* a = (grib_action_remove*)act; - grib_accessor* ga = NULL; - - ga = grib_find_accessor(p->h, grib_arguments_get_name(p->h, a->args, 0)); + grib_accessor* ga = grib_find_accessor(p->h, grib_arguments_get_name(p->h, a->args, 0)); if (ga) { remove_accessor(ga); @@ -134,15 +130,15 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) static void dump(grib_action* act, FILE* f, int lvl) { - grib_action_remove* a = (grib_action_remove*)act; - - int i = 0; - - for (i = 0; i < lvl; i++) - grib_context_print(act->context, f, " "); - - grib_context_print(act->context, f, "remove %s as %s in %s\n", grib_arguments_get_name(0, a->args, 0), act->name, grib_arguments_get_name(0, a->args, 1)); + grib_context_log(act->context, GRIB_LOG_ERROR, "%s: dump not implemented", act->name); + // grib_action_remove* a = (grib_action_remove*)act; + // int i = 0; + // for (i = 0; i < lvl; i++) + // grib_context_print(act->context, f, " "); + // grib_context_print(act->context, f, "remove %s as %s in %s\n", + // grib_arguments_get_name(0, a->args, 0), act->name, grib_arguments_get_name(0, a->args, 1)); } + static void destroy(grib_context* context, grib_action* act) { grib_action_remove* a = (grib_action_remove*)act; @@ -151,4 +147,3 @@ static void destroy(grib_context* context, grib_action* act) grib_context_free_persistent(context, act->name); grib_context_free_persistent(context, act->op); } - From f5c4761861d8719c8e7b82b947c1a79cec304572 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 20:16:18 +0000 Subject: [PATCH 067/156] Testing: expandedOriginalCodes (smart_table) --- tests/bufr_ecc-517.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/bufr_ecc-517.cc b/tests/bufr_ecc-517.cc index e4dc5d563..37c538fde 100644 --- a/tests/bufr_ecc-517.cc +++ b/tests/bufr_ecc-517.cc @@ -120,8 +120,17 @@ int main(int argc, char** argv) } fclose(fout); + + // expandedOriginalCodes + long orig[100]; + size = 100; + CODES_CHECK(codes_get_long_array(h, "expandedOriginalCodes", orig, &size), 0); + printf("Size of expandedOriginalCodes = %zu\n", size); + codes_handle_delete(h); free(ivalues); + codes_context_delete(0); + return 0; } From 18edad5b52b919d0a3c9ae5351ce838c24241096 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 21:57:46 +0000 Subject: [PATCH 068/156] Testing: smart_table unpack_string --- src/grib_accessor_class_smart_table.cc | 2 +- tests/bufr_filter_misc.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/grib_accessor_class_smart_table.cc b/src/grib_accessor_class_smart_table.cc index dd6cfcd41..5417dec67 100644 --- a/src/grib_accessor_class_smart_table.cc +++ b/src/grib_accessor_class_smart_table.cc @@ -545,7 +545,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) if (*len < self->tableCodesSize) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%lu) for %s it contains %lu values", *len, a->name, self->tableCodesSize); + "Wrong size (%zu) for %s, it contains %zu values", *len, a->name, self->tableCodesSize); *len = 0; return GRIB_ARRAY_TOO_SMALL; } diff --git a/tests/bufr_filter_misc.sh b/tests/bufr_filter_misc.sh index f1edf0368..f2021a3f5 100755 --- a/tests/bufr_filter_misc.sh +++ b/tests/bufr_filter_misc.sh @@ -1290,6 +1290,15 @@ cat > $fRules < $fLog +# smart table unpack_string +tempBufr=temp.$label.bufr +f="$ECCODES_SAMPLES_PATH/BUFR4.tmpl" +cat > $fRules < Date: Sat, 24 Feb 2024 22:07:55 +0000 Subject: [PATCH 069/156] Error messages --- src/grib_accessor_class_smart_table.cc | 56 +++++++++---------- src/grib_accessor_class_smart_table_column.cc | 22 ++++---- src/grib_oarray.cc | 8 +-- src/grib_sarray.cc | 6 +- 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/grib_accessor_class_smart_table.cc b/src/grib_accessor_class_smart_table.cc index 5417dec67..70f964c7d 100644 --- a/src/grib_accessor_class_smart_table.cc +++ b/src/grib_accessor_class_smart_table.cc @@ -165,9 +165,9 @@ static int grib_load_smart_table(grib_context* c, const char* filename, const ch static void init(grib_accessor* a, const long len, grib_arguments* params) { - int n = 0; + int n = 0; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(a); self->values = grib_arguments_get_name(hand, params, n++); self->tablename = grib_arguments_get_string(hand, params, n++); @@ -179,25 +179,25 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->dirty = 1; + self->dirty = 1; self->tableCodesSize = 0; - self->tableCodes = 0; + self->tableCodes = 0; } static grib_smart_table* load_table(grib_accessor* a) { grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; - size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent->h; - grib_context* c = h->context; - grib_smart_table* t = NULL; + size_t size = 0; + grib_handle* h = ((grib_accessor*)self)->parent->h; + grib_context* c = h->context; + grib_smart_table* t = NULL; grib_smart_table* next = NULL; - char* filename = 0; + char* filename = 0; char recomposed[1024] = {0,}; char localRecomposed[1024] = {0,}; - char* localFilename = 0; + char* localFilename = 0; char extraRecomposed[1024] = {0,}; - char* extraFilename = 0; + char* extraFilename = 0; char masterDir[1024] = {0,}; char localDir[1024] = {0,}; char extraDir[1024] = {0,}; @@ -258,8 +258,8 @@ static grib_smart_table* load_table(grib_accessor* a) */ size = (1ULL << self->widthOfCode); /* = 2^self->widthOfCode (as a 64 bit number) */ - t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); - t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); + t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); + t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); t->numberOfEntries = size; if (filename != 0) @@ -296,21 +296,21 @@ static int grib_load_smart_table(grib_context* c, const char* filename, Assert(t != NULL); if (t->filename[0] == NULL) { - t->filename[0] = grib_context_strdup_persistent(c, filename); + t->filename[0] = grib_context_strdup_persistent(c, filename); t->recomposed_name[0] = grib_context_strdup_persistent(c, recomposed_name); - t->next = c->smart_table; - t->numberOfEntries = size; + t->next = c->smart_table; + t->numberOfEntries = size; GRIB_MUTEX_INIT_ONCE(&once, &thread_init); GRIB_MUTEX_LOCK(&mutex); c->smart_table = t; GRIB_MUTEX_UNLOCK(&mutex); } else if (t->filename[1] == NULL) { - t->filename[1] = grib_context_strdup_persistent(c, filename); + t->filename[1] = grib_context_strdup_persistent(c, filename); t->recomposed_name[1] = grib_context_strdup_persistent(c, recomposed_name); } else { - t->filename[2] = grib_context_strdup_persistent(c, filename); + t->filename[2] = grib_context_strdup_persistent(c, filename); t->recomposed_name[2] = grib_context_strdup_persistent(c, recomposed_name); } @@ -405,7 +405,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_string(grib_accessor* a, char* buffer, size_t* len) { grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; - grib_smart_table* table = NULL; + grib_smart_table* table = NULL; size_t size = 1; long value; @@ -435,7 +435,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) } strcpy(buffer, tmp); - *len = l; + *len = l; self->dirty = 0; return GRIB_SUCCESS; @@ -444,9 +444,9 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) static int get_table_codes(grib_accessor* a) { grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; - size_t size = 0; - long* v = 0; - int err = 0; + size_t size = 0; + long* v = 0; + int err = 0; int count, j; size_t i; @@ -479,7 +479,7 @@ static int get_table_codes(grib_accessor* a) if (self->tableCodes) grib_context_free(a->context, self->tableCodes); self->tableCodes = (long*)grib_context_malloc_clear(a->context, count * sizeof(long)); - j = 0; + j = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) self->tableCodes[j++] = v[i]; @@ -488,16 +488,16 @@ static int get_table_codes(grib_accessor* a) grib_context_free(a->context, v); self->tableCodesSize = count; - self->dirty = 0; + self->dirty = 0; return 0; } static int value_count(grib_accessor* a, long* count) { - int err = 0; + int err = 0; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; - *count = 0; + *count = 0; if (!self->values) return 0; @@ -532,7 +532,7 @@ static int get_native_type(grib_accessor* a) static int unpack_long(grib_accessor* a, long* val, size_t* len) { - int err = 0; + int err = 0; grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; size_t i; diff --git a/src/grib_accessor_class_smart_table_column.cc b/src/grib_accessor_class_smart_table_column.cc index 28e5a4798..295f29281 100644 --- a/src/grib_accessor_class_smart_table_column.cc +++ b/src/grib_accessor_class_smart_table_column.cc @@ -130,11 +130,11 @@ typedef struct grib_accessor_smart_table static void init(grib_accessor* a, const long len, grib_arguments* params) { - int n = 0; + int n = 0; grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); + self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; @@ -158,18 +158,18 @@ static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) { grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table* tableAccessor = NULL; - grib_smart_table* table = NULL; + grib_smart_table* table = NULL; size_t size = 1; long* code; - int err = GRIB_SUCCESS; + int err = GRIB_SUCCESS; char tmp[1024] = {0,}; int i = 0; tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); if (!tableAccessor) { grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to find accessor %s", self->smartTable); + "Unable to find accessor %s", self->smartTable); return GRIB_NOT_FOUND; } @@ -213,7 +213,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; grib_accessor_smart_table* tableAccessor = NULL; - grib_smart_table* table = NULL; + grib_smart_table* table = NULL; size_t size = 1; long* code; @@ -226,7 +226,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); if (!tableAccessor) { grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to find accessor %s", self->smartTable); + "Unable to find accessor %s", self->smartTable); return GRIB_NOT_FOUND; } @@ -263,14 +263,14 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) static int value_count(grib_accessor* a, long* count) { grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; - size_t size = 0; - int err = 0; - *count = 0; + size_t size = 0; + int err = 0; + *count = 0; if (!self->smartTable) return 0; - err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); + err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); *count = size; return err; } diff --git a/src/grib_oarray.cc b/src/grib_oarray.cc index 91e7d9f33..6c5e06d45 100644 --- a/src/grib_oarray.cc +++ b/src/grib_oarray.cc @@ -17,8 +17,6 @@ grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize) c = grib_context_get_default(); v = (grib_oarray*)grib_context_malloc_clear(c, sizeof(grib_oarray)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_oarray_new unable to allocate %zu bytes", sizeof(grib_oarray)); return NULL; } v->size = size; @@ -27,8 +25,7 @@ grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize) v->v = (void**)grib_context_malloc_clear(c, sizeof(char*) * size); v->context = c; if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_oarray_new unable to allocate %zu bytes", sizeof(char*) * size); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * size); return NULL; } return v; @@ -44,8 +41,7 @@ static grib_oarray* grib_oarray_resize(grib_oarray* v) v->v = (void**)grib_context_realloc(c, v->v, newsize * sizeof(char*)); v->size = newsize; if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_oarray_resize unable to allocate %zu bytes", sizeof(char*) * newsize); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * newsize); return NULL; } return v; diff --git a/src/grib_sarray.cc b/src/grib_sarray.cc index 93e372e94..2159af7b3 100644 --- a/src/grib_sarray.cc +++ b/src/grib_sarray.cc @@ -30,7 +30,7 @@ grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize) v = (grib_sarray*)grib_context_malloc_clear(c, sizeof(grib_sarray)); if (!v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_sarray_new unable to allocate %lu bytes\n", sizeof(grib_sarray)); + "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_sarray)); return NULL; } v->size = size; @@ -40,7 +40,7 @@ grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize) v->v = (char**)grib_context_malloc_clear(c, sizeof(char*) * size); if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_sarray_new unable to allocate %lu bytes\n", sizeof(char*) * size); + "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * size); return NULL; } return v; @@ -57,7 +57,7 @@ static grib_sarray* grib_sarray_resize(grib_sarray* v) v->size = newsize; if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_sarray_resize unable to allocate %lu bytes\n", sizeof(char*) * newsize); + "%s: Unable to allocate %zu bytes", __func__, sizeof(char*) * newsize); return NULL; } return v; From f7869adb9c2f67334b715d00346bcfae2c7ffb34 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sat, 24 Feb 2024 22:21:36 +0000 Subject: [PATCH 070/156] Error messages: Print context --- src/grib_accessor_class_bufr_elements_table.cc | 3 +-- src/grib_accessor_class_data_g22order_packing.cc | 2 +- src/grib_bufr_descriptors_array.cc | 8 +++----- src/grib_darray.cc | 8 +++----- src/grib_dumper_class_json.cc | 2 +- src/grib_iarray.cc | 9 +++------ src/grib_index.cc | 10 +++------- 7 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/grib_accessor_class_bufr_elements_table.cc index cee7049aa..4858ff63d 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/grib_accessor_class_bufr_elements_table.cc @@ -379,8 +379,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i DEBUG_ASSERT(c); v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "accessor_bufr_elements_table_get_descriptor: unable to allocate %ld bytes\n", sizeof(bufr_descriptor)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor)); *err = GRIB_OUT_OF_MEMORY; return NULL; } diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/grib_accessor_class_data_g22order_packing.cc index f45d9f722..4ed535d29 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/grib_accessor_class_data_g22order_packing.cc @@ -1772,7 +1772,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) unsigned char* sec7 = reinterpret_cast(grib_context_malloc(a->context, size_sec7)); if (sec7 == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %d bytes", cclass_name, size_sec7); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7); return GRIB_OUT_OF_MEMORY; } diff --git a/src/grib_bufr_descriptors_array.cc b/src/grib_bufr_descriptors_array.cc index 0134048a2..637cf14eb 100644 --- a/src/grib_bufr_descriptors_array.cc +++ b/src/grib_bufr_descriptors_array.cc @@ -22,8 +22,7 @@ bufr_descriptors_array* grib_bufr_descriptors_array_new(grib_context* c, size_t v = (bufr_descriptors_array*)grib_context_malloc(c, sizeof(bufr_descriptors_array)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "bufr_descriptors_array_new unable to allocate %ld bytes\n", sizeof(bufr_descriptors_array)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptors_array)); return NULL; } v->context = c; @@ -34,7 +33,7 @@ bufr_descriptors_array* grib_bufr_descriptors_array_new(grib_context* c, size_t v->number_of_pop_front = 0; if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_bufr_descriptors_array_new unable to allocate %ld bytes\n", sizeof(bufr_descriptor) * size); + "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor) * size); return NULL; } return v; @@ -73,8 +72,7 @@ static bufr_descriptors_array* grib_bufr_descriptors_array_resize_to(bufr_descri newv = (bufr_descriptor**)grib_context_malloc_clear(c, newsize * sizeof(bufr_descriptor*)); if (!newv) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_bufr_descriptors_array_resize unable to allocate %ld bytes\n", sizeof(bufr_descriptor*) * newsize); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(bufr_descriptor*) * newsize); return NULL; } diff --git a/src/grib_darray.cc b/src/grib_darray.cc index f2250862d..5aac8265a 100644 --- a/src/grib_darray.cc +++ b/src/grib_darray.cc @@ -45,8 +45,7 @@ grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) c = grib_context_get_default(); v = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %zu bytes", sizeof(grib_darray)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_darray)); return NULL; } v->size = size; @@ -55,8 +54,7 @@ grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) v->context = c; v->v = (double*)grib_context_malloc_clear(c, sizeof(double) * size); if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %zu bytes", sizeof(double) * size); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(double) * size); return NULL; } return v; @@ -73,7 +71,7 @@ static grib_darray* grib_darray_resize(grib_darray* v) v->size = newsize; if (!v->v) { grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_resize unable to allocate %zu bytes", sizeof(double) * newsize); + "%s: Unable to allocate %zu bytes", __func__, sizeof(double) * newsize); return NULL; } return v; diff --git a/src/grib_dumper_class_json.cc b/src/grib_dumper_class_json.cc index be1b5bcc4..a3b052844 100644 --- a/src/grib_dumper_class_json.cc +++ b/src/grib_dumper_class_json.cc @@ -458,7 +458,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) * if (size==0) return; * value=(char*)grib_context_malloc_clear(a->context,size); * if (!value) { - * grib_context_log(a->context,GRIB_LOG_ERROR,"unable to allocate %d bytes",(int)size); + * grib_context_log(a->context,GRIB_LOG_ERROR,"Unable to allocate %zu bytes",size); * return; * } */ diff --git a/src/grib_iarray.cc b/src/grib_iarray.cc index 50d16bcaa..f69adfffd 100644 --- a/src/grib_iarray.cc +++ b/src/grib_iarray.cc @@ -46,8 +46,7 @@ grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize) v = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray)); if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %zu bytes", sizeof(grib_iarray)); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(grib_iarray)); return NULL; } v->context = c; @@ -57,8 +56,7 @@ grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize) v->v = (long*)grib_context_malloc(c, sizeof(long) * size); v->number_of_pop_front = 0; if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %zu bytes", sizeof(long) * size); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * size); return NULL; } return v; @@ -98,8 +96,7 @@ static grib_iarray* grib_iarray_resize_to(grib_iarray* v, size_t newsize) newv = (long*)grib_context_malloc_clear(c, newsize * sizeof(long)); if (!newv) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_resize unable to allocate %zu bytes", sizeof(long) * newsize); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to allocate %zu bytes", __func__, sizeof(long) * newsize); return NULL; } diff --git a/src/grib_index.cc b/src/grib_index.cc index 225e502eb..15e9de083 100644 --- a/src/grib_index.cc +++ b/src/grib_index.cc @@ -242,17 +242,13 @@ static grib_index_key* grib_index_new_key(grib_context* c, grib_index_key* keys, next = (grib_index_key*)grib_context_malloc_clear(c, sizeof(grib_index_key)); if (!next) { - grib_context_log(c, GRIB_LOG_ERROR, - "unable to allocate %ld bytes", - sizeof(grib_index_key)); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_index_key)); *err = GRIB_OUT_OF_MEMORY; return NULL; } values = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); if (!values) { - grib_context_log(c, GRIB_LOG_ERROR, - "unable to allocate %ld bytes", - sizeof(grib_string_list)); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", sizeof(grib_string_list)); *err = GRIB_OUT_OF_MEMORY; return NULL; } @@ -1908,7 +1904,7 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err) sizeof(grib_field_list)); if (!index->fieldset) { grib_context_log(index->context, GRIB_LOG_ERROR, - "unable to allocate %lu bytes", sizeof(grib_field_list)); + "Unable to allocate %zu bytes", sizeof(grib_field_list)); return NULL; } index->current = index->fieldset; From 2a625a483c9b0ff5f7dc4ab3c997f93bf8a9d310 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 25 Feb 2024 15:47:30 +0000 Subject: [PATCH 071/156] Testing: Product names --- tests/unit_tests.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index 12e18bd97..110e8c4ee 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -656,6 +656,7 @@ void test_codes_get_product_name() Assert( STR_EQUAL("BUFR", codes_get_product_name(PRODUCT_BUFR)) ); Assert( STR_EQUAL("GTS", codes_get_product_name(PRODUCT_GTS)) ); Assert( STR_EQUAL("METAR", codes_get_product_name(PRODUCT_METAR)) ); + Assert( STR_EQUAL("TAF", codes_get_product_name(PRODUCT_TAF)) ); } void test_codes_get_type_name() From 0be6b6c5808feada102a458963086a8eb171ff8f Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 25 Feb 2024 15:47:41 +0000 Subject: [PATCH 072/156] Fix compare method --- src/grib_accessor_class_values.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/grib_accessor_class_values.cc b/src/grib_accessor_class_values.cc index 3e69cf56e..384282317 100644 --- a/src/grib_accessor_class_values.cc +++ b/src/grib_accessor_class_values.cc @@ -231,10 +231,8 @@ static int compare(grib_accessor* a, grib_accessor* b) grib_unpack_double(b, bval, &blen); retval = GRIB_SUCCESS; - while (alen != 0) { - if (*bval != *aval) - retval = GRIB_DOUBLE_VALUE_MISMATCH; - alen--; + for (size_t i=0; icontext, aval); @@ -245,15 +243,13 @@ static int compare(grib_accessor* a, grib_accessor* b) static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int ret = 0; grib_accessor_values* self = (grib_accessor_values*)a; - int i; double* dval = (double*)grib_context_malloc(a->context, *len * sizeof(double)); - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) dval[i] = (double)val[i]; - ret = grib_pack_double(a, dval, len); + int ret = grib_pack_double(a, dval, len); grib_context_free(a->context, dval); From 8f31b291340eb154058d8d0528064a61577bbe55 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 25 Feb 2024 15:54:02 +0000 Subject: [PATCH 073/156] Accessors: Type safety --- src/grib_accessor_class_gen.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/grib_accessor_class_gen.cc b/src/grib_accessor_class_gen.cc index 8b59b3b7a..c74479aeb 100644 --- a/src/grib_accessor_class_gen.cc +++ b/src/grib_accessor_class_gen.cc @@ -455,16 +455,14 @@ static int pack_long(grib_accessor* a, const long* v, size_t* len) { grib_context* c = a->context; if (a->cclass->pack_double && a->cclass->pack_double != &pack_double) { - int i = 0, ret = 0; double* val = (double*)grib_context_malloc(c, *len * (sizeof(double))); if (!val) { - grib_context_log(c, GRIB_LOG_ERROR, - "Unable to allocate %zu bytes", *len * (sizeof(double))); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", *len * (sizeof(double))); return GRIB_OUT_OF_MEMORY; } - for (i = 0; i < *len; i++) - val[i] = (long)v[i]; - ret = grib_pack_double(a, val, len); + for (size_t i = 0; i < *len; i++) + val[i] = v[i]; + int ret = grib_pack_double(a, val, len); grib_context_free(c, val); return ret; } From 1a1b44662684d1f8596efdebe4fd13483e56e6db Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 25 Feb 2024 15:56:00 +0000 Subject: [PATCH 074/156] Accessors: Type safety --- src/grib_accessor_class_gen.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/grib_accessor_class_gen.cc b/src/grib_accessor_class_gen.cc index c74479aeb..b611f5043 100644 --- a/src/grib_accessor_class_gen.cc +++ b/src/grib_accessor_class_gen.cc @@ -477,14 +477,13 @@ static int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* { grib_context* c = a->context; int ret = GRIB_SUCCESS; - size_t i = 0; size_t numBytes = *len * (sizeof(long)); long* lValues = (long*)grib_context_malloc(c, numBytes); if (!lValues) { grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %ld bytes", numBytes); return GRIB_OUT_OF_MEMORY; } - for (i = 0; i < *len; i++) + for (size_t i = 0; i < *len; i++) lValues[i] = (long)v[i]; /* convert from double to long */ ret = grib_pack_long(a, lValues, len); grib_context_free(c, lValues); From f8e580061753e1ad9f6f0a8b4bdb26736994b45a Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 25 Feb 2024 16:18:44 +0000 Subject: [PATCH 075/156] Testing: switch for doubles --- tests/grib_filter.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index c8c632f1c..c4e6a4021 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -206,11 +206,15 @@ ${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB1.tmpl $ECCODES_SAM cat >$tempFilt < Date: Mon, 26 Feb 2024 13:21:23 +0000 Subject: [PATCH 076/156] Tools: Capitalisation --- tools/codes_info.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/codes_info.cc b/tools/codes_info.cc index a351ec34e..a73dcde14 100644 --- a/tools/codes_info.cc +++ b/tools/codes_info.cc @@ -136,8 +136,8 @@ int main(int argc, char* argv[]) "It is recommended you use ECCODES_SAMPLES_PATH instead!)\n"); } else { - printf("Default SAMPLES path is used: %s\n", context->grib_samples_path); - printf("SAMPLES path can be changed by setting the ECCODES_SAMPLES_PATH environment variable.\n"); + printf("Default samples path is used: %s\n", context->grib_samples_path); + printf("Samples path can be changed by setting the ECCODES_SAMPLES_PATH environment variable.\n"); } if ((path = getenv("ECCODES_EXTRA_SAMPLES_PATH")) != NULL) { printf("Environment variable ECCODES_EXTRA_SAMPLES_PATH=%s\n", path); From 41e82fbdcd61a8f9fccb85d4e28bdf21c5a103bc Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 26 Feb 2024 13:21:33 +0000 Subject: [PATCH 077/156] Compiler warnings --- src/grib_context.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/grib_context.cc b/src/grib_context.cc index 859f1087c..446481c4a 100644 --- a/src/grib_context.cc +++ b/src/grib_context.cc @@ -839,7 +839,6 @@ void grib_context_reset(grib_context* c) void grib_context_delete(grib_context* c) { - size_t i = 0; if (!c) c = grib_context_get_default(); @@ -851,7 +850,7 @@ void grib_context_delete(grib_context* c) if (c != &default_grib_context) grib_context_free_persistent(&default_grib_context, c); - for(i=0; ihash_array[i] = NULL; c->hash_array_count = 0; grib_itrie_delete(c->hash_array_index); From 91e4b96db502bd2e0b46ef3e5303cf05acb72fe6 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 26 Feb 2024 13:37:31 +0000 Subject: [PATCH 078/156] Testing: bufr_extract_headers --- tests/bufr_extract_headers.sh | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/bufr_extract_headers.sh b/tests/bufr_extract_headers.sh index 6b6f0a907..a20602391 100755 --- a/tests/bufr_extract_headers.sh +++ b/tests/bufr_extract_headers.sh @@ -115,26 +115,16 @@ amsu_55.bufr amv2_87.bufr asbh_139.bufr asbl_139.bufr -asca_139.bufr -asch_139.bufr -ascs_139.bufr -aseh_139.bufr asel_139.bufr ashs_139.bufr atap_55.bufr ateu_155.bufr atms_201.bufr atov_55.bufr -avhm_87.bufr -avhn_87.bufr -avhr_58.bufr b003_56.bufr b005_89.bufr -cmwi_87.bufr cmwn_87.bufr cori_156.bufr -crit_202.bufr -csrh_189.bufr emsg_189.bufr euwv_87.bufr fy3a_154.bufr @@ -150,20 +140,14 @@ hirb_55.bufr hirs_55.bufr ias1_240.bufr iasi_241.bufr -ifco_208.bufr ikco_217.bufr imssnow.bufr itrg_208.bufr itwt_233.bufr -j2eo_216.bufr j2nb_216.bufr jaso_214.bufr kond_209.bufr maer_207.bufr -mloz_206.bufr -modi_87.bufr -modw_87.bufr -monw_87.bufr nomi_206.bufr nos1_208.bufr pgps_110.bufr @@ -172,8 +156,6 @@ s4kn_165.bufr sb19_206.bufr sbu8_206.bufr smin_49.bufr -smiu_49.bufr -smos_203.bufr sn4k_165.bufr ssbt_127.bufr tmr7_129.bufr From 13bbefaa496e1120e0989be4b655f29312c205ae Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 26 Feb 2024 16:32:30 +0000 Subject: [PATCH 079/156] Replace Asserts with helpful error messages --- src/grib_iterator.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/grib_iterator.cc b/src/grib_iterator.cc index 9f4fadd95..0d253bc68 100644 --- a/src/grib_iterator.cc +++ b/src/grib_iterator.cc @@ -9,7 +9,6 @@ */ /*************************************************************************** - * Enrico Fucile * * Jean Baptiste Filippi - 01.11.2005 * ***************************************************************************/ #include "grib_api_internal.h" @@ -71,7 +70,8 @@ int grib_iterator_next(grib_iterator* i, double* lat, double* lon, double* value return c->next(i, lat, lon, value); c = s; } - Assert(0); + + grib_context_log(i->h->context, GRIB_LOG_FATAL, "%s: No next() function in iterator '%s'", __func__, i->cclass->name); return 0; } @@ -84,7 +84,7 @@ int grib_iterator_has_next(grib_iterator* i) return c->has_next(i); c = s; } - Assert(0); + grib_context_log(i->h->context, GRIB_LOG_FATAL, "%s: No has_next() function in iterator '%s'", __func__, i->cclass->name); return 0; } @@ -97,7 +97,7 @@ int grib_iterator_previous(grib_iterator* i, double* lat, double* lon, double* v return c->previous(i, lat, lon, value); c = s; } - Assert(0); + grib_context_log(i->h->context, GRIB_LOG_FATAL, "%s: No previous() function in iterator '%s'", __func__, i->cclass->name); return 0; } @@ -110,7 +110,7 @@ int grib_iterator_reset(grib_iterator* i) return c->reset(i); c = s; } - Assert(0); + grib_context_log(i->h->context, GRIB_LOG_FATAL, "%s: No reset() function in iterator '%s'", __func__, i->cclass->name); return 0; } From 65e32808502f1baf75a4db94666906ebf9d65c92 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 10:51:27 +0000 Subject: [PATCH 080/156] Update author list --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index f21f35fcf..c0f36b955 100755 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ -Enrico Fucile Shahram Najm Eugen Betke +Enrico Fucile +Pedro Maciel Sandor Kertesz Sebastien Villaume Florian Rathgeber From 151654a3392c16d8c7d3966143b0a656d88438c0 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 10:52:09 +0000 Subject: [PATCH 081/156] ECC-1764: Fix crash --- src/eccodes_prototypes.h | 1 - src/grib_index.cc | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 993074e1d..e26aace4e 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -655,7 +655,6 @@ 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); grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err); -void grib_index_rewind(grib_index* index); int codes_index_set_product_kind(grib_index* index, ProductKind product_kind); int codes_index_set_unpack_bufr(grib_index* index, int unpack); int is_index_file(const char* filename); diff --git a/src/grib_index.cc b/src/grib_index.cc index 15e9de083..5571f6e90 100644 --- a/src/grib_index.cc +++ b/src/grib_index.cc @@ -63,6 +63,7 @@ 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) { @@ -1881,7 +1882,8 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err) return NULL; c = index->context; if (!index->rewind) { - if (!index->current) { + // ECC-1764 + if (!index->current || !index->current->field) { *err = GRIB_END_OF_INDEX; return NULL; } @@ -1937,7 +1939,7 @@ grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err) return h; } -void grib_index_rewind(grib_index* index) +static void grib_index_rewind(grib_index* index) { index->rewind = 1; } From 07382ee77fd9415db0b987da7625bf18941b9367 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 11:54:09 +0000 Subject: [PATCH 082/156] HEALPix: Better error message re nested ordering --- src/grib_iterator_class_healpix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_iterator_class_healpix.cc b/src/grib_iterator_class_healpix.cc index f2e9c0766..6d7aad5c4 100644 --- a/src/grib_iterator_class_healpix.cc +++ b/src/grib_iterator_class_healpix.cc @@ -195,7 +195,7 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) if (!STR_EQUAL(ordering, "ring")) { grib_context_log(h->context, GRIB_LOG_ERROR, "%s: Only ring ordering is supported", ITER); - return GRIB_WRONG_GRID; + return GRIB_GEOCALCULUS_PROBLEM; } if (grib_is_earth_oblate(h)) { From 4f446ffc61c904fa619b04baa37c0c870ca673f3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 12:19:01 +0000 Subject: [PATCH 083/156] ECC-1764: Add test --- tests/CMakeLists.txt | 2 ++ tests/grib_ecc-1764.cc | 44 ++++++++++++++++++++++++++++++++++++++++++ tests/grib_ecc-1764.sh | 20 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/grib_ecc-1764.cc create mode 100755 tests/grib_ecc-1764.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 21640b8bb..092d9ea83 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,6 +45,7 @@ list(APPEND test_c_bins grib_ecc-1467 grib_ecc-1431 grib_ecc-1433 + grib_ecc-1764 bufr_ecc-517 bufr_ecc-1288 bufr_get_element @@ -259,6 +260,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1397 grib_ecc-1425 grib_ecc-1467 + grib_ecc-1764 grib_sub_hourly grib_set_bytes grib_set_force diff --git a/tests/grib_ecc-1764.cc b/tests/grib_ecc-1764.cc new file mode 100644 index 000000000..a2d884a18 --- /dev/null +++ b/tests/grib_ecc-1764.cc @@ -0,0 +1,44 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ +#include "grib_api.h" +#undef NDEBUG +#include "assert.h" + +int main(int argc, char* argv[]) +{ + int ret = GRIB_SUCCESS; + + if (argc != 2) return 1; + + const char* infile = argv[1]; + grib_index* index = grib_index_new(0, "shortName,level", &ret); + assert(ret == GRIB_SUCCESS); + + ret = grib_index_add_file(index, infile); + assert(ret == GRIB_SUCCESS); + + printf("Select nonexistent entries...\n"); + grib_index_select_string(index, "shortName", "frost"); + grib_index_select_long(index, "level", 666); + + grib_handle* h = grib_handle_new_from_index(index, &ret); + assert(!h); + assert(ret == GRIB_END_OF_INDEX); + + // Call it again. Should not crash + h = grib_handle_new_from_index(index, &ret); + assert(!h); + assert(ret == GRIB_END_OF_INDEX); + + grib_index_delete(index); + grib_context_delete(grib_context_get_default()); + + return 0; +} diff --git a/tests/grib_ecc-1764.sh b/tests/grib_ecc-1764.sh new file mode 100755 index 000000000..81891ec74 --- /dev/null +++ b/tests/grib_ecc-1764.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="grib_ecc-1764_test" +temp=temp.$label.txt + +infile=${data_dir}/tigge_cf_ecmwf.grib2 +$EXEC ${test_dir}/grib_ecc-1764 $infile # > $temp + +# Clean up +rm -f $temp From db30325fbfa3125195db8c66b43e35c52f0eb0a7 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 12:39:33 +0000 Subject: [PATCH 084/156] Cleanup --- src/action_class_list.cc | 5 ++--- src/grib_accessor_class_section_pointer.cc | 14 +++++++------- src/grib_index.cc | 16 ++++++++-------- src/grib_nearest_class_latlon_reduced.cc | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/action_class_list.cc b/src/action_class_list.cc index 0a4b8a630..c9693a554 100644 --- a/src/action_class_list.cc +++ b/src/action_class_list.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" /* @@ -107,7 +106,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) long val = 0; if ((ret = grib_expression_evaluate_long(p->h, a->expression, &val)) != GRIB_SUCCESS) { - grib_context_log(p->h->context, GRIB_LOG_DEBUG, "List %s creating %d values unable to evaluate long", act->name, val); + grib_context_log(p->h->context, GRIB_LOG_DEBUG, "List %s creating %ld values: Unable to evaluate long", act->name, val); return ret; } @@ -166,7 +165,7 @@ static grib_action* reparse(grib_action* a, grib_accessor* acc, int* doit) if ((ret = grib_expression_evaluate_long(grib_handle_of_accessor(acc), self->expression, &val)) != GRIB_SUCCESS) { grib_context_log(acc->context, GRIB_LOG_ERROR, - "List %s creating %ld values, unable to evaluate long", acc->name, val); + "List %s creating %ld values: Unable to evaluate long", acc->name, val); } *doit = (val != acc->loop); diff --git a/src/grib_accessor_class_section_pointer.cc b/src/grib_accessor_class_section_pointer.cc index e9b81614a..861ab12e7 100644 --- a/src/grib_accessor_class_section_pointer.cc +++ b/src/grib_accessor_class_section_pointer.cc @@ -107,7 +107,7 @@ grib_accessor_class* grib_accessor_class_section_pointer = &_grib_accessor_class static void init(grib_accessor* a, const long len, grib_arguments* arg) { - int n = 0; + int n = 0; grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; self->sectionOffset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); @@ -162,13 +162,13 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len) static long byte_count(grib_accessor* a) { grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; - long sectionLength = 0; - int ret = 0; + long sectionLength = 0; + int ret = 0; ret = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); if (ret) { grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get %s %s", + "Unable to get %s %s", self->sectionLength, grib_get_error_message(ret)); return -1; } @@ -179,13 +179,13 @@ static long byte_count(grib_accessor* a) static long byte_offset(grib_accessor* a) { grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; - long sectionOffset = 0; - int ret = 0; + long sectionOffset = 0; + int ret = 0; ret = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); if (ret) { grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get %s %s", + "Unable to get %s %s", self->sectionOffset, grib_get_error_message(ret)); return -1; } diff --git a/src/grib_index.cc b/src/grib_index.cc index 5571f6e90..66718a58b 100644 --- a/src/grib_index.cc +++ b/src/grib_index.cc @@ -543,7 +543,7 @@ grib_index* grib_index_new(grib_context* c, const char* key, int* err) index = (grib_index*)grib_context_malloc_clear(c, sizeof(grib_index)); if (!index) { - grib_context_log(c, GRIB_LOG_ERROR, "unable to create index"); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to create index"); *err = GRIB_OUT_OF_MEMORY; return NULL; } @@ -1033,7 +1033,7 @@ int grib_index_search_same(grib_index* index, grib_handle* h) } if (err && err != GRIB_NOT_FOUND) { grib_context_log(c, GRIB_LOG_ERROR, - "unable to create index. \"%s\": %s", + "Unable to create index. \"%s\": %s", keys->name, grib_get_error_message(err)); return err; } @@ -1138,7 +1138,7 @@ static int codes_index_add_file_internal(grib_index* index, const char* filename if (!error && set_values_count != 0) { err = grib_set_values(h, set_values, set_values_count); if (err) { - grib_context_log(c, GRIB_LOG_ERROR,"codes_index_add_file: unable to set %s\n", envsetkeys); + grib_context_log(c, GRIB_LOG_ERROR,"codes_index_add_file: Unable to set %s\n", envsetkeys); return err; } } @@ -1148,7 +1148,7 @@ static int codes_index_add_file_internal(grib_index* index, const char* filename if (index->product_kind == PRODUCT_BUFR && index->unpack_bufr) { err = grib_set_long(h, "unpack", 1); if (err) { - grib_context_log(c, GRIB_LOG_ERROR, "unable to unpack BUFR to create index. \"%s\": %s", + grib_context_log(c, GRIB_LOG_ERROR, "Unable to unpack BUFR to create index. \"%s\": %s", index_key->name, grib_get_error_message(err)); return err; } @@ -1186,7 +1186,7 @@ static int codes_index_add_file_internal(grib_index* index, const char* filename return err; } if (err && err != GRIB_NOT_FOUND) { - grib_context_log(c, GRIB_LOG_ERROR, "unable to create index. key=\"%s\" (message #%lu): %s", + grib_context_log(c, GRIB_LOG_ERROR, "Unable to create index. key=\"%s\" (message #%lu): %s", index_key->name, message_count, grib_get_error_message(err)); return err; } @@ -1359,7 +1359,7 @@ static int codes_index_add_file_internal(grib_index* index, const char* filename // return err; // } // if (err && err != GRIB_NOT_FOUND) { -// grib_context_log(c,GRIB_LOG_ERROR,"unable to create index. \"%s\": %s",index_key->name,grib_get_error_message(err)); +// grib_context_log(c,GRIB_LOG_ERROR,"Unable to create index. \"%s\": %s",index_key->name,grib_get_error_message(err)); // return err; // } @@ -1495,7 +1495,7 @@ int grib_index_get_long(const grib_index* index, const char* key, long* values, if (!k) return GRIB_NOT_FOUND; if (k->type != GRIB_TYPE_LONG) { - grib_context_log(index->context, GRIB_LOG_ERROR, "unable to get index %s as long", key); + grib_context_log(index->context, GRIB_LOG_ERROR, "Unable to get index %s as long", key); return GRIB_WRONG_TYPE; } if (k->values_count > *size) @@ -1524,7 +1524,7 @@ int grib_index_get_double(const grib_index* index, const char* key, double* valu if (!k) return GRIB_NOT_FOUND; if (k->type != GRIB_TYPE_DOUBLE) { - grib_context_log(index->context, GRIB_LOG_ERROR, "unable to get index %s as double", key); + grib_context_log(index->context, GRIB_LOG_ERROR, "Unable to get index %s as double", key); return GRIB_WRONG_TYPE; } if (k->values_count > *size) diff --git a/src/grib_nearest_class_latlon_reduced.cc b/src/grib_nearest_class_latlon_reduced.cc index e38978188..a5d2af222 100644 --- a/src/grib_nearest_class_latlon_reduced.cc +++ b/src/grib_nearest_class_latlon_reduced.cc @@ -210,7 +210,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, iter = grib_iterator_new(h, GRIB_GEOITERATOR_NO_VALUES, &ret); if (ret) { - grib_context_log(h->context, GRIB_LOG_ERROR, "unable to create iterator"); + grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to create iterator"); return ret; } while (grib_iterator_next(iter, &lat, &lon, NULL)) { From d1e008361604dd995ddfb5a9c7cfd1b3ef9c9340 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 27 Feb 2024 14:20:42 +0000 Subject: [PATCH 085/156] ECC-1776: GRIB2: Additional activity and experiment table entries for DestinE ClimateDT --- definitions/grib2/destine_activity.table | 1 + definitions/grib2/destine_experiment.table | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/definitions/grib2/destine_activity.table b/definitions/grib2/destine_activity.table index 8217458fd..b7c3e8d86 100644 --- a/definitions/grib2/destine_activity.table +++ b/definitions/grib2/destine_activity.table @@ -2,4 +2,5 @@ 1 CMIP6 Coupled Model Intercomparison Project Phase 6 2 ScenarioMIP Scenario Model Intercomparison Project 3 HighResMIP High Resolution Model Intercomparison Project +4 story-nudging Climate storylines by nudging to reanalysis 65535 65535 Missing diff --git a/definitions/grib2/destine_experiment.table b/definitions/grib2/destine_experiment.table index d98a8dd70..864ef9260 100644 --- a/definitions/grib2/destine_experiment.table +++ b/definitions/grib2/destine_experiment.table @@ -7,4 +7,8 @@ 6 SSP2-4.5 Shared Socio-economic Pathways 2-4.5 7 SSP3-7.0 Shared Socio-economic Pathways 3-7.0 8 SSP5-8.5 Shared Socio-economic Pathways 5-8.5 +9 Tplus1.5K Warmer world at 1.5 degrees K above pre-industrial temperatures +10 Tplus2.0K Warmer world at 2.0 degrees K above pre-industrial temperatures +11 Tplus3.0K Warmer world at 3.0 degrees K above pre-industrial temperatures +12 Tplus4.0K Warmer world at 4.0 degrees K above pre-industrial temperatures 65535 65535 Missing From 8b3134cd20f1fc24213b71c29db6bd2000df3d2b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 27 Feb 2024 17:09:20 +0000 Subject: [PATCH 086/156] ECC-1775: GRIB2: WMO conforming snowfall water equivalent parameters for DestinationEarth --- definitions/grib2/cfVarName.def | 16 ++++++++++++++++ definitions/grib2/name.def | 16 ++++++++++++++++ definitions/grib2/paramId.def | 16 ++++++++++++++++ definitions/grib2/shortName.def | 16 ++++++++++++++++ definitions/grib2/units.def | 16 ++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/definitions/grib2/cfVarName.def b/definitions/grib2/cfVarName.def index 889c839e3..ce2d3e54f 100644 --- a/definitions/grib2/cfVarName.def +++ b/definitions/grib2/cfVarName.def @@ -3786,6 +3786,22 @@ typeOfFirstFixedSurface = 187 ; typeOfSecondFixedSurface = 185 ; } +#Convective snowfall water equivalent +'csfwe' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 55 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } +#Large-scale snowfall water equivalent +'lsfwe' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 56 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } #Burned area 'fba' = { discipline = 2 ; diff --git a/definitions/grib2/name.def b/definitions/grib2/name.def index b3b91952a..3ca2e8bd3 100644 --- a/definitions/grib2/name.def +++ b/definitions/grib2/name.def @@ -3786,6 +3786,22 @@ typeOfFirstFixedSurface = 187 ; typeOfSecondFixedSurface = 185 ; } +#Convective snowfall water equivalent +'Convective snowfall water equivalent' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 55 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } +#Large-scale snowfall water equivalent +'Large-scale snowfall water equivalent' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 56 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } #Burned area 'Burned area' = { discipline = 2 ; diff --git a/definitions/grib2/paramId.def b/definitions/grib2/paramId.def index 4c79c56a5..f958d70d5 100644 --- a/definitions/grib2/paramId.def +++ b/definitions/grib2/paramId.def @@ -3786,6 +3786,22 @@ typeOfFirstFixedSurface = 187 ; typeOfSecondFixedSurface = 185 ; } +#Convective snowfall water equivalent +'231057' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 55 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } +#Large-scale snowfall water equivalent +'231058' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 56 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } #Burned area '232000' = { discipline = 2 ; diff --git a/definitions/grib2/shortName.def b/definitions/grib2/shortName.def index 614a8454d..657b668ea 100644 --- a/definitions/grib2/shortName.def +++ b/definitions/grib2/shortName.def @@ -3786,6 +3786,22 @@ typeOfFirstFixedSurface = 187 ; typeOfSecondFixedSurface = 185 ; } +#Convective snowfall water equivalent +'csfwe' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 55 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } +#Large-scale snowfall water equivalent +'lsfwe' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 56 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } #Burned area 'fba' = { discipline = 2 ; diff --git a/definitions/grib2/units.def b/definitions/grib2/units.def index d96d6bd9e..c63afd045 100644 --- a/definitions/grib2/units.def +++ b/definitions/grib2/units.def @@ -3786,6 +3786,22 @@ typeOfFirstFixedSurface = 187 ; typeOfSecondFixedSurface = 185 ; } +#Convective snowfall water equivalent +'kg m**-2' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 55 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } +#Large-scale snowfall water equivalent +'kg m**-2' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 56 ; + typeOfFirstFixedSurface = 1 ; + typeOfStatisticalProcessing = 1 ; + } #Burned area '%' = { discipline = 2 ; From f27616d3820487f225fa1b6d68232135e842bdb3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 10:35:59 +0000 Subject: [PATCH 087/156] Time validation --- src/grib_accessor_class_time.cc | 36 ++++++++++++++++++++++++++++++++- tests/grib_util_set_spec2.sh | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/grib_accessor_class_time.cc b/src/grib_accessor_class_time.cc index a90f4415a..d38a53b7c 100644 --- a/src/grib_accessor_class_time.cc +++ b/src/grib_accessor_class_time.cc @@ -160,7 +160,37 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -/* TODO: Check for a valid date */ +// In the 24-hour time notation, the day begins at midnight, 00:00 or 0:00, +// and the last minute of the day begins at 23:59. +// Where convenient, the notation 24:00 may also be used to refer to midnight +// at the end of a given date — that is, 24:00 of one day is the same time +// as 00:00 of the following day +#if 0 +static bool isValidTime(long number) +{ + // Check if the number is a four-digit integer + if (number < 0 || number > 9999) { + return false; + } + + // Extract hours and minutes + long hours = number / 100; // Get the first two digits as hours + long minutes = number % 100; // Get the last two digits as minutes + + // Check if hours are within the valid range (00-23) + if (hours < 0 || hours > 24) { + return false; + } + + // Check if minutes are within the valid range (00-59) + if (minutes < 0 || minutes > 59) { + return false; + } + + // All checks pass + return true; +} +#endif static int pack_long(grib_accessor* a, const long* val, size_t* len) { @@ -175,6 +205,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; + // if (!isValidTime(v)) { + // return GRIB_ENCODING_ERROR; + // } + hour = v / 100; minute = v % 100; second = 0; /* We ignore the 'seconds' in our time calculation! */ diff --git a/tests/grib_util_set_spec2.sh b/tests/grib_util_set_spec2.sh index 95fc00c01..fa289d291 100755 --- a/tests/grib_util_set_spec2.sh +++ b/tests/grib_util_set_spec2.sh @@ -10,4 +10,5 @@ . ./include.ctest.sh +export ECCODES_DEBUG=-1 $EXEC ${test_dir}/grib_util_set_spec2 From 50641af986f913d7b484e5a76c67ce8746a163e4 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 10:46:03 +0000 Subject: [PATCH 088/156] Testing: grib_util_set_spec --- tests/grib_util_set_spec2.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc index 5a0b69264..b032fcc1c 100644 --- a/tests/grib_util_set_spec2.cc +++ b/tests/grib_util_set_spec2.cc @@ -84,6 +84,9 @@ static grib_handle* test2() packing_spec.extra_settings[0].name = "tablesVersion"; packing_spec.extra_settings[0].long_value = 32; + packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER; + packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); From 95da948d3c867e326a57f468f6f3f37b709ad263 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 11:29:00 +0000 Subject: [PATCH 089/156] ECC-1706: Definitions: Align WMO Common Code Table 11 with ecCodes c-11 table (Part 1) --- definitions/common/c-11.table | 54 ++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/definitions/common/c-11.table b/definitions/common/c-11.table index 6c52dbf48..778001045 100644 --- a/definitions/common/c-11.table +++ b/definitions/common/c-11.table @@ -2,19 +2,26 @@ 0 0 WMO Secretariat 1 ammc Melbourne (WMC) 2 2 Melbourne (WMC) +3 3 Melbourne (WMC) 4 rums Moscow (WMC) 5 5 Moscow (WMC) +6 6 Moscow (WMC) 7 kwbc US National Weather Service - NCEP (WMC) 8 8 US National Weather Service - NWSTG (WMC) 9 9 US National Weather Service - Other (WMC) 10 10 Cairo (RSMC/RAFC) +11 11 Cairo (RSMC/RAFC) 12 12 Dakar (RSMC/RAFC) +13 13 Dakar (RSMC/RAFC) 14 14 Nairobi (RSMC/RAFC) -16 16 Atananarivo (RSMC) +15 15 Nairobi (RSMC/RAFC) +16 16 Casablanca (RSMC) +17 17 Tunis (RSMC) 18 18 Tunis-Casablanca (RSMC) 20 20 Las Palmas (RAFC) 21 21 Algiers (RSMC) -22 22 Lagos (RSMC) +22 22 ACMAD +23 23 Mozambique (NMC) 24 fapr Pretoria (RSMC) 26 26 Khabarovsk (RSMC) 28 vabb New Delhi (IMD) @@ -23,27 +30,38 @@ 32 32 Tashkent (RSMC) 33 33 Jeddah (RSMC) 34 rjtd Japanese Meteorological Agency - Tokyo (RSMC) -36 36 Bankok -37 37 Ulan Bator +36 36 Bangkok +37 37 Ulaanbaatar 38 babj Beijing (RSMC) 40 rksl Seoul 41 sabm Buenos Aires (RSMC/RAFC) 43 43 Brasilia (RSMC/RAFC) 45 45 Santiago 46 sbsj Brasilian Space Agency - INPE +47 47 Colombia (NMC) +48 48 Ecuador (NMC) +49 49 Peru (NMC) +50 50 Venezuela (Bolivarian Republic of) (NMC) 51 51 Miami (RSMC/RAFC) 52 52 National Hurricane Center, Miami 53 53 Canadian Meteorological Service - Montreal (RSMC) 54 cwao Canadian Meteorological Service - Montreal (RSMC) 55 55 San Francisco +56 56 ARINC Centre 57 57 U.S. Air Force - Global Weather Center 58 fnmo US Navy - Fleet Numerical Oceanography Center 59 59 NOAA Forecast Systems Lab, Boulder CO 60 60 National Center for Atmospheric Research (NCAR), Boulder, CO +61 61 Service ARGOS - Landover +62 62 US Naval Oceanographic Office +63 63 International Research Institute for Climate and Society (IRI) 64 64 Honolulu 65 65 Darwin (RSMC) 67 67 Melbourne (RSMC) 69 nzkl Wellington (RSMC/RAFC) +71 71 Nadi (RSMC) +72 72 Singapore +73 73 Malaysia (NMC) 74 egrr U.K. Met Office - Exeter 76 76 Moscow (RSMC/RAFC) 78 edzw Offenbach (RSMC) @@ -65,9 +83,34 @@ 97 97 European Space Agency (ESA) 98 ecmf European Centre for Medium-Range Weather Forecasts 99 99 DeBilt, Netherlands +100 100 Brazzaville +101 101 Abidjan +102 102 Libya (NMC) +103 103 Madagascar (NMC) +104 104 Mauritius (NMC) +105 105 Niger (NMC) +106 106 Seychelles (NMC) +107 107 Uganda (NMC) +108 108 United Republic of Tanzania (NMC) +109 109 Zimbabwe (NMC) 110 110 Hong-Kong +145 145 French Guiana +146 146 Brazilian Navy Hydrographic Centre +147 147 National Commission on Space Activities (CONAE) - Argentina +148 148 Brazilian Department of Airspace Control - DECEA 160 160 US NOAA/NESDIS +161 161 US NOAA Office of Oceanic and Atmospheric Research 173 nasa US National Aeronautics and Space Administration (NASA) + +174 174 Integrated Science Data Management/Marine Environmental Data Service (ISDM/MEDS - Canada) +175 175 University Corporation for Atmospheric Research (UCAR) - United States +176 176 Cooperative Institute for Meteorological Satellite Studies (CIMSS) - United States +177 177 NOAA National Ocean Service - United States +178 178 Spire Global, Inc. +179 179 GeoOptics, Inc. +180 180 PlanetiQ +181 181 Atmospheric and Environmental Research (AER) + 195 wiix Indonesia (NMC) 204 niwa National Institute of Water and Atmospheric Research (NIWA - New Zealand) 210 210 Frascati (ESA/ESRIN) @@ -85,6 +128,8 @@ 222 222 Albania (NMC) 223 223 Armenia (NMC) 224 lowm Austria +225 225 Azerbaijan (NMC) +226 226 Belarus (NMC) 227 ebum Belgium (NMC) 228 228 Bosnia and Herzegovina (NMC) 229 229 Bulgaria (NMC) @@ -94,6 +139,7 @@ 233 eidb Dublin 234 234 Israel (NMC) 235 ingv INGV +238 238 Lithuania (NMC) 239 crfc CERFAX 240 240 Malta (NMC) 241 241 Monaco From d31f36f66b9b7301e46dac018fc995a73bbd9481 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 12:36:48 +0000 Subject: [PATCH 090/156] Testing: grib_util_set_spec edition conversion --- tests/grib_util_set_spec2.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/grib_util_set_spec2.cc b/tests/grib_util_set_spec2.cc index b032fcc1c..ddd3f1dc5 100644 --- a/tests/grib_util_set_spec2.cc +++ b/tests/grib_util_set_spec2.cc @@ -14,12 +14,13 @@ static void dump_it(grib_handle* h) { int dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY; - grib_dump_content(h, stdout, "wmo", dump_flags, NULL); + grib_dump_content(h, stderr, "wmo", dump_flags, NULL); } // Lambert conformal static grib_handle* test0() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -47,6 +48,7 @@ static grib_handle* test0() // Lambert azimuthal static grib_handle* test1() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -68,6 +70,7 @@ static grib_handle* test1() // HEALPix static grib_handle* test2() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -75,17 +78,13 @@ static grib_handle* test2() int set_spec_flags = 0; size_t outlen = 4; - grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); + grib_handle* handle = grib_handle_new_from_samples(0, "GRIB1"); spec.grid_type = GRIB_UTIL_GRID_SPEC_HEALPIX; spec.N = 2; - packing_spec.extra_settings_count = 1; - packing_spec.extra_settings[0].type = GRIB_TYPE_LONG; - packing_spec.extra_settings[0].name = "tablesVersion"; - packing_spec.extra_settings[0].long_value = 32; - packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER; packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED; + packing_spec.editionNumber = 2; grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, @@ -97,6 +96,7 @@ static grib_handle* test2() // Spherical harmonics static grib_handle* test3() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -124,6 +124,7 @@ static grib_handle* test3() // Polar stereo static grib_handle* test4() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -132,10 +133,15 @@ static grib_handle* test4() size_t outlen = 0; grib_handle* handle = grib_handle_new_from_samples(0, "GRIB2"); - grib_set_long(handle, "tablesVersion", 32); + //grib_set_long(handle, "tablesVersion", 32); spec.grid_type = GRIB_UTIL_GRID_SPEC_POLAR_STEREOGRAPHIC; outlen = 4; + packing_spec.extra_settings_count = 1; + packing_spec.extra_settings[0].type = GRIB_TYPE_LONG; + packing_spec.extra_settings[0].name = "tablesVersion"; + packing_spec.extra_settings[0].long_value = 32; + grib_handle* finalh = grib_util_set_spec( handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err); @@ -146,6 +152,7 @@ static grib_handle* test4() // Regular Gaussian static grib_handle* test5() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -168,6 +175,7 @@ static grib_handle* test5() // Reduced LL static grib_handle* test6() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; @@ -190,6 +198,7 @@ static grib_handle* test6() // Unstructured static grib_handle* test7() { + fprintf(stderr, "Doing test %s\n-----------------\n", __func__); int err = 0; grib_util_grid_spec spec = {0,}; grib_util_packing_spec packing_spec = {0,}; From 29fb82739144fbc8b6e7b8f3c44a24167dc26cfd Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 13:30:59 +0000 Subject: [PATCH 091/156] Compiler warnings: format specifiers --- src/grib_accessor_class_md5.cc | 2 +- src/grib_accessor_class_optimal_step_units.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/grib_accessor_class_md5.cc b/src/grib_accessor_class_md5.cc index dfb08a7fb..6a57c1329 100644 --- a/src/grib_accessor_class_md5.cc +++ b/src/grib_accessor_class_md5.cc @@ -183,7 +183,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len) if (*len < 32) { const char* cclass_name = a->cclass->name; grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + "%s: Buffer too small for %s. It is %d bytes long (len=%zu)", cclass_name, a->name, 32, *len); *len = 32; return GRIB_BUFFER_TOO_SMALL; diff --git a/src/grib_accessor_class_optimal_step_units.cc b/src/grib_accessor_class_optimal_step_units.cc index 9bcf338be..261ff4c80 100644 --- a/src/grib_accessor_class_optimal_step_units.cc +++ b/src/grib_accessor_class_optimal_step_units.cc @@ -192,7 +192,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) 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, msg.c_str()); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INVALID_ARGUMENT; } @@ -235,7 +235,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, e.what()); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s", e.what()); return GRIB_INTERNAL_ERROR; } @@ -256,7 +256,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) supported_units_str.pop_back(); std::string msg = "Invalid unit: " + std::string(val) + " (" + e.what() + ")" + ". Available units are: " + supported_units_str; - grib_context_log(a->context, GRIB_LOG_ERROR, msg.c_str()); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INVALID_ARGUMENT; } From 1eb99c0bf8edfbf9112fdb657be19eb5cf676496 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 13:54:02 +0000 Subject: [PATCH 092/156] Testing: Julian dates --- tests/julian.cc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/julian.cc b/tests/julian.cc index 318429e79..b51157e63 100644 --- a/tests/julian.cc +++ b/tests/julian.cc @@ -14,18 +14,14 @@ #define EPSILON 1e-12 #define DBL_EQUAL(a, b) (fabs((a) - (b)) <= (EPSILON)*fabs((a))) -#define BOOL int -#define TRUE 1 -#define FALSE 0 - -static BOOL Check( +static bool Check( const long year1, const long month1, const long day1, const long hour1, const long min1, const long sec1, const long year2, const long month2, const long day2, const long hour2, const long min2, const long sec2) { if (year1 != year2 || month1 != month2 || day1 != day2 || hour1 != hour2 || min1 != min2 || sec1 != sec2) { - return FALSE; + return false; } - return TRUE; + return true; } static void TestDateTime(const long year, const long month, const long day, const long hour, const long min, const long sec) @@ -184,6 +180,7 @@ static void Test3() static void Test4() { const long iyear = 1582; + printf("Test4...\n"); TestDateTime(iyear, 9, 1, 1, 0, 0); TestDateTime(iyear, 9, 2, 1, 0, 0); @@ -215,6 +212,21 @@ static void Test4() */ } +static void Test5() +{ + printf("Test5...\n"); + double jd = 0.0; + long year=2017, month=2, day=29, hour=0, min=0, sec=0; // Feb 2017 had 28 days + long year1, month1, day1, hour1, min1, sec1; + + codes_datetime_to_julian(year, month, day, hour, min, sec, &jd); + codes_julian_to_datetime(jd, &year1, &month1, &day1, &hour1, &min1, &sec1); + + if (Check(year, month, day, hour, min, sec, year1, month1, day1, hour1, min1, sec1)) { + Assert(!"Bad input should have failed checks"); + } +} + int main(int argc, char* argv[]) { Test0(); @@ -222,6 +234,7 @@ int main(int argc, char* argv[]) Test2(); Test3(); Test4(); + Test5(); printf("All OK\n"); return 0; } From e68e56d2aad76775354dd9ef602e3ec27f809d2f Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 13:55:45 +0000 Subject: [PATCH 093/156] Testing: Julian dates --- tests/julian.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/julian.cc b/tests/julian.cc index b51157e63..559d9883a 100644 --- a/tests/julian.cc +++ b/tests/julian.cc @@ -215,6 +215,9 @@ static void Test4() static void Test5() { printf("Test5...\n"); + + // Also see function is_date_valid() + double jd = 0.0; long year=2017, month=2, day=29, hour=0, min=0, sec=0; // Feb 2017 had 28 days long year1, month1, day1, hour1, min1, sec1; From 8b4d1eb323ffa30cb305359931d861202951da98 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 14:47:50 +0000 Subject: [PATCH 094/156] Testing: Fix julian test --- data/julian.out.good | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/julian.out.good b/data/julian.out.good index c1321285c..c897c9476 100644 --- a/data/julian.out.good +++ b/data/julian.out.good @@ -62,4 +62,6 @@ Test2... - -47120001 -> 6 Test3... +Test4... +Test5... All OK From e2368676b3937a68f1a25be6d4a378089efcf4a2 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 15:36:21 +0000 Subject: [PATCH 095/156] ECC-1777: Validate dataDate and dataTime on input --- src/codes_util.cc | 32 +++++++++++++++ src/eccodes_prototypes.h | 1 + src/grib_accessor_class_g2date.cc | 17 +++++--- src/grib_accessor_class_time.cc | 65 ++++++++----------------------- tests/grib_set_fail.sh | 12 ++++++ 5 files changed, 73 insertions(+), 54 deletions(-) diff --git a/src/codes_util.cc b/src/codes_util.cc index 1b73432f8..3ff4ac353 100644 --- a/src/codes_util.cc +++ b/src/codes_util.cc @@ -213,6 +213,38 @@ int is_date_valid(long year, long month, long day, long hour, long minute, doubl return 1; } +// Return 1 if input date is valid. Otherwise 0 +// Note: In the 24-hour time notation, the day begins at midnight, 00:00 or 0:00, +// and the last minute of the day begins at 23:59. +// Where convenient, the notation 24:00 may also be used to refer to midnight +// at the end of a given date — that is, 24:00 of one day is the same time +// as 00:00 of the following day +int is_time_valid(long number) +{ + // number should be 4 digits i.e., HHMM + // Check if the number is a four-digit integer + if (number < 0 || number > 9999) { + return 0; + } + + // Extract hours and minutes + long hours = number / 100; // Get the first two digits as hours + long minutes = number % 100; // Get the last two digits as minutes + + // Check if hours are within the valid range (00-23) + if (hours < 0 || hours > 24) { + return 0; + } + + // Check if minutes are within the valid range (00-59) + if (minutes < 0 || minutes > 59) { + return 0; + } + + // All checks pass + return 1; +} + static float float_epsilon(void) { float floatEps = 1.0; diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index e26aace4e..db119f1ce 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1328,6 +1328,7 @@ char* codes_getenv(const char* name); int codes_check_grib_ieee_packing_value(int value); int codes_flush_sync_close_file(FILE* f); int is_date_valid(long year, long month, long day, long hour, long minute, double second); +int is_time_valid(long number); // number is HHMM int compute_scaled_value_and_scale_factor(double input, int64_t scaled_value_max, int64_t scale_factor_max, int64_t* ret_value, int64_t* ret_factor); /* grib_util.cc*/ diff --git a/src/grib_accessor_class_g2date.cc b/src/grib_accessor_class_g2date.cc index 4ed01d99e..c85e86b9e 100644 --- a/src/grib_accessor_class_g2date.cc +++ b/src/grib_accessor_class_g2date.cc @@ -123,9 +123,9 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t* len) { - int ret = 0; - grib_accessor_g2date* self = (grib_accessor_g2date*)a; + const grib_accessor_g2date* self = (grib_accessor_g2date*)a; + int ret = 0; long year = 0; long month = 0; long day = 0; @@ -145,13 +145,12 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -/* TODO: Check for a valid date */ static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int ret; - long v = val[0]; - grib_accessor_g2date* self = (grib_accessor_g2date*)a; + const grib_accessor_g2date* self = (grib_accessor_g2date*)a; + int ret = GRIB_SUCCESS; + long v = val[0]; long year = 0; long month = 0; long day = 0; @@ -165,6 +164,12 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) v %= 100; day = v; + if (!is_date_valid(year, month, day, 0, 0, 0)) { + // ECC-1777: For now just a warning. Will later change to an error + fprintf(stderr, "ECCODES WARNING : %s:%s: Date is not valid! year=%ld month=%ld day=%ld\n", + a->cclass->name, __func__, year, month, day); + } + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) return ret; if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) diff --git a/src/grib_accessor_class_time.cc b/src/grib_accessor_class_time.cc index d38a53b7c..36aa290c9 100644 --- a/src/grib_accessor_class_time.cc +++ b/src/grib_accessor_class_time.cc @@ -126,12 +126,11 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t* len) { - int ret = 0; - grib_accessor_time* self = (grib_accessor_time*)a; - long hour = 0; - long minute = 0; - long second = 0; - grib_handle* hand = grib_handle_of_accessor(a); + const grib_accessor_time* self = (grib_accessor_time*)a; + + int ret = 0; + long hour = 0, minute = 0, second = 0; + grib_handle* hand = grib_handle_of_accessor(a); if ((ret = grib_get_long_internal(hand, self->hour, &hour)) != GRIB_SUCCESS) return ret; @@ -160,54 +159,24 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -// In the 24-hour time notation, the day begins at midnight, 00:00 or 0:00, -// and the last minute of the day begins at 23:59. -// Where convenient, the notation 24:00 may also be used to refer to midnight -// at the end of a given date — that is, 24:00 of one day is the same time -// as 00:00 of the following day -#if 0 -static bool isValidTime(long number) -{ - // Check if the number is a four-digit integer - if (number < 0 || number > 9999) { - return false; - } - - // Extract hours and minutes - long hours = number / 100; // Get the first two digits as hours - long minutes = number % 100; // Get the last two digits as minutes - - // Check if hours are within the valid range (00-23) - if (hours < 0 || hours > 24) { - return false; - } - - // Check if minutes are within the valid range (00-59) - if (minutes < 0 || minutes > 59) { - return false; - } - - // All checks pass - return true; -} -#endif - static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int ret = 0; - long v = val[0]; - grib_accessor_time* self = (grib_accessor_time*)a; - grib_handle* hand = grib_handle_of_accessor(a); - long hour = 0; - long minute = 0; - long second = 0; + const grib_accessor_time* self = (grib_accessor_time*)a; + + int ret = 0; + long v = val[0]; + grib_handle* hand = grib_handle_of_accessor(a); + long hour = 0, minute = 0, second = 0; if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; - // if (!isValidTime(v)) { - // return GRIB_ENCODING_ERROR; - // } + if (!is_time_valid(v)) { + // ECC-1777: For now just a warning. Will later change to an error + fprintf(stderr, "ECCODES WARNING : %s:%s: Time is not valid! hour=%ld min=%ld sec=%ld\n", + a->cclass->name, __func__, hour, minute, second); + // return GRIB_ENCODING_ERROR; + } hour = v / 100; minute = v % 100; diff --git a/tests/grib_set_fail.sh b/tests/grib_set_fail.sh index 1d850141e..d4c2a0b4e 100755 --- a/tests/grib_set_fail.sh +++ b/tests/grib_set_fail.sh @@ -95,6 +95,18 @@ status=$? set -e [ $status -ne 0 ] +# Bad date +# --------- +input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl +${tools_dir}/grib_set -s dataDate=20180229 $input $outfile > $temp 2>&1 +cat $temp +grep -q "Date is not valid" $temp + +${tools_dir}/grib_set -s dataTime=4261 $input $outfile > $temp 2>&1 +cat $temp +grep -q "Time is not valid" $temp + + # ECC-1359: string that can be converted to an integer # --------------------------------------------------- ${tools_dir}/grib_set -s month:s=6 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile From b9dcf3fb63485b3dac50d8f24078b2c0677a6bec Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 16:03:46 +0000 Subject: [PATCH 096/156] ECC-1777: Validate dataDate and dataTime on input --- tests/grib_set_fail.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/grib_set_fail.sh b/tests/grib_set_fail.sh index d4c2a0b4e..1a44b5a3b 100755 --- a/tests/grib_set_fail.sh +++ b/tests/grib_set_fail.sh @@ -95,17 +95,30 @@ status=$? set -e [ $status -ne 0 ] -# Bad date -# --------- +# ECC-1777: Bad date/time +# ------------------------- input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl ${tools_dir}/grib_set -s dataDate=20180229 $input $outfile > $temp 2>&1 -cat $temp grep -q "Date is not valid" $temp ${tools_dir}/grib_set -s dataTime=4261 $input $outfile > $temp 2>&1 -cat $temp grep -q "Time is not valid" $temp +${tools_dir}/grib_set -s dataTime=2501 $input $outfile > $temp 2>&1 +grep -q "Time is not valid" $temp + +# Note for GRIB1 we DO fail on a bad date! This need to be consistent across editions +input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl +set +e +${tools_dir}/grib_set -s dataDate=20180229 $input $outfile > $temp 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "invalid date 20180229" $temp + +# 2016 did have 29th Feb +${tools_dir}/grib_set -s dataDate=20160229 $input $outfile + # ECC-1359: string that can be converted to an integer # --------------------------------------------------- From b2c381d6b8b37351fcc23f938f6ac55e0bc5bd2a Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 16:39:30 +0000 Subject: [PATCH 097/156] Cleanup --- src/codes_util.cc | 3 +-- src/grib_accessor_class_g1date.cc | 43 ++++++++++++------------------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/codes_util.cc b/src/codes_util.cc index 3ff4ac353..2d91fa598 100644 --- a/src/codes_util.cc +++ b/src/codes_util.cc @@ -221,8 +221,7 @@ int is_date_valid(long year, long month, long day, long hour, long minute, doubl // as 00:00 of the following day int is_time_valid(long number) { - // number should be 4 digits i.e., HHMM - // Check if the number is a four-digit integer + // Number should be 4 digits i.e., HHMM if (number < 0 || number > 9999) { return 0; } diff --git a/src/grib_accessor_class_g1date.cc b/src/grib_accessor_class_g1date.cc index 37cd80ad5..10294a935 100644 --- a/src/grib_accessor_class_g1date.cc +++ b/src/grib_accessor_class_g1date.cc @@ -129,14 +129,11 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int unpack_long(grib_accessor* a, long* val, size_t* len) { - int ret = 0; grib_accessor_g1date* self = (grib_accessor_g1date*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(a); - long year = 0; - long century = 0; - long month = 0; - long day = 0; + int ret = 0; + long year = 0, century = 0, month = 0, day = 0; if ((ret = grib_get_long_internal(hand, self->century, ¢ury)) != GRIB_SUCCESS) return ret; @@ -165,25 +162,20 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) static int pack_long(grib_accessor* a, const long* val, size_t* len) { - int ret = 0; - long v = val[0]; grib_accessor_g1date* self = (grib_accessor_g1date*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(a); - long year = 0; - long century = 0; - long month = 0; - long day = 0; + int ret = 0; + long v = val[0]; + long year = 0, century = 0, month = 0, day = 0; if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; - { - long d = grib_julian_to_date((long)grib_date_to_julian(v)); - if (v != d) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g1date: pack_long invalid date %ld, changed to %ld", v, d); - return GRIB_ENCODING_ERROR; - } + long d = grib_julian_to_date(grib_date_to_julian(v)); + if (v != d) { + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g1date: pack_long invalid date %ld, changed to %ld", v, d); + return GRIB_ENCODING_ERROR; } century = v / 1000000; @@ -228,15 +220,12 @@ static const char* months[] = { static int unpack_string(grib_accessor* a, char* val, size_t* len) { - int ret = 0; - char tmp[1024]; grib_accessor_g1date* self = (grib_accessor_g1date*)a; grib_handle* hand = grib_handle_of_accessor(a); - long year = 0; - long century = 0; - long month = 0; - long day = 0; - size_t l; + + int ret = 0; + char tmp[1024]; + long year = 0, century = 0, month = 0, day = 0; if ((ret = grib_get_long_internal(hand, self->century, ¢ury)) != GRIB_SUCCESS) return ret; @@ -261,7 +250,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) snprintf(tmp, sizeof(tmp), "%ld", x); } - l = strlen(tmp) + 1; + size_t l = strlen(tmp) + 1; if (*len < l) { *len = l; return GRIB_BUFFER_TOO_SMALL; From 1fc934731609204cc7e4cfef0f50ced56defe005 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 17:48:00 +0000 Subject: [PATCH 098/156] Reformatting --- ...cessor_class_data_apply_boustrophedonic.cc | 32 ++++---- src/grib_dumper_class_bufr_encode_C.cc | 79 ++++++++++--------- src/grib_dumper_class_bufr_encode_fortran.cc | 78 ++++++++++-------- 3 files changed, 103 insertions(+), 86 deletions(-) diff --git a/src/grib_accessor_class_data_apply_boustrophedonic.cc b/src/grib_accessor_class_data_apply_boustrophedonic.cc index 1f10885e0..e01917384 100644 --- a/src/grib_accessor_class_data_apply_boustrophedonic.cc +++ b/src/grib_accessor_class_data_apply_boustrophedonic.cc @@ -119,7 +119,7 @@ grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic = &_grib_acc static void init(grib_accessor* a, const long v, grib_arguments* args) { - int n = 0; + int n = 0; grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); @@ -138,10 +138,10 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int value_count(grib_accessor* a, long* numberOfPoints) { grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; - int ret = 0; + int ret = 0; *numberOfPoints = 0; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints); + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints); return ret; } @@ -150,12 +150,13 @@ template static int unpack(grib_accessor* a, T* val, size_t* len) { grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; - size_t plSize = 0; - long* pl = 0; - double* values = 0; - double* pvalues = 0; - T* pval = 0; - size_t valuesSize = 0; + + size_t plSize = 0; + long* pl = 0; + double* values = 0; + double* pvalues = 0; + T* pval = 0; + size_t valuesSize = 0; long i, j; int ret; long numberOfPoints, numberOfRows, numberOfColumns; @@ -306,12 +307,13 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array static int pack_double(grib_accessor* a, const double* val, size_t* len) { grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; - size_t plSize = 0; - long* pl = 0; - double* values = 0; - double* pvalues = 0; - double* pval = 0; - size_t valuesSize = 0; + + size_t plSize = 0; + long* pl = 0; + double* values = 0; + double* pvalues = 0; + double* pval = 0; + size_t valuesSize = 0; long i, j; int ret; long numberOfPoints, numberOfRows, numberOfColumns; diff --git a/src/grib_dumper_class_bufr_encode_C.cc b/src/grib_dumper_class_bufr_encode_C.cc index d07825434..568a035bb 100644 --- a/src/grib_dumper_class_bufr_encode_C.cc +++ b/src/grib_dumper_class_bufr_encode_C.cc @@ -102,13 +102,14 @@ static void init_class(grib_dumper_class* c) {} static int init(grib_dumper* d) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - grib_context* c = d->context; - self->section_offset = 0; - self->empty = 1; - d->count = 1; - self->isLeaf = 0; - self->isAttribute = 0; - self->keys = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); + + grib_context* c = d->context; + self->section_offset = 0; + self->empty = 1; + d->count = 1; + self->isLeaf = 0; + self->isAttribute = 0; + self->keys = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); return GRIB_SUCCESS; } @@ -116,9 +117,9 @@ static int init(grib_dumper* d) static int destroy(grib_dumper* d) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - grib_string_list* next = self->keys; - grib_string_list* cur = NULL; - grib_context* c = d->context; + grib_string_list* next = self->keys; + grib_string_list* cur = NULL; + grib_context* c = d->context; while (next) { cur = next; next = next->next; @@ -152,10 +153,11 @@ static char* dval_to_string(grib_context* c, double v) static void dump_values(grib_dumper* d, grib_accessor* a) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - double value = 0; + + double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; + double* values = NULL; + int err = 0; int i, r, icount; int cols = 2; long count = 0; @@ -248,10 +250,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* prefix) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - double value = 0; + + double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; + double* values = NULL; + int err = 0; int i, icount; int cols = 2; long count = 0; @@ -333,16 +336,17 @@ static int is_hidden(grib_accessor* a) static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - long value = 0; + + long value = 0; size_t size = 0, size2 = 0; - long* values = NULL; - int err = 0; + long* values = NULL; + int err = 0; int i, r, icount; - int cols = 4; - long count = 0; - char* sval = NULL; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + int cols = 4; + long count = 0; + char* sval = NULL; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); int doing_unexpandedDescriptors = 0; if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ @@ -471,10 +475,11 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* prefix) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - long value = 0; + + long value = 0; size_t size = 0, size2 = 0; - long* values = NULL; - int err = 0; + long* values = NULL; + int err = 0; int i, icount; int cols = 4; long count = 0; @@ -552,8 +557,9 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - double value = 0; - size_t size = 1; + + double value = 0; + size_t size = 1; int r; char* sval; grib_handle* h = grib_handle_of_accessor(a); @@ -667,12 +673,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - char* value = NULL; - char* p = NULL; - size_t size = 0; - grib_context* c = a->context; + + char* value = NULL; + char* p = NULL; + size_t size = 0; + grib_context* c = a->context; int r = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); const char* acc_name = a->name; grib_get_string_length_acc(a, &size); @@ -814,7 +821,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix) { - int i = 0; + int i = 0; grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; unsigned long flags; while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { @@ -846,7 +853,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix static void header(grib_dumper* d, grib_handle* h) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - char sampleName[200] = { 0 }; + char sampleName[200] = { 0 }; long localSectionPresent, edition, bufrHeaderCentre, isSatellite; Assert(h->product_kind == PRODUCT_BUFR); diff --git a/src/grib_dumper_class_bufr_encode_fortran.cc b/src/grib_dumper_class_bufr_encode_fortran.cc index c689867b8..e76bd0872 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.cc +++ b/src/grib_dumper_class_bufr_encode_fortran.cc @@ -103,13 +103,14 @@ static void init_class(grib_dumper_class* c) {} static int init(grib_dumper* d) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - grib_context* c = d->context; - self->section_offset = 0; - self->empty = 1; - d->count = 1; - self->isLeaf = 0; - self->isAttribute = 0; - self->keys = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); + + grib_context* c = d->context; + self->section_offset = 0; + self->empty = 1; + d->count = 1; + self->isLeaf = 0; + self->isAttribute = 0; + self->keys = (grib_string_list*)grib_context_malloc_clear(c, sizeof(grib_string_list)); return GRIB_SUCCESS; } @@ -117,9 +118,10 @@ static int init(grib_dumper* d) static int destroy(grib_dumper* d) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - grib_string_list* next = self->keys; - grib_string_list* cur = NULL; - grib_context* c = d->context; + + grib_string_list* next = self->keys; + grib_string_list* cur = NULL; + grib_context* c = d->context; while (next) { cur = next; next = next->next; @@ -200,10 +202,11 @@ static char* break_line(grib_context* c, const char* input) static void dump_values(grib_dumper* d, grib_accessor* a) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - double value = 0; + + double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; + double* values = NULL; + int err = 0; int i, r, icount; int cols = 2; long count = 0; @@ -295,10 +298,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* prefix) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - double value = 0; + + double value = 0; size_t size = 0, size2 = 0; - double* values = NULL; - int err = 0; + double* values = NULL; + int err = 0; int i, icount; int cols = 2; long count = 0; @@ -381,16 +385,17 @@ static int is_hidden(grib_accessor* a) static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - long value = 0; + + long value = 0; size_t size = 0, size2 = 0; - long* values = NULL; - int err = 0; + long* values = NULL; + int err = 0; int i, r, icount; - int cols = 4; - long count = 0; - char* sval = NULL; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + int cols = 4; + long count = 0; + char* sval = NULL; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); int doing_unexpandedDescriptors = 0; if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ @@ -516,10 +521,11 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* prefix) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - long value = 0; + + long value = 0; size_t size = 0, size2 = 0; - long* values = NULL; - int err = 0; + long* values = NULL; + int err = 0; int i, icount; int cols = 4; long count = 0; @@ -603,8 +609,9 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - double value = 0; - size_t size = 1; + + double value = 0; + size_t size = 1; int r; char* sval; grib_handle* h = grib_handle_of_accessor(a); @@ -715,10 +722,11 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - char* value = NULL; - char* p = NULL; - size_t size = 0; - grib_context* c = a->context; + + char* value = NULL; + char* p = NULL; + size_t size = 0; + grib_context* c = a->context; int r; int err = 0; grib_handle* h = grib_handle_of_accessor(a); @@ -860,7 +868,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix) { - int i = 0; + int i = 0; grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; unsigned long flags; while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { @@ -892,7 +900,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix static void header(grib_dumper* d, grib_handle* h) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - char sampleName[200] = { 0 }; + char sampleName[200] = { 0 }; long localSectionPresent, edition, bufrHeaderCentre, isSatellite; grib_get_long(h, "localSectionPresent", &localSectionPresent); From 3614dfdc5a857df77e66b109c41d0bbc5631a327 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 17:49:15 +0000 Subject: [PATCH 099/156] Openjpeg 2.5.1: Fix compilation --- src/grib_openjpeg_encoding.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/grib_openjpeg_encoding.cc b/src/grib_openjpeg_encoding.cc index 6b726a97a..381e36c22 100644 --- a/src/grib_openjpeg_encoding.cc +++ b/src/grib_openjpeg_encoding.cc @@ -13,6 +13,7 @@ #if HAVE_LIBOPENJPEG #include "openjpeg.h" +#include "opj_config.h" static void openjpeg_warning(const char* msg, void* client_data) { From 24e13c4f8a8f7c56ca7e9d4af76d701cbb8ae328 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 18:06:33 +0000 Subject: [PATCH 100/156] Bamboo CIE: Have to disable OpenJPEG for now as it is too old --- bamboo/flags.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bamboo/flags.cmake b/bamboo/flags.cmake index 2c5a809e2..4c4a1ede8 100644 --- a/bamboo/flags.cmake +++ b/bamboo/flags.cmake @@ -1,3 +1,4 @@ -SET(ENABLE_EXTRA_TESTS ON CACHE BOOL "Enable extra tests") -SET(ENABLE_ECCODES_THREADS ON CACHE BOOL "Enable POSIX threads") -SET(ENABLE_MEMFS ON CACHE BOOL "Enable MEMFS") +SET(ENABLE_EXTRA_TESTS ON CACHE BOOL "Enable extra tests") +SET(ENABLE_ECCODES_THREADS ON CACHE BOOL "Enable POSIX threads") +SET(ENABLE_MEMFS ON CACHE BOOL "Enable MEMFS") +SET(ENABLE_JPG_LIBOPENJPEG OFF CACHE BOOL "Disable OpenJPEG") From 66e39ad3e87eb6bed44faecb22900865bf3db000 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 28 Feb 2024 19:35:25 +0000 Subject: [PATCH 101/156] Openjpeg 2.5.1: Try again --- bamboo/flags.cmake | 2 +- src/grib_openjpeg_encoding.cc | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bamboo/flags.cmake b/bamboo/flags.cmake index 4c4a1ede8..832133409 100644 --- a/bamboo/flags.cmake +++ b/bamboo/flags.cmake @@ -1,4 +1,4 @@ SET(ENABLE_EXTRA_TESTS ON CACHE BOOL "Enable extra tests") SET(ENABLE_ECCODES_THREADS ON CACHE BOOL "Enable POSIX threads") SET(ENABLE_MEMFS ON CACHE BOOL "Enable MEMFS") -SET(ENABLE_JPG_LIBOPENJPEG OFF CACHE BOOL "Disable OpenJPEG") +# SET(ENABLE_JPG_LIBOPENJPEG OFF CACHE BOOL "Disable OpenJPEG") diff --git a/src/grib_openjpeg_encoding.cc b/src/grib_openjpeg_encoding.cc index 381e36c22..9b3b67566 100644 --- a/src/grib_openjpeg_encoding.cc +++ b/src/grib_openjpeg_encoding.cc @@ -13,7 +13,11 @@ #if HAVE_LIBOPENJPEG #include "openjpeg.h" -#include "opj_config.h" +// The older versions did not have the opj_config.h file +// So we use a more recent macro to detect whether it is there +#if defined(OPJ_IMG_INFO) + #include "opj_config.h" +#endif static void openjpeg_warning(const char* msg, void* client_data) { From c9259f69eb088b323acf1753dfec52d394b4d272 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 13:36:35 +0000 Subject: [PATCH 102/156] Const correctness and cppcheck warnings --- src/eccodes_prototypes.h | 4 +- src/grib_util.cc | 182 +++++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index db119f1ce..34a63088f 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1345,9 +1345,9 @@ int grib2_is_PDTN_Aerosol(long productDefinitionTemplateNumber); int grib2_is_PDTN_AerosolOptical(long productDefinitionTemplateNumber); int grib2_select_PDTN(int is_eps, int is_instant, int is_chemical, int is_chemical_srcsink, int is_chemical_distfn, int is_aerosol, int is_aerosol_optical); size_t sum_of_pl_array(const long* pl, size_t plsize); -int grib_is_earth_oblate(grib_handle* h); +int grib_is_earth_oblate(const grib_handle* h); int grib_check_data_values_minmax(grib_handle* h, const double min_val, const double max_val); -int grib_producing_large_constant_fields(grib_handle* h, int edition); +int grib_producing_large_constant_fields(const grib_handle* h, int edition); int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max_val); /* bufr_util.cc*/ diff --git a/src/grib_util.cc b/src/grib_util.cc index c559eeacb..7ecc75f72 100644 --- a/src/grib_util.cc +++ b/src/grib_util.cc @@ -90,18 +90,18 @@ static grib_handle* grib_sections_copy_internal(grib_handle* hfrom, grib_handle* p = buffer; off = 0; for (i = 0; i <= hfrom->sections_count; i++) { - grib_handle* hand = NULL; + const grib_handle* hand = NULL; if (sections[i]) hand = hfrom; else hand = hto; - p = (unsigned char*)memcpy(p, hand->buffer->data + section_offset[i], section_length[i]); + p = (unsigned char*)memcpy(p, hand->buffer->data + section_offset[i], section_length[i]); section_offset[i] = off; off += section_length[i]; p += section_length[i]; } - /* copy section 3 present flag*/ + // copy section 3 present flag if (edition == 1) { const void* buffer_to = NULL; size_t size_to = 0; @@ -113,7 +113,7 @@ static grib_handle* grib_sections_copy_internal(grib_handle* hfrom, grib_handle* h = grib_handle_new_from_message(hfrom->context, buffer, totalLength); - /*to allow free of buffer*/ + // to allow freeing of buffer h->buffer->property = CODES_MY_BUFFER; switch (edition) { @@ -279,7 +279,7 @@ grib_handle* grib_util_sections_copy(grib_handle* hfrom, grib_handle* hto, int w static grib_trie* init_list(const char* name); static grib_trie* param_id_list = NULL; static grib_trie* mars_param_list = NULL; -/* TODO thread safe */ +// TODO thread safe grib_string_list* grib_util_get_param_id(const char* mars_param) { if (!mars_param_list && (mars_param_list = init_list("mars_param.table")) == NULL) @@ -382,13 +382,13 @@ static const char* get_packing_spec_packing_type_name(long packing_spec_packing_ return NULL; } -/* For debugging purposes */ -static void print_values(grib_context* c, +// For debugging purposes +static void print_values(const grib_context* c, const grib_util_grid_spec* spec, const grib_util_packing_spec* packing_spec, const char* input_packing_type, - const double* data_values, const size_t data_values_count, /* the data pay load */ - const grib_values* keyval_pairs, const size_t count) /* keys and their values */ + const double* data_values, const size_t data_values_count, // the data pay load + const grib_values* keyval_pairs, const size_t count) // keys and their values { size_t i = 0; int isConstant = 1; @@ -464,14 +464,12 @@ static void print_values(grib_context* c, } -/* -static int DBL_EQUAL(double d1, double d2, double tolerance) -{ - return fabs(d1-d2) < tolerance; -} -*/ +// static int DBL_EQUAL(double d1, double d2, double tolerance) +// { +// return fabs(d1-d2) < tolerance; +// } -// /* Returns a boolean: 1 if angle can be encoded, 0 otherwise */ +// Returns a boolean: 1 if angle can be encoded, 0 otherwise // static int grib1_angle_can_be_encoded(const double angle) // { // const double angle_milliDegrees = angle * 1000; @@ -480,10 +478,10 @@ static int DBL_EQUAL(double d1, double d2, double tolerance) // rounded = (int)(angle_milliDegrees-0.5)/1000.0; // } // if (angle == rounded) return 1; -// return 0; /* sub millidegree. Cannot be encoded in grib1 */ +// return 0; // sub millidegree. Cannot be encoded in grib1 // } -// /* Returns a boolean: 1 if angle can be encoded, 0 otherwise */ +// Returns a boolean: 1 if angle can be encoded, 0 otherwise // static int angle_can_be_encoded(const double angle, const double angular_precision) // { // const double angle_expanded = angle * angular_precision; @@ -493,18 +491,18 @@ static int DBL_EQUAL(double d1, double d2, double tolerance) // rounded = (long)(angle_expanded-0.5)/angular_precision; // } // if (angle == rounded) return 1; -// /*printf(" ......... angle cannot be encoded: %.10e\n", angle);*/ -// return 0; /* Cannot be encoded */ +// //printf(" ......... angle cannot be encoded: %.10e\n", angle); +// return 0; // Cannot be encoded // } -/* Returns a boolean: 1 if angle can be encoded, 0 otherwise */ -static int angle_can_be_encoded(grib_handle* h, const double angle) +// Returns a boolean: 1 if angle can be encoded, 0 otherwise +static int angle_can_be_encoded(const grib_handle* h, const double angle) { int ret = 0; int retval = 1; grib_handle* h2 = NULL; char sample_name[16] = {0,}; - long angle_subdivisions = 0; /* e.g. 1e3 for grib1 and 1e6 for grib2 */ + long angle_subdivisions = 0; // e.g. 1e3 for grib1 and 1e6 for grib2 long edition = 0, coded = 0; double expanded, diff; @@ -545,20 +543,19 @@ static double adjust_angle(const double angle, const RoundingPolicy policy, cons return result; } -/* Search key=value array for: - * latitudeOfFirstGridPointInDegrees - * longitudeOfFirstGridPointInDegrees - * latitudeOfLastGridPointInDegrees - * longitudeOfLastGridPointInDegrees - * and change their values to expand the bounding box - */ -static int expand_bounding_box(grib_handle* h, grib_values* values, const size_t count) +// Search key=value array for: +// * latitudeOfFirstGridPointInDegrees +// * longitudeOfFirstGridPointInDegrees +// * latitudeOfLastGridPointInDegrees +// * longitudeOfLastGridPointInDegrees +// and change their values to expand the bounding box +static int expand_bounding_box(const grib_handle* h, grib_values* values, const size_t count) { int ret = GRIB_SUCCESS; size_t i = 0; double new_angle = 0; RoundingPolicy roundingPolicy = eROUND_ANGLE_UP; - long angle_subdivisions = 0; /* e.g. 1e3 for grib1 and 1e6 for grib2 */ + long angle_subdivisions = 0; // e.g. 1e3 for grib1 and 1e6 for grib2 if ((ret = grib_get_long(h, "angleSubdivisions", &angle_subdivisions)) != 0) return ret; @@ -625,7 +622,7 @@ static int check_values(const double* data_values, size_t data_values_count) }*/ static int check_geometry(grib_handle* handle, const grib_util_grid_spec* spec, - size_t data_values_count, int specified_as_global) + size_t data_values_count, bool specified_as_global) { int err = 0; @@ -650,7 +647,7 @@ static int check_geometry(grib_handle* handle, const grib_util_grid_spec* spec, #if defined(CHECK_HANDLE_AGAINST_SPEC) /* Check what is coded in the handle is what is requested by the spec. */ /* Return GRIB_SUCCESS if the geometry matches, otherwise the error code */ -static int check_handle_against_spec(grib_handle* handle, const long edition, +static int check_handle_against_spec(const grib_handle* handle, const long edition, const grib_util_grid_spec* spec, int global_grid) { int err = 0; @@ -884,10 +881,10 @@ static int get_grib_sample_name(grib_handle* h, long editionNumber, switch (spec->grid_type) { case GRIB_UTIL_GRID_SPEC_REDUCED_GG: case GRIB_UTIL_GRID_SPEC_REDUCED_ROTATED_GG: - /* Choose a sample with the right Gaussian number and edition */ + // Choose a sample with the right Gaussian number and edition snprintf(sample_name, sample_name_len, "%s_pl_%ld_grib%ld", grid_type, spec->N, editionNumber); if (spec->pl && spec->pl_size) { - /* GRIB-834: pl is given so can use any of the reduced_gg_pl samples */ + // GRIB-834: pl is given so can use any of the reduced_gg_pl samples snprintf(sample_name, sample_name_len, "%s_pl_grib%ld", grid_type, editionNumber); } break; @@ -905,7 +902,7 @@ static int get_grib_sample_name(grib_handle* h, long editionNumber, } if (spec->pl && spec->grid_name) { - /* Cannot have BOTH pl and grid name specified */ + // Cannot have BOTH pl and grid name specified fprintf(stderr, "%s: Cannot set BOTH spec.pl and spec.grid_name!\n", __func__); return GRIB_INTERNAL_ERROR; } @@ -967,25 +964,25 @@ grib_handle* grib_util_set_spec(grib_handle* h, } while (0) grib_values values[1024] = {{0,},}; - grib_context* c = grib_context_get_default(); + const grib_context* c = grib_context_get_default(); grib_handle* h_out = NULL; grib_handle* h_sample = NULL; const char* grid_type = NULL; - char sample_name[1024]; /* name of the GRIB sample file */ + char sample_name[1024]; // name of the GRIB sample file char input_grid_type[100]; char input_packing_type[100]; long editionNumber = 0; size_t count = 0, len = 100, slen = 20, input_grid_type_len = 100; double laplacianOperator; int i = 0, packingTypeIsSet = 0, setSecondOrder = 0, setJpegPacking = 0, setCcsdsPacking = 0; - int convertEditionEarlier = 0; /* For cases when we cannot set some keys without converting */ - int grib1_high_resolution_fix = 0; /* boolean: See GRIB-863 */ - int global_grid = 0; /* boolean */ + bool convertEditionEarlier = false; // For cases when we cannot set some keys without converting + bool grib1_high_resolution_fix = false; // See GRIB-863 + bool global_grid = false; int expandBoundingBox = 0; Assert(h); - /* Get edition number from input handle */ + // Get edition number from input handle if ((*err = grib_get_long(h, "edition", &editionNumber)) != 0) { if (c->write_on_fail) grib_write_message(h, "error.grib", "w"); return NULL; @@ -997,7 +994,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, grib_get_string(h, "packingType", input_packing_type, &len); - /* ECC-1201, ECC-1529, ECC-1530: Make sure input packing type is preserved */ + // ECC-1201, ECC-1529, ECC-1530: Make sure input packing type is preserved if (packing_spec->packing == GRIB_UTIL_PACKING_SAME_AS_INPUT && packing_spec->packing_type == GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT) { @@ -1031,7 +1028,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, } SET_STRING_VALUE("gridType", grid_type); - /* The "pl" is given from the template, but "section_copy" will take care of setting the right headers */ + // The "pl" is given from the template, but "section_copy" will take care of setting the right headers if (get_grib_sample_name(h, editionNumber, spec, grid_type, sample_name) != GRIB_SUCCESS) { goto cleanup; } @@ -1040,7 +1037,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, fprintf(stderr, "ECCODES WARNING %s: '%s' specified " "but input is GRIB edition %ld. Output must be a higher edition!\n", __func__, grid_type, editionNumber); - convertEditionEarlier = 1; + convertEditionEarlier = true; } h_sample = grib_handle_new_from_samples(NULL, sample_name); @@ -1049,7 +1046,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, return NULL; } - /* Set grid */ + // Set grid switch (spec->grid_type) { case GRIB_UTIL_GRID_SPEC_REGULAR_LL: case GRIB_UTIL_GRID_SPEC_ROTATED_LL: @@ -1060,16 +1057,16 @@ grib_handle* grib_util_set_spec(grib_handle* h, SET_LONG_VALUE("ijDirectionIncrementGiven", 1); if (editionNumber == 1) { - /* GRIB-863: GRIB1 cannot represent increments less than a millidegree */ + // GRIB-863: GRIB1 cannot represent increments less than a millidegree if (!angle_can_be_encoded(h, spec->iDirectionIncrementInDegrees) || !angle_can_be_encoded(h, spec->jDirectionIncrementInDegrees)) { - grib1_high_resolution_fix = 1; - /* Set flag to compute the increments */ + grib1_high_resolution_fix = true; + // Set flag to compute the increments SET_LONG_VALUE("ijDirectionIncrementGiven", 0); } } - /* default iScansNegatively=0 jScansPositively=0 is ok */ + // default iScansNegatively=0 jScansPositively=0 is ok COPY_SPEC_LONG(iScansNegatively); COPY_SPEC_LONG(jScansPositively); @@ -1094,7 +1091,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, if (spec->missingValue) COPY_SPEC_DOUBLE(missingValue); SET_LONG_VALUE("ijDirectionIncrementGiven", 1); - /* TODO: add Assert */ + // TODO: add Assert COPY_SPEC_LONG(Ni); COPY_SPEC_DOUBLE(iDirectionIncrementInDegrees); COPY_SPEC_LONG(Nj); @@ -1129,7 +1126,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, COPY_SPEC_LONG(Ni); COPY_SPEC_LONG(Nj); - /* default iScansNegatively=0 jScansPositively=0 is ok */ + // default iScansNegatively=0 jScansPositively=0 is ok COPY_SPEC_LONG(iScansNegatively); COPY_SPEC_LONG(jScansPositively); COPY_SPEC_DOUBLE(orientationOfTheGridInDegrees); @@ -1143,8 +1140,8 @@ grib_handle* grib_util_set_spec(grib_handle* h, COPY_SPEC_DOUBLE(longitudeOfFirstGridPointInDegrees); COPY_SPEC_DOUBLE(latitudeOfFirstGridPointInDegrees); - COPY_SPEC_LONG(Ni); /* same as Nx */ - COPY_SPEC_LONG(Nj); /* same as Ny */ + COPY_SPEC_LONG(Ni); // same as Nx + COPY_SPEC_LONG(Nj); // same as Ny COPY_SPEC_LONG(iScansNegatively); COPY_SPEC_LONG(jScansPositively); @@ -1160,15 +1157,15 @@ grib_handle* grib_util_set_spec(grib_handle* h, case GRIB_UTIL_GRID_SPEC_UNSTRUCTURED: COPY_SPEC_LONG(bitmapPresent); if (spec->missingValue) COPY_SPEC_DOUBLE(missingValue); - /* TODO(masn): Other keys */ + // TODO(masn): Other keys break; case GRIB_UTIL_GRID_SPEC_LAMBERT_CONFORMAL: COPY_SPEC_LONG(bitmapPresent); if (spec->missingValue) COPY_SPEC_DOUBLE(missingValue); COPY_SPEC_DOUBLE(longitudeOfFirstGridPointInDegrees); COPY_SPEC_DOUBLE(latitudeOfFirstGridPointInDegrees); - COPY_SPEC_LONG(Ni); /* same as Nx */ - COPY_SPEC_LONG(Nj); /* same as Ny */ + COPY_SPEC_LONG(Ni); // same as Nx + COPY_SPEC_LONG(Nj); // same as Ny COPY_SPEC_LONG(iScansNegatively); COPY_SPEC_LONG(jScansPositively); @@ -1239,7 +1236,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, break; } - /* Set rotation */ + // Set rotation switch (spec->grid_type) { case GRIB_UTIL_GRID_SPEC_ROTATED_LL: case GRIB_UTIL_GRID_SPEC_ROTATED_GG: @@ -1251,7 +1248,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, break; } - /* process packing options */ + // process packing options if (!packingTypeIsSet && packing_spec->packing == GRIB_UTIL_PACKING_USE_PROVIDED && strcmp(input_packing_type, "grid_simple_matrix")) { @@ -1271,7 +1268,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, case GRIB_UTIL_PACKING_TYPE_GRID_COMPLEX: if (!STR_EQUAL(input_packing_type, "grid_complex")) { SET_STRING_VALUE("packingType", "grid_complex"); - convertEditionEarlier=1; + convertEditionEarlier = true; } break; case GRIB_UTIL_PACKING_TYPE_JPEG: @@ -1310,7 +1307,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, long numberOfDirections, numberOfFrequencies; int keep_matrix = h->context->keep_matrix; if (packing_spec->packing_type == GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE) { - keep_matrix = 0; /* ECC-911 */ + keep_matrix = 0; // ECC-911 } if (keep_matrix) { SET_STRING_VALUE("packingType", "grid_simple_matrix"); @@ -1384,14 +1381,14 @@ grib_handle* grib_util_set_spec(grib_handle* h, packing_spec->extra_settings[i].long_value == 1) { /* GRIB-922: Request is for a global grid. Setting this key will * calculate the lat/lon values. So the spec's lat/lon can be ignored */ - global_grid = 1; + global_grid = true; } } } } - /* grib_write_message(h,"input.grib","w"); */ - /* grib_write_message(h_sample,"geo.grib","w"); */ - /* copy product and local sections from h to h_sample handle and store in h_out */ + // grib_write_message(h,"input.grib","w"); + // grib_write_message(h_sample,"geo.grib","w"); + // copy product and local sections from h to h_sample handle and store in h_out if ((h_out = grib_util_sections_copy(h, h_sample, GRIB_SECTION_PRODUCT | GRIB_SECTION_LOCAL, err)) == NULL) { goto cleanup; } @@ -1399,7 +1396,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, grib_handle_delete(h_sample); Assert(*err == 0); - /* GRIB-857: Set "pl" array if provided (For reduced Gaussian grids) */ + // GRIB-857: Set "pl" array if provided (For reduced Gaussian grids) Assert(spec->pl_size >= 0); if (spec->pl && spec->pl_size == 0) { fprintf(stderr, "%s: pl array not NULL but pl_size == 0!\n", __func__); @@ -1434,7 +1431,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, print_values(h->context, spec, packing_spec, input_packing_type, data_values, data_values_count, values, count); } - /* Apply adjustments to bounding box if needed */ + // Apply adjustments to bounding box if needed if (expandBoundingBox) { if ((*err = expand_bounding_box(h_out, values, count)) != 0) { fprintf(stderr, "%s: Cannot expand bounding box: %s\n", __func__, grib_get_error_message(*err)); @@ -1445,6 +1442,14 @@ grib_handle* grib_util_set_spec(grib_handle* h, } if (convertEditionEarlier && packing_spec->editionNumber > 1) { + // Note: + // If the input is GRIB1 and the requested grid type is HealPix or ORCA etc, + // we deliberately fail unless the user specifies edition conversion. + // i.e., we do not automatically convert edition + // If we later change our mind, we need to change editionNumber to 2 here: + // long new_edition = packing_spec->editionNumber; + // if (new_edition == 0) new_edition = 2; + // *err = grib_set_long(h_out, "edition", packing_spec->editionNumber); if (*err) { fprintf(stderr, "%s: Cannot convert to edition %ld.\n", __func__, packing_spec->editionNumber); @@ -1477,8 +1482,8 @@ grib_handle* grib_util_set_spec(grib_handle* h, } */ if (grib1_high_resolution_fix) { - /* GRIB-863: must set increments to MISSING */ - /* increments are not coded in message but computed */ + // GRIB-863: must set increments to MISSING + // increments are not coded in message but computed if ((*err = grib_set_missing(h_out, "iDirectionIncrement")) != 0) { fprintf(stderr, "%s: Cannot set Di to missing: %s\n", __func__, grib_get_error_message(*err)); goto cleanup; @@ -1489,8 +1494,8 @@ grib_handle* grib_util_set_spec(grib_handle* h, } } - /*grib_dump_content(h_out, stdout,"debug", ~0, NULL);*/ - /* convert to second_order if not constant field. (Also see ECC-326) */ + //grib_dump_content(h_out, stdout,"debug", ~0, NULL); + // convert to second_order if not constant field. (Also see ECC-326) if (setSecondOrder) { int constant = 0; double missingValue = 0; @@ -1505,7 +1510,7 @@ grib_handle* grib_util_set_spec(grib_handle* h, slen = 17; grib_set_string(htmp, "packingType", "grid_second_order", &slen); grib_get_long(htmp, "numberOfGroups", &numberOfGroups); - /* GRIBEX is not able to decode overflown numberOfGroups with SPD */ + // GRIBEX is not able to decode overflown numberOfGroups with SPD if (numberOfGroups > 65534 && h_out->context->no_spd) { slen = 24; grib_set_string(h_out, "packingType", "grid_second_order_no_SPD", &slen); @@ -1546,8 +1551,8 @@ grib_handle* grib_util_set_spec(grib_handle* h, } } - if (editionNumber > 1 || packing_spec->editionNumber > 1) { /* ECC-353 */ - /* Some packing types are not available in GRIB1 and have to be done AFTER we set data values */ + if (editionNumber > 1 || packing_spec->editionNumber > 1) { // ECC-353 + // Some packing types are not available in GRIB1 and have to be done AFTER we set data values if (setJpegPacking == 1) { *err = grib_set_string(h_out, "packingType", "grid_jpeg", &slen); if (*err != GRIB_SUCCESS) { @@ -1570,9 +1575,9 @@ grib_handle* grib_util_set_spec(grib_handle* h, grib_set_long(h_out, "deleteLocalDefinition", 1); } - /* ECC-445 */ + // ECC-445 if (expandBoundingBox) { - Assert(!global_grid); /* ECC-576: "global" should not be set */ + Assert(!global_grid); // ECC-576: "global" should not be set } if ((*err = check_geometry(h_out, spec, data_values_count, global_grid)) != GRIB_SUCCESS) { @@ -1632,9 +1637,7 @@ cleanup: // } // } // grib_iterator_delete(iter); - // ret = grib_get_double(h, "missingValue", &missingValue); - // centroidX = 0; // centroidY = 0; // mass = 0; @@ -1650,10 +1653,8 @@ cleanup: // centroidX /= mass; // centroidY /= mass; // mass /= *count; - // for (j = 0; j < order * order; j++) // moments[j] = 0; - // for (i = 0; i < numberOfPoints; i++) { // if (values[i] != missingValue) { // dx = (lon[i] - centroidX); @@ -1693,7 +1694,7 @@ static void set_value(grib_values* value, char* str, int equal) { char *p = 0, *q = 0, *s = 0; char buf[1000] = {0,}; - grib_context* c = grib_context_get_default(); + const grib_context* c = grib_context_get_default(); value->equal = equal; q = str; @@ -1814,7 +1815,7 @@ int parse_keyval_string(const char* grib_tool, int equal = 1; char* value = NULL; if (values_required) { - /* Can be either k=v or k!=v */ + // Can be either k=v or k!=v p = (char*)values[i].name; while (*p != '=' && *p != '!' && *p != '\0') p++; @@ -2046,7 +2047,7 @@ size_t sum_of_pl_array(const long* pl, size_t plsize) return count; } -int grib_is_earth_oblate(grib_handle* h) +int grib_is_earth_oblate(const grib_handle* h) { long oblate = 0; int err = grib_get_long(h, "earthIsOblate", &oblate); @@ -2058,8 +2059,8 @@ int grib_is_earth_oblate(grib_handle* h) int grib_check_data_values_minmax(grib_handle* h, const double min_val, const double max_val) { - int result = GRIB_SUCCESS; - grib_context* ctx = h->context; + int result = GRIB_SUCCESS; + const grib_context* ctx = h->context; if (!(min_val < DBL_MAX && min_val > -DBL_MAX)) { grib_context_log(ctx, GRIB_LOG_ERROR, "Minimum value out of range: %g", min_val); @@ -2079,10 +2080,10 @@ int grib_check_data_values_minmax(grib_handle* h, const double min_val, const do } // Return true(1) if large constant fields are to be created, otherwise false(0) -int grib_producing_large_constant_fields(grib_handle* h, int edition) +int grib_producing_large_constant_fields(const grib_handle* h, int edition) { // First check if the transient key is set - grib_context* c = h->context; + const grib_context* c = h->context; long produceLargeConstantFields = 0; if (grib_get_long(h, "produceLargeConstantFields", &produceLargeConstantFields) == GRIB_SUCCESS && produceLargeConstantFields != 0) { @@ -2097,13 +2098,12 @@ int grib_producing_large_constant_fields(grib_handle* h, int edition) return c->large_constant_fields; } - int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max_val) { - int err = 0; + int err = 0; double min_field_value_allowed = 0, max_field_value_allowed = 0; long paramId = 0; - grib_context* ctx = h->context; + const grib_context* ctx = h->context; bool is_error = true; char description[1024] = {0,}; char step[32] = "unknown"; From cf47f8d18649eebcd3158ccc4d581f9d93dfb049 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 13:37:15 +0000 Subject: [PATCH 103/156] Use bool rather than int --- src/grib_util.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/grib_util.cc b/src/grib_util.cc index 7ecc75f72..670dbd8aa 100644 --- a/src/grib_util.cc +++ b/src/grib_util.cc @@ -643,7 +643,6 @@ static int check_geometry(grib_handle* handle, const grib_util_grid_spec* spec, return err; } - #if defined(CHECK_HANDLE_AGAINST_SPEC) /* Check what is coded in the handle is what is requested by the spec. */ /* Return GRIB_SUCCESS if the geometry matches, otherwise the error code */ @@ -830,10 +829,10 @@ static const char* get_grid_type_name(const int spec_grid_type) return NULL; } -static int is_constant_field(const double missingValue, const double* data_values, size_t data_values_count) +static bool is_constant_field(const double missingValue, const double* data_values, size_t data_values_count) { size_t ii = 0; - int constant = 1; + bool constant = true; double value = missingValue; for (ii = 0; ii < data_values_count; ii++) { @@ -843,7 +842,7 @@ static int is_constant_field(const double missingValue, const double* data_value } else { if (value != data_values[ii]) { - constant = 0; + constant = false; break; } } @@ -1497,10 +1496,9 @@ grib_handle* grib_util_set_spec(grib_handle* h, //grib_dump_content(h_out, stdout,"debug", ~0, NULL); // convert to second_order if not constant field. (Also see ECC-326) if (setSecondOrder) { - int constant = 0; double missingValue = 0; grib_get_double(h_out, "missingValue", &missingValue); - constant = is_constant_field(missingValue, data_values, data_values_count); + bool constant = is_constant_field(missingValue, data_values, data_values_count); if (!constant) { if (editionNumber == 1) { From 457fad43488571d319b0cdb7ba51b50b65dd83a7 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 15:15:44 +0000 Subject: [PATCH 104/156] Time validation: Fix comment --- src/codes_util.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codes_util.cc b/src/codes_util.cc index 2d91fa598..57613109a 100644 --- a/src/codes_util.cc +++ b/src/codes_util.cc @@ -230,7 +230,7 @@ int is_time_valid(long number) long hours = number / 100; // Get the first two digits as hours long minutes = number % 100; // Get the last two digits as minutes - // Check if hours are within the valid range (00-23) + // Check if hours are within the valid range (00-24) if (hours < 0 || hours > 24) { return 0; } From ec5223618c18fe58a5e2a1c1da2f566f16c97896 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 16:52:47 +0000 Subject: [PATCH 105/156] ECC-1767: Make new keys read-only --- definitions/grib2/template.4.optical.def | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/definitions/grib2/template.4.optical.def b/definitions/grib2/template.4.optical.def index 385513edc..71dcf77e0 100644 --- a/definitions/grib2/template.4.optical.def +++ b/definitions/grib2/template.4.optical.def @@ -15,5 +15,5 @@ alias firstWavelengthInMetres = firstWavelength; alias secondWavelengthInMetres = secondWavelength; constant billion = 1000000000 : hidden; -meta firstWavelengthInNanometres multdouble(firstWavelength, billion); -meta secondWavelengthInNanometres multdouble(secondWavelength, billion); +meta firstWavelengthInNanometres multdouble(firstWavelength, billion) : read_only; +meta secondWavelengthInNanometres multdouble(secondWavelength, billion) : read_only; From 81e84a282d50368cac083d9ee8e4fd7575e5c17e Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 17:17:37 +0000 Subject: [PATCH 106/156] ECC-1778: Crash: Decoding invalid BUFR file --- src/grib_io.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/grib_io.cc b/src/grib_io.cc index 64c197a29..c47e4d509 100644 --- a/src/grib_io.cc +++ b/src/grib_io.cc @@ -820,6 +820,9 @@ static int read_BUFR(reader* r, int no_alloc) GROW_BUF_IF_REQUIRED(sec1len + sec2len + sec3len + 4 + 3); /* Read section 3 */ + if (sec3len < 5) { + return GRIB_INVALID_MESSAGE; // ECC-1778 + } if ((r->read(r->read_data, tmp + i, sec3len - 3, &err) != sec3len - 3) || err) return err; i += sec3len - 3; From 9709382d8f2101fef0b8b83b6e3528d01282244c Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 17:25:31 +0000 Subject: [PATCH 107/156] ECC-1779: GRIB2: Add keys to identify experimental and deprecated templates --- definitions/grib2/boot.def | 7 +++++++ definitions/grib2/template.3.1000.def | 5 +++++ definitions/grib2/template.3.1100.def | 5 +++++ definitions/grib2/template.3.1200.def | 4 ++++ definitions/grib2/template.4.10.def | 3 +++ definitions/grib2/template.4.1000.def | 3 +++ definitions/grib2/template.4.1001.def | 3 +++ definitions/grib2/template.4.1100.def | 4 +++- definitions/grib2/template.4.1101.def | 1 + definitions/grib2/template.4.44.def | 1 + definitions/grib2/template.4.83.def | 4 +++- definitions/grib2/template.5.1.def | 3 ++- definitions/grib2/template.5.61.def | 3 ++- definitions/grib2/template.7.1.def | 4 +++- definitions/grib2/template.7.61.def | 1 + 15 files changed, 46 insertions(+), 5 deletions(-) diff --git a/definitions/grib2/boot.def b/definitions/grib2/boot.def index 4ed94b503..5c3be280c 100644 --- a/definitions/grib2/boot.def +++ b/definitions/grib2/boot.def @@ -43,3 +43,10 @@ template core "grib2/sections.def"; #} template section_8 "grib2/section.8.def"; + +concept isTemplateDeprecated(false) { + 1 = { template_is_deprecated = 1; } +} +concept isTemplateExperimental(false) { + 1 = { template_is_experimental = 1; } +} diff --git a/definitions/grib2/template.3.1000.def b/definitions/grib2/template.3.1000.def index e76507aaf..8f825f393 100644 --- a/definitions/grib2/template.3.1000.def +++ b/definitions/grib2/template.3.1000.def @@ -1,6 +1,11 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 3.1000, Cross-section grid, with points equally spaced on the horizontal + +# This template is simply experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden ; + include "grib2/template.3.shape_of_the_earth.def" constant isGridded = true; diff --git a/definitions/grib2/template.3.1100.def b/definitions/grib2/template.3.1100.def index 26fe4a92a..de65bca94 100644 --- a/definitions/grib2/template.3.1100.def +++ b/definitions/grib2/template.3.1100.def @@ -1,6 +1,11 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 3.1100, Hovmoller diagram grid with points equally spaced on the horizontal + +# This template is simply experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; + include "grib2/template.3.shape_of_the_earth.def" constant isGridded = true; diff --git a/definitions/grib2/template.3.1200.def b/definitions/grib2/template.3.1200.def index 0b7e234ae..06bb38c96 100644 --- a/definitions/grib2/template.3.1200.def +++ b/definitions/grib2/template.3.1200.def @@ -1,6 +1,10 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 3.1200, Time section grid +# This template is simply experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; + constant isGridded = true; # NT - Number of time steps diff --git a/definitions/grib2/template.4.10.def b/definitions/grib2/template.4.10.def index 1bcd610b0..84b437bdc 100644 --- a/definitions/grib2/template.4.10.def +++ b/definitions/grib2/template.4.10.def @@ -2,6 +2,9 @@ # TEMPLATE 4.10, Percentile forecasts at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval +# This template was not validated at the time of publication and should be used with caution. +transient template_is_experimental = 1 : hidden; + include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" include "grib2/template.4.forecast_time.def" diff --git a/definitions/grib2/template.4.1000.def b/definitions/grib2/template.4.1000.def index a31654ff5..f179ae483 100644 --- a/definitions/grib2/template.4.1000.def +++ b/definitions/grib2/template.4.1000.def @@ -1,6 +1,9 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.1000, Cross section of analysis and forecast at a point in time +# This template is experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" diff --git a/definitions/grib2/template.4.1001.def b/definitions/grib2/template.4.1001.def index b0e1ca17e..5fafe70f3 100644 --- a/definitions/grib2/template.4.1001.def +++ b/definitions/grib2/template.4.1001.def @@ -1,6 +1,9 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.1001, Cross section of averaged or otherwise statistically processed analysis or forecast over a range of time +# This template is experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" diff --git a/definitions/grib2/template.4.1100.def b/definitions/grib2/template.4.1100.def index 87016a586..ac65bc69f 100644 --- a/definitions/grib2/template.4.1100.def +++ b/definitions/grib2/template.4.1100.def @@ -1,7 +1,9 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.1100, Hovmoller-type grid with no averaging or other statistical processing -# This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests +# This template is experimental, was not validated at the time of publication +# and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" diff --git a/definitions/grib2/template.4.1101.def b/definitions/grib2/template.4.1101.def index 6f27693f2..83e46a389 100644 --- a/definitions/grib2/template.4.1101.def +++ b/definitions/grib2/template.4.1101.def @@ -4,6 +4,7 @@ # This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests. # (Octets 35-50 are very similar to octets 43-58 of product definition template 4.8, but the meaning of some fields differs slightly) +transient template_is_experimental = 1 : hidden; include "grib2/template.4.parameter.def" include "grib2/template.4.generating_process.def" diff --git a/definitions/grib2/template.4.44.def b/definitions/grib2/template.4.44.def index fa1bf2d74..1fbadeec8 100644 --- a/definitions/grib2/template.4.44.def +++ b/definitions/grib2/template.4.44.def @@ -2,6 +2,7 @@ # TEMPLATE 4.44, Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for aerosol # It is recommended not to use this template. PDT 4.48 should be used instead with optical wave length range set to missing +transient template_is_deprecated = 1 : hidden; # GRIB-530: Special case for aerosol thanks to WMO error diff --git a/definitions/grib2/template.4.83.def b/definitions/grib2/template.4.83.def index a92e3cfd4..395931e68 100644 --- a/definitions/grib2/template.4.83.def +++ b/definitions/grib2/template.4.83.def @@ -1,7 +1,9 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.83, Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval with source/sink -# Note: This template is deprecated. Template 4.84 should be used instead. + +# It is recommended not to use this template. Product definition template 4.84 should be used instead because it contains an additional octet to specify the type of generating process +transient template_is_deprecated = 1 : hidden; include "grib2/template.4.parameter.def" include "grib2/template.4.aerosol.def" diff --git a/definitions/grib2/template.5.1.def b/definitions/grib2/template.5.1.def index 8f1c22bea..14864c9f5 100644 --- a/definitions/grib2/template.5.1.def +++ b/definitions/grib2/template.5.1.def @@ -1,8 +1,9 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 5.1, Matrix values at grid point - simple packing -# Preliminary note: + # This template was not validated at the time of publication and should be used with caution +transient template_is_experimental = 1 : hidden; include "grib2/template.5.packing.def" diff --git a/definitions/grib2/template.5.61.def b/definitions/grib2/template.5.61.def index 9c8e73a9e..f19db39ee 100644 --- a/definitions/grib2/template.5.61.def +++ b/definitions/grib2/template.5.61.def @@ -2,8 +2,9 @@ # TEMPLATE 5.61, Grid point data - Simple packing with logarithmic preprocessing -# Note from WMO document: # This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests +transient template_is_experimental = 1 : hidden; + constant typeOfPreProcessing = 1; include "grib2/template.5.packing.def" diff --git a/definitions/grib2/template.7.1.def b/definitions/grib2/template.7.1.def index 7d49264b1..1426d4fe7 100644 --- a/definitions/grib2/template.7.1.def +++ b/definitions/grib2/template.7.1.def @@ -1,6 +1,8 @@ # (C) Copyright 2005- ECMWF. -# TEMPLATE 7.1, Matrix values at grid point -simple packing +# TEMPLATE 7.1, Matrix values at grid point - simple packing +# This template was not validated at the time of publication and should be used with caution +transient template_is_experimental = 1 : hidden; meta codedValues data_g2simple_packing( section7Length, diff --git a/definitions/grib2/template.7.61.def b/definitions/grib2/template.7.61.def index 328afbcaa..6f7f3fdd6 100644 --- a/definitions/grib2/template.7.61.def +++ b/definitions/grib2/template.7.61.def @@ -4,6 +4,7 @@ # Note from WMO document: # This template is experimental, was not validated at the time of publication and should be used only for bilateral previously agreed tests +transient template_is_deprecated = 1 : hidden; meta codedValues data_g2simple_packing_with_preprocessing( section7Length, From c6ef32e28cb017e1b78efde757bb0afc9d6201ec Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 17:33:28 +0000 Subject: [PATCH 108/156] ECC-1779: Test --- tests/grib2_templates.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/grib2_templates.sh b/tests/grib2_templates.sh index 437eb36b1..024dd26dd 100755 --- a/tests/grib2_templates.sh +++ b/tests/grib2_templates.sh @@ -180,6 +180,21 @@ test_PDTN_conversions 57 67 test_PDTN_conversions 58 68 test_PDTN_conversions 71 73 +# ECC-1779: Deprecated and experimental templates +# ------------------------------------------------ +grib_check_key_equals $sample2 isTemplateDeprecated,isTemplateExperimental '0 0' + +$tools_dir/grib_set -s productDefinitionTemplateNumber=44 $sample2 $temp +grib_check_key_equals $temp isTemplateDeprecated,isTemplateExperimental '1 0' + +$tools_dir/grib_set -s productDefinitionTemplateNumber=10 $sample2 $temp +grib_check_key_equals $temp isTemplateDeprecated,isTemplateExperimental '0 1' + +$tools_dir/grib_set -s gridType=cross_section $sample2 $temp +grib_check_key_equals $temp isTemplateDeprecated,isTemplateExperimental '0 1' +$tools_dir/grib_set -s gridType=time_section $sample2 $temp +grib_check_key_equals $temp isTemplateDeprecated,isTemplateExperimental '0 1' + # Clean up rm -f $temp $temp1 $temp2 $tempFilt $tempText From 16c99d7f36f3abcacbe7ab25b426eec864a653c3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 29 Feb 2024 21:38:15 +0000 Subject: [PATCH 109/156] Testing: dump on repeated keys --- tests/grib_dump.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/grib_dump.sh b/tests/grib_dump.sh index c2844ec0d..c413f93f1 100755 --- a/tests/grib_dump.sh +++ b/tests/grib_dump.sh @@ -111,6 +111,16 @@ file=$data_dir/sample.grib2 ECCODES_DEBUG=1 ${tools_dir}/grib_dump $file > $temp 2>&1 +# Repeated key numberOfSection +file=$data_dir/sample.grib2 +${tools_dir}/grib_dump -O $file > $temp +grep -q "numberOfSection = 1" $temp +grep -q "numberOfSection = 3" $temp +grep -q "numberOfSection = 4" $temp +grep -q "numberOfSection = 5" $temp +grep -q "numberOfSection = 7" $temp + + # Dump long array # ---------------- input=$data_dir/lfpw.grib1 From 41ed4d12c83ae047af74c19b5e6acb462b1d592b Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 12:10:27 +0000 Subject: [PATCH 110/156] Tools: Dead code removal --- tools/bufr_compare.cc | 25 ++++++------------------- tools/grib_compare.cc | 15 ++------------- tools/gts_compare.cc | 10 +++------- tools/metar_compare.cc | 18 +++--------------- 4 files changed, 14 insertions(+), 54 deletions(-) diff --git a/tools/bufr_compare.cc b/tools/bufr_compare.cc index c6714fedb..3fa715669 100644 --- a/tools/bufr_compare.cc +++ b/tools/bufr_compare.cc @@ -236,7 +236,7 @@ int grib_tool_before_getopt(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options) { - int ret = 0, i; + int ret = 0; grib_context* context = grib_context_get_default(); options->strict = 1; @@ -315,16 +315,6 @@ int grib_tool_init(grib_runtime_options* options) compare_double = &compare_double_absolute; if (grib_options_on("R:")) { global_tolerance = 0; - for (i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -342,9 +332,9 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("t:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; - ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); + ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (ret == GRIB_INVALID_ARGUMENT) { usage(); exit(1); @@ -771,11 +761,10 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g return GRIB_COUNT_MISMATCH; } */ - if (options->mode != MODE_BUFR) { + Assert(options->mode == MODE_BUFR); /* TODO: Ignore missing values for keys in BUFR. Not yet implemented */ //isMissing1 = ((grib_is_missing(handle1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; //isMissing2 = ((grib_is_missing(handle2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - } if ((isMissing1 == 1) && (isMissing2 == 1)) { // if (verbose) printf(" is set to missing in both fields\n"); @@ -1081,16 +1070,14 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_BUFR) - return 0; + return 0; // Not in BUFR break; case GRIB_TYPE_LABEL: break; default: - if (verbose) - printf("\n"); + if (verbose) printf("\n"); printInfo(handle1); save_error(c, name); printf("Cannot compare [%s], unsupported type %d\n", name, type1); diff --git a/tools/grib_compare.cc b/tools/grib_compare.cc index e70119d6d..f9f4d0977 100644 --- a/tools/grib_compare.cc +++ b/tools/grib_compare.cc @@ -330,18 +330,7 @@ int grib_tool_init(grib_runtime_options* options) global_tolerance = 0; compare_double = &compare_double_absolute; if (grib_options_on("R:")) { - int i; global_tolerance = 0; - for (i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -374,9 +363,9 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("T:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; - ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); + ret = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (ret == GRIB_INVALID_ARGUMENT) { usage(); exit(1); diff --git a/tools/gts_compare.cc b/tools/gts_compare.cc index cedbfa4b6..9133b3435 100644 --- a/tools/gts_compare.cc +++ b/tools/gts_compare.cc @@ -439,12 +439,10 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, save_error(c, name); return err; } - - //if (options->mode != MODE_GTS) { + Assert(options->mode == MODE_GTS); /* TODO: Ignore missing values for keys in GTS. Not yet implemented */ //isMissing1 = ((grib_is_missing(h1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; //isMissing2 = ((grib_is_missing(h2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - //} if ((isMissing1 == 1) && (isMissing2 == 1)) { if (verbose) @@ -573,10 +571,8 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_GTS) { - // We do not want to compare the message itself - return 0; - } + // We do not want to compare the message itself + return 0; break; case GRIB_TYPE_LABEL: diff --git a/tools/metar_compare.cc b/tools/metar_compare.cc index 973794988..e4318bd44 100644 --- a/tools/metar_compare.cc +++ b/tools/metar_compare.cc @@ -249,16 +249,6 @@ int grib_tool_init(grib_runtime_options* options) compare_double = &compare_double_absolute; if (grib_options_on("R:")) { global_tolerance = 0; - for (int i = 0; i < options->tolerance_count; i++) { - if (!strcmp((options->tolerance[i]).name, "all")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - if (!strcmp((options->tolerance[i]).name, "global")) { - global_tolerance = (options->tolerance[i]).double_value; - break; - } - } compare_double = &compare_double_relative; compareAbsolute = 0; } @@ -276,7 +266,7 @@ int grib_tool_init(grib_runtime_options* options) tolerance_factor = atof(grib_options_get_option("t:")); if (grib_options_on("R:")) { - char* sarg = grib_options_get_option("R:"); + char* sarg = grib_options_get_option("R:"); options->tolerance_count = MAX_KEYS; int err = parse_keyval_string(tool_name, sarg, 1, GRIB_TYPE_DOUBLE, options->tolerance, &(options->tolerance_count)); if (err == GRIB_INVALID_ARGUMENT) { @@ -514,11 +504,10 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, return err; } - // if (options->mode != MODE_METAR) { + Assert(options->mode == MODE_METAR); // // TODO: Ignore missing values for keys in METAR. Not yet implemented // isMissing1 = ((grib_is_missing(h1, name, &err1) == 1) && (err1 == 0)) ? 1 : 0; // isMissing2 = ((grib_is_missing(h2, name, &err2) == 1) && (err2 == 0)) ? 1 : 0; - // } if ((isMissing1 == 1) && (isMissing2 == 1)) { if (verbose) @@ -746,8 +735,7 @@ static int compare_values(const grib_runtime_options* options, grib_handle* h1, break; case GRIB_TYPE_BYTES: - if (options->mode == MODE_METAR) - return 0; + return 0; // No such type for METAR break; case GRIB_TYPE_LABEL: From 6941c672b9cba2c2abca37efefdd744a35c613b0 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 12:10:51 +0000 Subject: [PATCH 111/156] ECC-1779: Comment --- definitions/grib2/boot.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/definitions/grib2/boot.def b/definitions/grib2/boot.def index 5c3be280c..d2c44fb74 100644 --- a/definitions/grib2/boot.def +++ b/definitions/grib2/boot.def @@ -44,6 +44,9 @@ template core "grib2/sections.def"; template section_8 "grib2/section.8.def"; +# ECC-1779: Add keys to identify experimental and deprecated templates +# The low-level transient keys template_is_XXX +# are set inside the template definition files concept isTemplateDeprecated(false) { 1 = { template_is_deprecated = 1; } } From 40357e1dbe9ad02687194ec602a605b3ec7fc49e Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 14:07:30 +0000 Subject: [PATCH 112/156] Testing: Split grib_filter tests --- tests/CMakeLists.txt | 1 + tests/grib_filter.sh | 81 ---------------------------- tests/grib_filter_fail.sh | 111 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 81 deletions(-) create mode 100755 tests/grib_filter_fail.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 092d9ea83..55bf2adee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -301,6 +301,7 @@ if( HAVE_BUILD_TOOLS ) grib_ls grib_ls_json grib_filter + grib_filter_fail grib_multi grib_nearest_test pseudo_budg diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index c4e6a4021..250302890 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -36,24 +36,6 @@ rm -f ${data_dir}/split/* rmdir ${data_dir}/split rm -f ${data_dir}/f.rules -echo "Test with nonexistent keys. Note spelling of centre!" -# --------------------------------------------------------- -cat >${data_dir}/nonexkey.rules < $REDIRECT > $REDIRECT -if [ $? -eq 0 ]; then - echo "grib_filter should have failed if key not found" >&2 - exit 1 -fi -set -e -# Now repeat with -f option (do not exit on error) -${tools_dir}/grib_filter -f ${data_dir}/nonexkey.rules ${data_dir}/tigge_pf_ecmwf.grib2 2> $REDIRECT > $REDIRECT - -rm -f ${data_dir}/nonexkey.rules - echo "Test GRIB-308: format specifier for integer keys" # ---------------------------------------------------- cat > ${data_dir}/formatint.rules < $tempOut grep -q "defined and equal to -42" $tempOut -echo "Test IEEE float overflow" -# ----------------------------------------- -input="${samp_dir}/GRIB2.tmpl" -cat >$tempFilt < $tempOut -status=$? -set -e -[ $status -ne 0 ] -grep -q "ECCODES ERROR.*Number is too large" $tempOut - - echo "Padded count for filenames" # ----------------------------------------- input=${data_dir}/tigge_af_ecmwf.grib2 @@ -378,16 +345,6 @@ EOF ${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut -cat >$tempFilt < $tempOut -status=$? -set -e -[ $status -ne 0 ] -grep "Assertion failure" $tempOut - # Use of the "length" expression cat >$tempFilt < $tempOut 2>&1 -status=$? -set -e -[ $status -ne 0 ] -grep -q "Invalid argument" $tempOut - # GTS header # --------------- @@ -463,27 +413,6 @@ set -e [ $status -ne 0 ] -# Bad write -set +e -echo 'write "/";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1 -status=$? -set -e -[ $status -ne 0 ] -grep -q "Unable to open file" $tempOut - -# Signed bits -# ----------- -cat >$tempFilt < $tempOut 2>&1 -status=$? -set -e -[ $status -ne 0 ] - - # Setting step # ------------- input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl @@ -505,16 +434,6 @@ EOF ${tools_dir}/grib_filter $tempFilt $input -# Bad filter -# ---------------- -set +e -${tools_dir}/grib_filter a_non_existent_filter_file $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut 2>&1 -status=$? -set -e -[ $status -ne 0 ] -grep -q "Cannot include file" $tempOut - - # Clean up rm -f $tempGrib $tempFilt $tempOut $tempRef rm -f ${data_dir}/formatint.rules ${data_dir}/binop.rules diff --git a/tests/grib_filter_fail.sh b/tests/grib_filter_fail.sh new file mode 100755 index 000000000..cf66e7b6c --- /dev/null +++ b/tests/grib_filter_fail.sh @@ -0,0 +1,111 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +REDIRECT=/dev/null + +label="grib_filter_fail_test" +tempFilt="temp.$label.filt" +tempGrib="temp.$label.grib" +tempOut="temp.$label.txt" +tempRef="temp.$label.ref" + +echo "Test with nonexistent keys. Note spelling of centre!" +# --------------------------------------------------------- +cat >${data_dir}/nonexkey.rules < $REDIRECT > $REDIRECT +if [ $? -eq 0 ]; then + echo "grib_filter should have failed if key not found" >&2 + exit 1 +fi +set -e + +# Now repeat with -f option (do not exit on error) +${tools_dir}/grib_filter -f ${data_dir}/nonexkey.rules ${data_dir}/tigge_pf_ecmwf.grib2 2> $REDIRECT > $REDIRECT + +rm -f ${data_dir}/nonexkey.rules + +echo "Test IEEE float overflow" +# ----------------------------------------- +input="${samp_dir}/GRIB2.tmpl" +cat >$tempFilt < $tempOut +status=$? +set -e +[ $status -ne 0 ] +grep -q "ECCODES ERROR.*Number is too large" $tempOut + +# Assert statement +# ----------------- +cat >$tempFilt < $tempOut +status=$? +set -e +[ $status -ne 0 ] +grep "Assertion failure" $tempOut + + +# Bad write +# --------- +input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +set +e +echo 'write(-10);' | ${tools_dir}/grib_filter -o $tempGrib - $input > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Invalid argument" $tempOut + +# Bad write +# ---------- +set +e +echo 'write "/";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Unable to open file" $tempOut + +# Signed bits +# ----------- +cat >$tempFilt < $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] + + +# Non existent filter +# -------------------- +set +e +${tools_dir}/grib_filter a_non_existent_filter_file $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Cannot include file" $tempOut + + +# Clean up +rm -f $tempGrib $tempFilt $tempOut $tempRef From 3b2ed365d92d7948f4c801cdf37e6db94fab1b05 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 14:57:25 +0000 Subject: [PATCH 113/156] ECC-1780: GRIB HEALPix: In the 'geography' namespace replace 'pointsOrdering' with 'orderingConvention' --- definitions/grib2/template.3.healpix.def | 2 +- tests/CMakeLists.txt | 1 + tests/grib_grid_healpix.sh | 3 ++- tests/grib_units_bias_factor.sh | 34 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100755 tests/grib_units_bias_factor.sh diff --git a/definitions/grib2/template.3.healpix.def b/definitions/grib2/template.3.healpix.def index bd59c3246..bf0429a5b 100644 --- a/definitions/grib2/template.3.healpix.def +++ b/definitions/grib2/template.3.healpix.def @@ -27,7 +27,7 @@ concept orderingConvention(unknown) { "ring" = { ordering = 0; } "nested" = { ordering = 1; } } : dump; -alias geography.pointsOrdering = orderingConvention; +alias geography.orderingConvention = orderingConvention; flags[1] scanningMode 'grib2/tables/[tablesVersion]/3.13.table'; flagbit iScansNegatively(scanningMode,7) : dump; # WMO bit 1 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 55bf2adee..2a211f511 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -169,6 +169,7 @@ if( HAVE_BUILD_TOOLS ) # and/or take much longer list(APPEND tests_extra grib_data_quality_checks + grib_units_bias_factor grib_set_large_message_fail grib_g1monthlydate grib_g1fcperiod diff --git a/tests/grib_grid_healpix.sh b/tests/grib_grid_healpix.sh index 9b3560693..59652e57b 100755 --- a/tests/grib_grid_healpix.sh +++ b/tests/grib_grid_healpix.sh @@ -42,7 +42,8 @@ if [ $latest -gt 31 ]; then fi ${tools_dir}/grib_dump -O -p section_3 $tempGrib -${tools_dir}/grib_ls -jn geography $tempGrib +${tools_dir}/grib_ls -jn geography $tempGrib > $tempLog +grep -q "orderingConvention.*ring" $tempLog # Geoiterator # ------------- diff --git a/tests/grib_units_bias_factor.sh b/tests/grib_units_bias_factor.sh new file mode 100755 index 000000000..e10662d7a --- /dev/null +++ b/tests/grib_units_bias_factor.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="grib_units_bias_factor_test" +outfile=temp.$label.grib + +infile=${data_dir}/sample.grib2 +max=`${tools_dir}/grib_get -F%.3f -p max $infile` +[ "$max" = "311.099" ] + +${tools_dir}/grib_set -rs unitsFactor=1.1,unitsBias=4 $infile $outfile +max=`${tools_dir}/grib_get -F%.3f -p max $outfile` +[ "$max" = "346.209" ] + +${tools_dir}/grib_set -rs unitsFactor=2 $infile $outfile +max=`${tools_dir}/grib_get -F%.3f -p max $outfile` +[ "$max" = "622.197" ] + +${tools_dir}/grib_set -rs unitsBias=4 $infile $outfile +max=`${tools_dir}/grib_get -F%.3f -p max $outfile` +[ "$max" = "315.099" ] + + +# Clean up +rm -f $outfile From d0caf0e4cf97fb2bad8e5c946fd4b74e6dca5da0 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 15:24:56 +0000 Subject: [PATCH 114/156] Refactoring --- ...ib_accessor_class_data_g1simple_packing.cc | 18 ++++++---- ...ib_accessor_class_data_g2simple_packing.cc | 17 ++++++---- ...ib_accessor_class_data_jpeg2000_packing.cc | 19 +++++++---- ...grib_accessor_class_data_simple_packing.cc | 17 ++++++---- tests/grib_units_bias_factor.sh | 33 ++++++++++++------- 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/grib_accessor_class_data_g1simple_packing.cc b/src/grib_accessor_class_data_g1simple_packing.cc index e9f4aefdc..82c72c64c 100644 --- a/src/grib_accessor_class_data_g1simple_packing.cc +++ b/src/grib_accessor_class_data_g1simple_packing.cc @@ -194,16 +194,22 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) } if (units_factor != 1.0) { - if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] = val[i] * units_factor + units_bias; - else - for (i = 0; i < n_vals; i++) + } + } + else { + for (i = 0; i < n_vals; i++) { val[i] *= units_factor; + } + } } - else if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + else if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] += units_bias; + } + } if (c->ieee_packing && self->ieee_packing) { long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */ diff --git a/src/grib_accessor_class_data_g2simple_packing.cc b/src/grib_accessor_class_data_g2simple_packing.cc index 69e1bdbc9..56441fc96 100644 --- a/src/grib_accessor_class_data_g2simple_packing.cc +++ b/src/grib_accessor_class_data_g2simple_packing.cc @@ -177,16 +177,21 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) } if (units_factor != 1.0) { - if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] = val[i] * units_factor + units_bias; - else - for (i = 0; i < n_vals; i++) + } + } else { + for (i = 0; i < n_vals; i++) { val[i] *= units_factor; + } + } } - else if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + else if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] += units_bias; + } + } /* IEEE packing */ if (c->ieee_packing) { diff --git a/src/grib_accessor_class_data_jpeg2000_packing.cc b/src/grib_accessor_class_data_jpeg2000_packing.cc index 66d6f6767..b00160214 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/grib_accessor_class_data_jpeg2000_packing.cc @@ -225,7 +225,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; int err = GRIB_SUCCESS; - int i; + size_t i = 0; size_t buflen = grib_byte_count(a); double bscale = 0; @@ -304,16 +304,21 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) val[i] = (val[i] * bscale + reference_value) * dscale; } if (units_factor != 1.0) { - if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] = val[i] * units_factor + units_bias; - else - for (i = 0; i < n_vals; i++) + } + } else { + for (i = 0; i < n_vals; i++) { val[i] *= units_factor; + } + } } - else if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + else if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] += units_bias; + } + } return err; } diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/grib_accessor_class_data_simple_packing.cc index 0d44acd7f..e78bda53c 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/grib_accessor_class_data_simple_packing.cc @@ -406,16 +406,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = (long)n_vals; if (units_factor != 1.0) { - if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] = val[i] * units_factor + units_bias; - else - for (i = 0; i < n_vals; i++) + } + } else { + for (i = 0; i < n_vals; i++) { val[i] *= units_factor; + } + } } - else if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + else if (units_bias != 0.0) { + for (i = 0; i < n_vals; i++) { val[i] += units_bias; + } + } return err; } diff --git a/tests/grib_units_bias_factor.sh b/tests/grib_units_bias_factor.sh index e10662d7a..4dbc9db81 100755 --- a/tests/grib_units_bias_factor.sh +++ b/tests/grib_units_bias_factor.sh @@ -13,22 +13,31 @@ label="grib_units_bias_factor_test" outfile=temp.$label.grib -infile=${data_dir}/sample.grib2 -max=`${tools_dir}/grib_get -F%.3f -p max $infile` -[ "$max" = "311.099" ] +infiles="${data_dir}/sample.grib2 ${data_dir}/regular_latlon_surface.grib1" +for infile in $infiles; do + #infile=${data_dir}/sample.grib2 + max=`${tools_dir}/grib_get -F%.3f -p max $infile` + [ "$max" = "311.099" ] -${tools_dir}/grib_set -rs unitsFactor=1.1,unitsBias=4 $infile $outfile -max=`${tools_dir}/grib_get -F%.3f -p max $outfile` -[ "$max" = "346.209" ] + ${tools_dir}/grib_set -rs unitsFactor=1.1,unitsBias=4 $infile $outfile + max=`${tools_dir}/grib_get -F%.3f -p max $outfile` + [ "$max" = "346.209" ] -${tools_dir}/grib_set -rs unitsFactor=2 $infile $outfile -max=`${tools_dir}/grib_get -F%.3f -p max $outfile` -[ "$max" = "622.197" ] + ${tools_dir}/grib_set -rs unitsFactor=2 $infile $outfile + max=`${tools_dir}/grib_get -F%.3f -p max $outfile` + [ "$max" = "622.197" ] -${tools_dir}/grib_set -rs unitsBias=4 $infile $outfile -max=`${tools_dir}/grib_get -F%.3f -p max $outfile` -[ "$max" = "315.099" ] + ${tools_dir}/grib_set -rs unitsBias=4 $infile $outfile + max=`${tools_dir}/grib_get -F%.3f -p max $outfile` + [ "$max" = "315.099" ] +done +if [ $HAVE_JPEG -eq 1 ]; then + infile=${data_dir}/jpeg.grib2 + ${tools_dir}/grib_get -p max -s unitsBias=1.5 $infile $outfile + ${tools_dir}/grib_get -p min -s unitsFactor=2 $infile $outfile + ${tools_dir}/grib_get -p avg -s unitsFactor=1.1,unitsBias=100 $infile $outfile +fi # Clean up rm -f $outfile From fdd650cba9788b98e791f8c69f38ebf5742d9e98 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 1 Mar 2024 17:18:18 +0000 Subject: [PATCH 115/156] GTS: Another instance of ECC-735 --- src/grib_io.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_io.cc b/src/grib_io.cc index c47e4d509..b20dbce7b 100644 --- a/src/grib_io.cc +++ b/src/grib_io.cc @@ -952,7 +952,7 @@ static int read_any_gts(reader* r) unsigned long magic = 0; unsigned long start = 0x010d0d0a; /* SOH CR CR LF */ unsigned long theEnd = 0x0d0d0a03; /* CR CR LF ETX */ - unsigned char tmp[1024] = {0,}; /* See ECC-735 */ + unsigned char tmp[16384] = {0,}; /* See ECC-735 */ size_t message_size = 0; size_t already_read = 0; int i = 0; From 40b0f34701ee3b72624db14d7be5c4ee34672f29 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 23:01:36 +0000 Subject: [PATCH 116/156] Bamboo CIE: Enable extra tools --- bamboo/flags.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bamboo/flags.cmake b/bamboo/flags.cmake index 832133409..b434036aa 100644 --- a/bamboo/flags.cmake +++ b/bamboo/flags.cmake @@ -1,4 +1,5 @@ -SET(ENABLE_EXTRA_TESTS ON CACHE BOOL "Enable extra tests") -SET(ENABLE_ECCODES_THREADS ON CACHE BOOL "Enable POSIX threads") -SET(ENABLE_MEMFS ON CACHE BOOL "Enable MEMFS") +SET(ENABLE_EXTRA_TESTS ON CACHE BOOL "Enable extra tests") +SET(ECCODES_INSTALL_EXTRA_TOOLS ON CACHE BOOL "Install extra tools") +SET(ENABLE_ECCODES_THREADS ON CACHE BOOL "Enable POSIX threads") +SET(ENABLE_MEMFS ON CACHE BOOL "Enable MEMFS") # SET(ENABLE_JPG_LIBOPENJPEG OFF CACHE BOOL "Disable OpenJPEG") From 4112313874e5c77854dd17991e2e9484274f75c6 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 23:12:05 +0000 Subject: [PATCH 117/156] Make local function static --- src/action_class_template.cc | 9 +++------ src/eccodes_prototypes.h | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/action_class_template.cc b/src/action_class_template.cc index 8f240ea27..33a753513 100644 --- a/src/action_class_template.cc +++ b/src/action_class_template.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" @@ -115,19 +114,17 @@ static void dump(grib_action* act, FILE* f, int lvl) grib_context_print(act->context, f, "Template %s %s\n", act->name, a->arg); } -grib_action* get_empty_template(grib_context* c, int* err) +static grib_action* get_empty_template(grib_context* c, int* err) { char fname[] = "empty_template.def"; - char* path = 0; - - path = grib_context_full_defs_path(c, fname); + char* path = grib_context_full_defs_path(c, fname); if (path) { *err = GRIB_SUCCESS; return grib_parse_file(c, path); } else { *err = GRIB_INTERNAL_ERROR; - grib_context_log(c, GRIB_LOG_ERROR, "get_empty_template: unable to get template %s", fname); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to get template %s", __func__, fname); return NULL; } } diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 34a63088f..67ae32d11 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -57,7 +57,6 @@ grib_action* grib_action_create_assert(grib_context* context, grib_expression* e /* action_class_template.cc*/ grib_action* grib_action_create_template(grib_context* context, int nofail, const char* name, const char* arg1); -grib_action* get_empty_template(grib_context* c, int* err); /* action_class_trigger.cc*/ grib_action* grib_action_create_trigger(grib_context* context, grib_arguments* args, grib_action* block); From e24fdb90f1f37defde75938f8ba456a77c68c7d7 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 23:34:10 +0000 Subject: [PATCH 118/156] Rename template to sample --- src/eccodes_prototypes.h | 4 ++-- src/grib_handle.cc | 7 +++---- src/grib_templates.cc | 34 ++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 67ae32d11..73f47e3a3 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1101,8 +1101,8 @@ double grib_power(long s, long n); long grib_get_binary_scale_fact(double max, double min, long bpval, int* error); /* grib_templates.cc*/ -grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, const char* name); -char* get_external_template_path(grib_context* c, const char* name); +grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name); +char* get_external_sample_path(grib_context* c, const char* name); /* grib_dependency.cc*/ grib_handle* grib_handle_of_accessor(const grib_accessor* a); diff --git a/src/grib_handle.cc b/src/grib_handle.cc index e1c361eba..732537f12 100644 --- a/src/grib_handle.cc +++ b/src/grib_handle.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" @@ -228,7 +227,7 @@ grib_handle* codes_handle_new_from_samples(grib_context* c, const char* name) fprintf(stderr, "ECCODES DEBUG codes_handle_new_from_samples '%s'\n", name); } - g = codes_external_template(c, PRODUCT_ANY, name); + g = codes_external_sample(c, PRODUCT_ANY, name); if (!g) { grib_context_log(c, GRIB_LOG_ERROR, "Unable to load sample file '%s.tmpl'\n" @@ -256,7 +255,7 @@ grib_handle* grib_handle_new_from_samples(grib_context* c, const char* name) fprintf(stderr, "ECCODES DEBUG grib_handle_new_from_samples '%s'\n", name); } - g = codes_external_template(c, PRODUCT_GRIB, name); + g = codes_external_sample(c, PRODUCT_GRIB, name); if (!g) grib_context_log(c, GRIB_LOG_ERROR, "Unable to load GRIB sample file '%s.tmpl'\n" @@ -279,7 +278,7 @@ grib_handle* codes_bufr_handle_new_from_samples(grib_context* c, const char* nam fprintf(stderr, "ECCODES DEBUG bufr_handle_new_from_samples '%s'\n", name); } - g = codes_external_template(c, PRODUCT_BUFR, name); + g = codes_external_sample(c, PRODUCT_BUFR, name); if (!g) { grib_context_log(c, GRIB_LOG_ERROR, "Unable to load BUFR sample file '%s.tmpl'\n" diff --git a/src/grib_templates.cc b/src/grib_templates.cc index 3e357382c..ca2076a2a 100644 --- a/src/grib_templates.cc +++ b/src/grib_templates.cc @@ -35,15 +35,15 @@ // return NULL; // } -/* Windows always has a colon in pathnames e.g. C:\temp\file. It uses semi-colons as delimiter */ +// Windows always has a colon in pathnames e.g. C:\temp\file. It uses semi-colons as delimiter #ifdef ECCODES_ON_WINDOWS #define ECC_PATH_DELIMITER_CHAR ';' #else #define ECC_PATH_DELIMITER_CHAR ':' #endif -/* if product_kind is PRODUCT_ANY, the type of sample file is determined at runtime */ -static grib_handle* try_product_template(grib_context* c, ProductKind product_kind, const char* dir, const char* name) +// if product_kind is PRODUCT_ANY, the type of sample file is determined at runtime +static grib_handle* try_product_sample(grib_context* c, ProductKind product_kind, const char* dir, const char* name) { char path[1024]; grib_handle* g = NULL; @@ -55,10 +55,10 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name); if (c->debug) { - fprintf(stderr, "ECCODES DEBUG try_product_template product=%s, path='%s'\n", codes_get_product_name(product_kind), path); + fprintf(stderr, "ECCODES DEBUG try_product_sample product=%s, path='%s'\n", codes_get_product_name(product_kind), path); } - if (codes_access(path, F_OK) == 0) { /* 0 means file exists */ + if (codes_access(path, F_OK) == 0) { // 0 means file exists FILE* f = codes_fopen(path, "r"); if (!f) { grib_context_log(c, GRIB_LOG_PERROR, "cannot open %s", path); @@ -66,7 +66,7 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki } if (product_kind == PRODUCT_ANY) { - /* Determine the product kind from sample file */ + // Determine the product kind from sample file char* mesg = NULL; size_t size = 0; off_t offset = 0; @@ -89,7 +89,7 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki if (product_kind == PRODUCT_BUFR) { g = codes_bufr_handle_new_from_file(c, f, &err); } else { - /* Note: Pseudo GRIBs like DIAG and BUDG also come here */ + // Note: Pseudo GRIBs like DIAG and BUDG also come here DEBUG_ASSERT(product_kind == PRODUCT_GRIB); g = grib_handle_new_from_file(c, f, &err); } @@ -102,22 +102,24 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki return g; } -static char* try_template_path(grib_context* c, const char* dir, const char* name) +static char* try_sample_path(grib_context* c, const char* dir, const char* name) { + // The ".tmpl" extension is historic. It should have been ".sample" char path[2048]; if (string_ends_with(name, ".tmpl")) snprintf(path, sizeof(path), "%s/%s", dir, name); else snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name); - if (codes_access(path, F_OK) == 0) { /* 0 means file exists */ + if (codes_access(path, F_OK) == 0) { // 0 means file exists return grib_context_strdup(c, path); } return NULL; } -grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, const char* name) +// External here means on disk +grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name) { const char* base = c->grib_samples_path; char buffer[1024]; @@ -130,21 +132,21 @@ grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, while (*base) { if (*base == ECC_PATH_DELIMITER_CHAR) { *p = 0; - g = try_product_template(c, product_kind, buffer, name); + g = try_product_sample(c, product_kind, buffer, name); if (g) return g; p = buffer; - base++; /*advance past delimiter*/ + base++; //advance past delimiter } *p++ = *base++; } *p = 0; - g = try_product_template(c, product_kind, buffer, name); + g = try_product_sample(c, product_kind, buffer, name); return g; } -char* get_external_template_path(grib_context* c, const char* name) +char* get_external_sample_path(grib_context* c, const char* name) { const char* base = c->grib_samples_path; char buffer[1024]; @@ -157,7 +159,7 @@ char* get_external_template_path(grib_context* c, const char* name) while (*base) { if (*base == ECC_PATH_DELIMITER_CHAR) { *p = 0; - g = try_template_path(c, buffer, name); + g = try_sample_path(c, buffer, name); if (g) return g; p = buffer; @@ -167,5 +169,5 @@ char* get_external_template_path(grib_context* c, const char* name) } *p = 0; - return g = try_template_path(c, buffer, name); + return g = try_sample_path(c, buffer, name); } From 278ee348c4377fbb551f2c525c415a4be62d5266 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 1 Mar 2024 23:34:18 +0000 Subject: [PATCH 119/156] Rename template to sample --- tools/codes_export_resource.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/codes_export_resource.cc b/tools/codes_export_resource.cc index f2d484fbb..61a8b7db6 100644 --- a/tools/codes_export_resource.cc +++ b/tools/codes_export_resource.cc @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) } if (resource_type == SAMPLE) { - full_path = get_external_template_path(c, resource_path); + full_path = get_external_sample_path(c, resource_path); } else if (resource_type == DEFINITION) { full_path = grib_context_full_defs_path(c, resource_path); From 71cabbf6ddb8a5df843cd4db6d17b9634aa59da3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Sun, 3 Mar 2024 19:05:57 +0000 Subject: [PATCH 120/156] C++ flags: Add them in a failsafe manner --- CMakeLists.txt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f60682739..2b340ad1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,17 +73,11 @@ endif() ############################################################################### # some variables/options of this project -if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ) - ecbuild_add_cxx_flags("-Wno-write-strings") - ecbuild_add_cxx_flags("-Wno-deprecated") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - ecbuild_add_cxx_flags("-Wno-write-strings") - ecbuild_add_cxx_flags("-Wno-deprecated") - else() - ecbuild_add_cxx_flags("-Wno-writable-strings") - endif() -elseif( CMAKE_CXX_COMPILER_ID STREQUAL "Cray" ) +ecbuild_add_cxx_flags("-Wno-write-strings" NO_FAIL) +ecbuild_add_cxx_flags("-Wno-writable-strings" NO_FAIL) +ecbuild_add_cxx_flags("-Wno-deprecated" NO_FAIL) + +if( CMAKE_CXX_COMPILER_ID STREQUAL "Cray" ) set(CMAKE_CXX_FLAGS "-hstd=c++11 ${CMAKE_CXX_FLAGS}") endif() From 12a2484c13ede467c17b0986fc795f51fcb295cf Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 10:25:35 +0000 Subject: [PATCH 121/156] Const correctness and cppcheck warnings --- src/eccodes_prototypes.h | 2 +- src/grib_accessor_classes_hash.cc | 2 +- src/grib_context.cc | 2 +- src/grib_hash_keys.cc | 2 +- src/make_accessor_class_hash.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 73f47e3a3..2ac2f9e13 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1104,7 +1104,7 @@ long grib_get_binary_scale_fact(double max, double min, long bpval, int* error); grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name); char* get_external_sample_path(grib_context* c, const char* name); -/* grib_dependency.cc*/ +/* grib_dependency.cc */ grib_handle* grib_handle_of_accessor(const grib_accessor* a); void grib_dependency_add(grib_accessor* observer, grib_accessor* observed); void grib_dependency_remove_observed(grib_accessor* observed); diff --git a/src/grib_accessor_classes_hash.cc b/src/grib_accessor_classes_hash.cc index 2643a32fb..5617c9456 100644 --- a/src/grib_accessor_classes_hash.cc +++ b/src/grib_accessor_classes_hash.cc @@ -35,7 +35,7 @@ #include "grib_accessor_class.h" #line 6 "accessor_class_list.gperf" -struct accessor_class_hash { char *name; grib_accessor_class **cclass;}; +struct accessor_class_hash { const char *name; grib_accessor_class **cclass;}; #define TOTAL_KEYWORDS 205 #define MIN_WORD_LENGTH 1 diff --git a/src/grib_context.cc b/src/grib_context.cc index 446481c4a..a22fcc654 100644 --- a/src/grib_context.cc +++ b/src/grib_context.cc @@ -453,7 +453,7 @@ grib_context* grib_context_get_default() #ifdef ECCODES_SAMPLES_PATH if (!default_grib_context.grib_samples_path) - default_grib_context.grib_samples_path = ECCODES_SAMPLES_PATH; + default_grib_context.grib_samples_path = (char*)ECCODES_SAMPLES_PATH; #endif default_grib_context.grib_definition_files_path = codes_getenv("ECCODES_DEFINITION_PATH"); diff --git a/src/grib_hash_keys.cc b/src/grib_hash_keys.cc index a71738e88..ba26dbe03 100644 --- a/src/grib_hash_keys.cc +++ b/src/grib_hash_keys.cc @@ -31,7 +31,7 @@ #include "grib_api_internal.h" -struct grib_keys_hash { char* name; int id;}; +struct grib_keys_hash { const char* name; int id;}; #include #define TOTAL_KEYWORDS 2535 diff --git a/src/make_accessor_class_hash.sh b/src/make_accessor_class_hash.sh index 8a3f26f79..72955ae4a 100755 --- a/src/make_accessor_class_hash.sh +++ b/src/make_accessor_class_hash.sh @@ -6,7 +6,7 @@ cat > accessor_class_list.gperf < Date: Mon, 4 Mar 2024 10:25:52 +0000 Subject: [PATCH 122/156] Const correctness and cppcheck warnings --- tests/list_all_keys.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/list_all_keys.sh b/tests/list_all_keys.sh index 573d166d6..78ee26631 100755 --- a/tests/list_all_keys.sh +++ b/tests/list_all_keys.sh @@ -32,7 +32,7 @@ cat >keys <> keys From f7ba64e1304910639a52e1f4f8d48e154edd9e1b Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 11:03:26 +0000 Subject: [PATCH 123/156] Openjpeg 2.5.2 fixes the problem with 2.5.1 --- src/grib_openjpeg_encoding.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/grib_openjpeg_encoding.cc b/src/grib_openjpeg_encoding.cc index 9b3b67566..f03ba2fcb 100644 --- a/src/grib_openjpeg_encoding.cc +++ b/src/grib_openjpeg_encoding.cc @@ -13,8 +13,10 @@ #if HAVE_LIBOPENJPEG #include "openjpeg.h" + // The older versions did not have the opj_config.h file -// So we use a more recent macro to detect whether it is there +// So we use a more recent macro to detect whether it is there. +// Also see https://github.com/uclouvain/openjpeg/issues/1514 #if defined(OPJ_IMG_INFO) #include "opj_config.h" #endif From 2482483e76f41d1dc9e1008ce6a4b6a662a9d58f Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 11:03:44 +0000 Subject: [PATCH 124/156] Const correctness and cppcheck warnings --- tools/grib_options.cc | 2 +- tools/grib_tools.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/grib_options.cc b/tools/grib_options.cc index f9ef49400..8059f1b0b 100644 --- a/tools/grib_options.cc +++ b/tools/grib_options.cc @@ -139,7 +139,7 @@ char* grib_options_get_option(const char* id) int i = 0; for (i = 0; i < grib_options_count; i++) { if (!strcmp(id, grib_options[i].id)) - return grib_options[i].value; + return (char*)grib_options[i].value; } return NULL; } diff --git a/tools/grib_tools.h b/tools/grib_tools.h index 34465b628..6f54074e1 100644 --- a/tools/grib_tools.h +++ b/tools/grib_tools.h @@ -83,7 +83,7 @@ typedef struct grib_option const char* help; int on; int command_line; - char* value; + const char* value; } grib_option; typedef struct grib_failed grib_failed; From 4e4b7676f91dcc1448b3560a6e67e79dc561862b Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 11:04:54 +0000 Subject: [PATCH 125/156] C++ flags: No need for suppressing writable-strings warnings --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b340ad1d..3ff3609ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,9 +73,9 @@ endif() ############################################################################### # some variables/options of this project -ecbuild_add_cxx_flags("-Wno-write-strings" NO_FAIL) -ecbuild_add_cxx_flags("-Wno-writable-strings" NO_FAIL) -ecbuild_add_cxx_flags("-Wno-deprecated" NO_FAIL) +# ecbuild_add_cxx_flags("-Wno-write-strings" NO_FAIL) +# ecbuild_add_cxx_flags("-Wno-writable-strings" NO_FAIL) +# ecbuild_add_cxx_flags("-Wno-deprecated" NO_FAIL) if( CMAKE_CXX_COMPILER_ID STREQUAL "Cray" ) set(CMAKE_CXX_FLAGS "-hstd=c++11 ${CMAKE_CXX_FLAGS}") From 33223f4c5abe9922cd7237cdf600d3e2e33e8005 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 12:55:25 +0000 Subject: [PATCH 126/156] Testing: skipping messages --- tests/grib_ls.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/grib_ls.sh b/tests/grib_ls.sh index bdbdba4d4..390df9d7c 100755 --- a/tests/grib_ls.sh +++ b/tests/grib_ls.sh @@ -172,6 +172,14 @@ grep -q "0 of 38 messages" $tempText ${tools_dir}/grib_ls -w units!=K $file > $tempText grep -q "30 of 38 messages" $tempText +${tools_dir}/grib_ls -w scaleFactorOfSecondFixedSurface=missing $file > $tempText +grep -q "36 of 38 messages" $tempText +${tools_dir}/grib_ls -w scaleFactorOfSecondFixedSurface!=missing $file > $tempText +grep -q "2 of 38 messages" $tempText + +${tools_dir}/grib_ls -w referenceValue=0 $file > $tempText +grep -q "11 of 38 messages" $tempText + file=mixed.grib # Has 14 messages ${tools_dir}/grib_ls -w packingType=grid_simple,gridType=regular_ll/regular_gg $file > $tempText grep -q "12 of 14 messages" $tempText From 3e3f0063cff534c8818d7cb713fc27e8016e396e Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 13:15:11 +0000 Subject: [PATCH 127/156] Tools: Dead code removal --- tools/grib_options.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/grib_options.cc b/tools/grib_options.cc index 8059f1b0b..c15de1d80 100644 --- a/tools/grib_options.cc +++ b/tools/grib_options.cc @@ -357,12 +357,6 @@ int grib_process_runtime_options(grib_context* context, int argc, char** argv, g else grib_gts_header_off(context); - if (grib_options_on("V")) { - printf("\necCodes Version "); - grib_print_api_version(stdout); - printf("\n\n"); - } - if (grib_options_on("s:")) { sarg = grib_options_get_option("s:"); options->set_values_count = MAX_KEYS; From 8347bbcae67583aa668e5c6a8b29747e66550bd6 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 13:15:49 +0000 Subject: [PATCH 128/156] Testing: Basic tools invocation --- tests/grib_ls.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/grib_ls.sh b/tests/grib_ls.sh index 390df9d7c..8e895b48a 100755 --- a/tests/grib_ls.sh +++ b/tests/grib_ls.sh @@ -32,6 +32,24 @@ set -e grep -q "Full documentation and examples at" $tempLog grep -q "https://confluence.ecmwf.int/display/ECC/grib_ls" $tempLog +set +e +${tools_dir}/grib_ls -? > $tempLog +status=$? +set -e +[ $status -ne 0 ] + +set +e +${tools_dir}/grib_ls -h > $tempLog +status=$? +set -e +[ $status -ne 0 ] + +set +e +DOXYGEN_USAGE=1 ${tools_dir}/grib_ls > $tempLog +status=$? +set -e +[ $status -ne 0 ] + ${tools_dir}/grib_ls -P count $infile > $tempLog ${tools_dir}/grib_ls -p count,step $infile >> $tempLog From 6f10faac1ca8ba89cf5973d31932e6d216270821 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 18:35:10 +0000 Subject: [PATCH 129/156] Testing: Several time ranges --- tests/grib_step.sh | 56 ++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/tests/grib_step.sh b/tests/grib_step.sh index e7e9e28ff..4ed45a3f1 100755 --- a/tests/grib_step.sh +++ b/tests/grib_step.sh @@ -14,8 +14,9 @@ REDIRECT=/dev/null label=grib_step_test tempGrb=${data_dir}/temp.$label.out.grib -templog=${data_dir}/temp.$label.log -rm -f $templog $tempGrb +tempLog=${data_dir}/temp.$label.log +tempFilt=${data_dir}/temp.$label.filt +rm -f $tempLog $tempGrb grib1_sample=$ECCODES_SAMPLES_PATH/GRIB1.tmpl grib2_sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl @@ -31,7 +32,7 @@ do #echo grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb #grib_get -p step,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb ${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \ - ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> ${templog} + ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> $tempLog done done done @@ -44,7 +45,7 @@ do #echo grib_set -s ${key}=$s ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb #grib_ls -p step,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb ${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \ - ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> ${templog} + ${data_dir}/timeRangeIndicator_${i}.grib $tempGrb >> $tempLog done rm -f $tempGrb @@ -52,17 +53,17 @@ rm -f $tempGrb # test added for ifs stepType=max,min ${tools_dir}/grib_set -s stepType=max,startStep=3,endStep=6 ${data_dir}/reduced_gaussian_model_level.grib1 $tempGrb ${tools_dir}/grib_get -p mars.step,stepRange,startStep,endStep,P1,P2,timeRangeIndicator,indicatorOfUnitOfTimeRange:l \ - ${data_dir}/reduced_gaussian_model_level.grib1 $tempGrb >> ${templog} + ${data_dir}/reduced_gaussian_model_level.grib1 $tempGrb >> $tempLog rm -f $tempGrb -diff ${data_dir}/step.log ${templog} +diff ${data_dir}/step.log $tempLog -(${tools_dir}/grib_filter ${data_dir}/step_grib1.filter ${data_dir}/timeRangeIndicator_0.grib > ${templog}) 2>$REDIRECT +(${tools_dir}/grib_filter ${data_dir}/step_grib1.filter ${data_dir}/timeRangeIndicator_0.grib > $tempLog) 2>$REDIRECT -diff ${data_dir}/step_grib1.log ${templog} +diff ${data_dir}/step_grib1.log $tempLog -rm -f ${templog} +rm -f $tempLog # GRIB-180 # ------------ @@ -166,10 +167,10 @@ grib_check_key_equals $temp day 7 # Seconds (ignored) # ----------------- -${tools_dir}/grib_ls -s second=9 -n time $grib2_sample 2>$templog +${tools_dir}/grib_ls -s second=9 -n time $grib2_sample 2>$tempLog # Something should have been written to stderr -[ -s $templog ] -grep -q "Truncating time: non-zero seconds.* ignored" $templog +[ -s $tempLog ] +grep -q "Truncating time: non-zero seconds.* ignored" $tempLog # Hour or minute set to 255 # --------------------------- @@ -214,33 +215,50 @@ ECCODES_GRIBEX_MODE_ON=1 ${tools_dir}/grib_set -s stepRange=11-12 $input $temp grib_check_key_equals $temp P1,P2 '0 11' set +e -${tools_dir}/grib_set -s stepRange=11-12 $input $temp 2>$templog +${tools_dir}/grib_set -s stepRange=11-12 $input $temp 2>$tempLog status=$? set -e [ $status -ne 0 ] -grep -q "Unable to set stepRange" $templog +grep -q "Unable to set stepRange" $tempLog # GRIB1: sub-hourly # ----------------- ${tools_dir}/grib_set -s unitOfTimeRange=0,P1=5 $grib1_sample $temp set +e -${tools_dir}/grib_get -p step $temp 2>$templog +${tools_dir}/grib_get -p step $temp 2>$tempLog status=$? set -e [ $status -ne 0 ] -grep -q "unable to represent the step in h" $templog +grep -q "unable to represent the step in h" $tempLog # GRIB1: Unknown timeRangeIndicator ${tools_dir}/grib_set -s timeRangeIndicator=138 $grib1_sample $temp set +e -${tools_dir}/grib_get -p step $temp 2>$templog +${tools_dir}/grib_get -p step $temp 2>$tempLog status=$? set -e [ $status -ne 0 ] -grep -q "Unknown stepType" $templog +grep -q "Unknown stepType" $tempLog +# Several time ranges +# -------------------- +cat >$tempFilt < $tempLog +cat $tempLog +grep -q "255 8 7" $tempLog # Clean up -rm -f $temp $templog +rm -f $temp $tempLog $tempFilt rm -f $grib2File.p8tmp ${grib2File}.tmp x.grib From 0514d24a72d1c3144b93fa93f4663e2008e824bc Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 18:52:22 +0000 Subject: [PATCH 130/156] Testing: Cleanup --- tests/grib_bpv_limit.cc | 8 +------- tests/grib_ecc-1467.cc | 15 ++++----------- tests/grib_ecc-386.cc | 27 ++++----------------------- tests/grib_multi_from_message.cc | 28 +++++----------------------- 4 files changed, 14 insertions(+), 64 deletions(-) diff --git a/tests/grib_bpv_limit.cc b/tests/grib_bpv_limit.cc index b5a3af0f6..97be2e39c 100644 --- a/tests/grib_bpv_limit.cc +++ b/tests/grib_bpv_limit.cc @@ -25,12 +25,6 @@ static double compare_double_absolute(double a, double b, double tolerance) return ret; } -static void usage(const char* prog) -{ - fprintf(stderr, "usage: %s input\n", prog); - exit(1); -} - static int check_error_code(int err) { if (err == GRIB_INVALID_BPV || err == GRIB_DECODING_ERROR) @@ -49,7 +43,7 @@ int main(int argc, char** argv) grib_handle* h; char* filename; - if (argc < 2) usage(argv[0]); + Assert(argc == 2); filename = argv[1]; for (i = 0; i < 255; i++) { diff --git a/tests/grib_ecc-1467.cc b/tests/grib_ecc-1467.cc index 20a2b7268..3e20bdb08 100644 --- a/tests/grib_ecc-1467.cc +++ b/tests/grib_ecc-1467.cc @@ -26,21 +26,14 @@ int main(int argc, char** argv) double dmin, dmax, dval; float fval; - FILE* in = NULL; - const char* filename = 0; - codes_handle* h = NULL; - - if (argc != 2) { - fprintf(stderr, "usage: %s file\n", argv[0]); - return 1; - } - filename = argv[1]; + Assert(argc == 2); + const char* filename = argv[1]; printf("Opening %s\n", filename); - in = fopen(filename, "rb"); + FILE* in = fopen(filename, "rb"); Assert(in); - h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); + codes_handle* h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); Assert(h); CODES_CHECK(codes_get_float(h, "referenceValue", &fval), 0); diff --git a/tests/grib_ecc-386.cc b/tests/grib_ecc-386.cc index d4e238c4f..10f2adcdb 100644 --- a/tests/grib_ecc-386.cc +++ b/tests/grib_ecc-386.cc @@ -9,18 +9,11 @@ */ /* - * Description: Reads a GRIB message from file, measures read time. - * + * Description: Reads a GRIB message from file, measures time taken */ #include #include "grib_api_internal.h" -static void usage(const char* prog) -{ - printf("usage: %s filename\n", prog); - exit(1); -} - int main(int argc, char** argv) { grib_timer* tes = grib_get_timer(0, "decoding", 0, 0); @@ -33,21 +26,15 @@ int main(int argc, char** argv) const double duration_max = 3.6; /* seconds */ const int num_repetitions = 100; - if (argc < 2) usage(argv[0]); + if (argc < 2) return 1; in = fopen(argv[1], "rb"); - if (!in) { - printf("ERROR: unable to open file %s\n", argv[1]); - return 1; - } + Assert(in); /* create new handle */ err = 0; h = grib_handle_new_from_file(0, in, &err); - if (h == NULL) { - printf("Error: unable to create handle from file.\n"); - return 1; - } + Assert(h); /* get the size of the values array*/ GRIB_CHECK(grib_get_size(h, "values", &values_len), 0); @@ -72,9 +59,3 @@ int main(int argc, char** argv) fclose(in); return 0; } - -// int main(int argc, char** argv) -// { -// return 0; -// } -// #endif diff --git a/tests/grib_multi_from_message.cc b/tests/grib_multi_from_message.cc index 798230db5..1728e371c 100644 --- a/tests/grib_multi_from_message.cc +++ b/tests/grib_multi_from_message.cc @@ -8,25 +8,14 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/* - * test: reading GRIB2 multi fields messages from memory - */ +/* Test: reading GRIB2 multi fields messages from memory */ #include "grib_api_internal.h" - -static void usage(const char* prog) -{ - fprintf(stderr, "usage: %s [-m] file.grib\n", prog); - exit(1); -} - int main(int argc, char* argv[]) { struct stat finfo; - char shortName[20] = { - 0, - }; + char shortName[20] = {0,}; size_t len; grib_handle* h = NULL; size_t fsize; @@ -49,25 +38,18 @@ int main(int argc, char* argv[]) else if (argc == 2) filename = argv[1]; else - usage(argv[0]); + return 1; Assert(filename); f = fopen(filename, "rb"); - if (!f) { - perror(filename); - exit(1); - } + Assert(f); stat(filename, &finfo); fsize = finfo.st_size; data = (unsigned char*)malloc(fsize); p = data; - - if (!data) { - fprintf(stderr, "unable to allocate %ld bytes\n", (long)fsize); - exit(1); - } + Assert(data); if (fread(data, 1, fsize, f) != fsize) { perror(filename); From c38285e5674f6287e212a898ec5576149efb005f Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 18:54:38 +0000 Subject: [PATCH 131/156] Testing: Cleanup --- tests/read_any.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/read_any.cc b/tests/read_any.cc index f340aede9..98f1d450f 100644 --- a/tests/read_any.cc +++ b/tests/read_any.cc @@ -9,12 +9,6 @@ */ #include "grib_api.h" -static void usage(const char* prog) -{ - printf("usage: %s infile\n", prog); - exit(1); -} - static unsigned char buffer[50000000]; int main(int argc, char* argv[]) @@ -35,7 +29,7 @@ int main(int argc, char* argv[]) size_t len; if (argc != 2) - usage(argv[0]); + return 1; filename = argv[1]; f = fopen(filename, "rb"); From 3fc47dcf77d405c0e9677b8dadcc680da904733d Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Mar 2024 20:45:39 +0000 Subject: [PATCH 132/156] Testing: Coverage --- tests/bufr_keys_iter.cc | 9 +-------- tests/gauss_sub.cc | 8 +------- tests/grib_clone_headers_only.cc | 9 ++------- tests/grib_ecc-1467.cc | 6 ++++-- tests/grib_ecc-1467.sh | 2 ++ tests/grib_fieldset.cc | 8 +------- tests/index_orderby.cc | 8 +------- tests/largefile.cc | 8 +------- 8 files changed, 13 insertions(+), 45 deletions(-) diff --git a/tests/bufr_keys_iter.cc b/tests/bufr_keys_iter.cc index f2ab295b7..9938fcdd5 100644 --- a/tests/bufr_keys_iter.cc +++ b/tests/bufr_keys_iter.cc @@ -12,12 +12,6 @@ #undef NDEBUG #include -static void usage(const char* prog) -{ - printf("usage: %s [-a|-d] infile\n", prog); - exit(1); -} - #define ITER_ALL_KEYS 1 #define ITER_DATA_KEYS 2 @@ -28,12 +22,11 @@ int main(int argc, char* argv[]) codes_handle* h = NULL; codes_bufr_keys_iterator* kiter = NULL; char* input_filename = NULL; - const char* prog = argv[0]; FILE* f = NULL; int iterator_mode = ITER_ALL_KEYS; if (argc == 1 || argc > 3) - usage(prog); + return 1; // usage: prog [-a|-d] infile for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-a") == 0) { diff --git a/tests/gauss_sub.cc b/tests/gauss_sub.cc index b1114e964..b743b5d3c 100644 --- a/tests/gauss_sub.cc +++ b/tests/gauss_sub.cc @@ -10,12 +10,6 @@ #include "grib_api.h" -static void usage(char* prog) -{ - printf("usage: %s file1.grib file2.grib\n", prog); - exit(1); -} - int main(int argc, char* argv[]) { grib_handle *h1, *h2; @@ -34,7 +28,7 @@ int main(int argc, char* argv[]) c = grib_context_get_default(); - if (argc < 3) usage(argv[0]); + if (argc < 3) return 1;//usage: %s file1.grib file2.grib infile1 = argv[1]; infile2 = argv[2]; diff --git a/tests/grib_clone_headers_only.cc b/tests/grib_clone_headers_only.cc index f59b204ed..6a029b1ca 100644 --- a/tests/grib_clone_headers_only.cc +++ b/tests/grib_clone_headers_only.cc @@ -12,11 +12,6 @@ #undef NDEBUG #include -static void usage(const char* app) -{ - fprintf(stderr, "Usage is: %s input_file ouput_file\n", app); -} - int main(int argc, char* argv[]) { FILE* in = NULL; @@ -32,7 +27,7 @@ int main(int argc, char* argv[]) size_t messageLength_src = 0, messageLength_dst = 0; if (argc != 3) { - usage(argv[0]); + // Usage: prog input_file ouput_file return 1; } @@ -73,7 +68,7 @@ int main(int argc, char* argv[]) assert(isConstant_dst == 1); } - /* write out the cloned buffer */ + // write out the cloned buffer if (fwrite(buffer, 1, messageLength_dst, out) != messageLength_dst) { perror(argv[1]); return 1; diff --git a/tests/grib_ecc-1467.cc b/tests/grib_ecc-1467.cc index 3e20bdb08..5c5e8e53b 100644 --- a/tests/grib_ecc-1467.cc +++ b/tests/grib_ecc-1467.cc @@ -8,6 +8,9 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +// +// ECC-1467: Support data values array decoded as "floats" (single-precision) +// #include #include "eccodes.h" #include "grib_api_internal.h" @@ -60,8 +63,7 @@ int main(int argc, char** argv) fval = fvalues[i]; if (!((dmin <= fval) && (fval <= dmax))) { - fprintf(stderr, "Error:\n"); - fprintf(stderr, "dvalue: %f, fvalue: %f\n", dvalues[i], fvalues[i]); + fprintf(stderr, "Error: dvalue: %f, fvalue: %f\n", dvalues[i], fvalues[i]); fprintf(stderr, "\tmin < fvalue < max = %.20e < %.20e < %.20e FAILED\n", dmin, fvalues[i], dmax); fprintf(stderr, "\tfvalue - min = %.20e (%s)\n", diff --git a/tests/grib_ecc-1467.sh b/tests/grib_ecc-1467.sh index fb5d0bd1c..abb9aa5f3 100755 --- a/tests/grib_ecc-1467.sh +++ b/tests/grib_ecc-1467.sh @@ -8,6 +8,8 @@ # virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. # +# ECC-1467: Support data values array decoded as "floats" (single-precision) + . ./include.ctest.sh # Constant fields diff --git a/tests/grib_fieldset.cc b/tests/grib_fieldset.cc index a6eb38ce7..d1431b021 100644 --- a/tests/grib_fieldset.cc +++ b/tests/grib_fieldset.cc @@ -13,12 +13,6 @@ #include "grib_api.h" -static void usage(const char* prog) -{ - fprintf(stderr, "Usage: %s order_by grib_file grib_file ...\n", prog); - exit(1); -} - int main(int argc, char** argv) { int err = 0; @@ -34,7 +28,7 @@ int main(int argc, char** argv) size_t lenDate = 10, lenParam = 20, lenLevel = 50; char* order_by = NULL; - if (argc != 3) usage(argv[0]); + if (argc != 3) return 1; //Usage: prog order_by grib_file grib_file ... nkeys = sizeof(keys) / sizeof(*keys); order_by = argv[1]; diff --git a/tests/index_orderby.cc b/tests/index_orderby.cc index f2346fc82..55ff9c2f5 100644 --- a/tests/index_orderby.cc +++ b/tests/index_orderby.cc @@ -10,12 +10,6 @@ #include "grib_api.h" -void usage(char* prog) -{ - printf("usage: %s infile\n", prog); - exit(1); -} - int main(int argc, char* argv[]) { grib_index* index = NULL; @@ -27,7 +21,7 @@ int main(int argc, char* argv[]) size_t lenshortName = 200; int ret = 0, count = 0; - if (argc != 2) usage(argv[0]); + if (argc != 2) return 1; infile = argv[1]; outfile = argv[2]; diff --git a/tests/largefile.cc b/tests/largefile.cc index a09d84be4..51e77949b 100644 --- a/tests/largefile.cc +++ b/tests/largefile.cc @@ -14,12 +14,6 @@ #include #endif -void usage(const char* prog) -{ - printf("usage: %s filename\n", prog); - exit(1); -} - int main(int argc, char* argv[]) { off_t offsetin = 0, offsetout = 0; @@ -30,7 +24,7 @@ int main(int argc, char* argv[]) char str[10]; int i; - if (argc != 2) usage(argv[0]); + if (argc != 2) return 1; printf("sizeof(off_t)=%zu sizeof(long)=%zu\n", sizeof(off_t), sizeof(long)); From 99a21bdd0f1a9c74ade031dd1850a265bf3a21a8 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 5 Mar 2024 13:19:31 +0000 Subject: [PATCH 133/156] Testing: headers only clone --- tests/grib_clone_headers_only.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/grib_clone_headers_only.cc b/tests/grib_clone_headers_only.cc index 6a029b1ca..f96048a15 100644 --- a/tests/grib_clone_headers_only.cc +++ b/tests/grib_clone_headers_only.cc @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) int err = 0; long totalLength_src = 0, totalLength_dst = 0; - long edition = 0, isGridded = 0, bitmapPresent = 0; + long edition = 0, isGridded_src = 0, bitmapPresent = 0; long isConstant_src = 0, isConstant_dst = 0; long dataSectionLength_src = 0, dataSectionLength_dst = 0; size_t messageLength_src = 0, messageLength_dst = 0; @@ -41,8 +41,8 @@ int main(int argc, char* argv[]) assert(clone_handle); codes_get_long(source_handle, "isConstant", &isConstant_src); - codes_get_long(source_handle, "isGridded", &isGridded); - if (isGridded && !isConstant_src) { + codes_get_long(source_handle, "isGridded", &isGridded_src); + if (isGridded_src && !isConstant_src) { CODES_CHECK(codes_get_message(source_handle, &buffer, &messageLength_src), 0); CODES_CHECK(codes_get_message(clone_handle, &buffer, &messageLength_dst), 0); From b83641aa474c4a4271278b0b10d2ae7cfb03958b Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 5 Mar 2024 13:42:57 +0000 Subject: [PATCH 134/156] ECC-1781: Geoiterator: Support reduced Gaussian grid with rotation --- src/grib_iterator_class_gaussian_reduced.cc | 52 +++++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/src/grib_iterator_class_gaussian_reduced.cc b/src/grib_iterator_class_gaussian_reduced.cc index cde71f746..7882cc54a 100644 --- a/src/grib_iterator_class_gaussian_reduced.cc +++ b/src/grib_iterator_class_gaussian_reduced.cc @@ -53,6 +53,11 @@ typedef struct grib_iterator_gaussian_reduced{ double *las; double *los; long Nj; + long isRotated; + double angleOfRotation; + double southPoleLat; + double southPoleLon; + long disableUnrotate; } grib_iterator_gaussian_reduced; extern grib_iterator_class* grib_iterator_class_gen; @@ -76,9 +81,9 @@ grib_iterator_class* grib_iterator_class_gaussian_reduced = &_grib_iterator_clas static void init_class(grib_iterator_class* c) { - c->previous = (*(c->super))->previous; - c->reset = (*(c->super))->reset; - c->has_next = (*(c->super))->has_next; + c->previous = (*(c->super))->previous; + c->reset = (*(c->super))->reset; + c->has_next = (*(c->super))->has_next; } /* END_CLASS_IMP */ @@ -87,16 +92,29 @@ static void init_class(grib_iterator_class* c) static int next(grib_iterator* iter, double* lat, double* lon, double* val) { grib_iterator_gaussian_reduced* self = (grib_iterator_gaussian_reduced*)iter; + double ret_lat=0, ret_lon=0; if (iter->e >= (long)(iter->nv - 1)) return 0; iter->e++; - *lat = self->las[iter->e]; - *lon = self->los[iter->e]; + ret_lat = self->las[iter->e]; + ret_lon = self->los[iter->e]; if (val && iter->data) { *val = iter->data[iter->e]; } + + if (self->isRotated && !self->disableUnrotate) { + double new_lat = 0, new_lon = 0; + unrotate(ret_lat, ret_lon, + self->angleOfRotation, self->southPoleLat, self->southPoleLon, + &new_lat, &new_lon); + ret_lat = new_lat; + ret_lon = new_lon; + } + *lat = ret_lat; + *lon = ret_lon; + return 1; } @@ -104,7 +122,7 @@ typedef void (*get_reduced_row_proc)(long pl, double lon_first, double lon_last, /* For a reduced Gaussian grid which is GLOBAL, the number of points is the sum of the 'pl' array */ /* i.e. the total number of points on all latitudes */ -static size_t count_global_points(long* pl, size_t plsize) +static size_t count_global_points(const long* pl, size_t plsize) { return sum_of_pl_array(pl, plsize); } @@ -288,9 +306,9 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) long* pl; long max_pl = 0; long nj = 0, order = 0, i; - long row_count = 0; - long angleSubdivisions = 0; - grib_context* c = h->context; + long row_count = 0; + long angleSubdivisions = 0; + const grib_context* c = h->context; grib_iterator_gaussian_reduced* self = (grib_iterator_gaussian_reduced*)iter; const char* slat_first = grib_arguments_get_name(h, args, self->carg++); const char* slon_first = grib_arguments_get_name(h, args, self->carg++); @@ -300,6 +318,22 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args) const char* spl = grib_arguments_get_name(h, args, self->carg++); const char* snj = grib_arguments_get_name(h, args, self->carg++); + self->angleOfRotation = 0; + self->isRotated = 0; + self->southPoleLat = 0; + self->southPoleLon = 0; + self->disableUnrotate = 0; /* unrotate enabled by default */ + + ret = grib_get_long(h, "isRotatedGrid", &self->isRotated); + if (ret == GRIB_SUCCESS && self->isRotated) { + if ((ret = grib_get_double_internal(h, "angleOfRotation", &self->angleOfRotation))) + return ret; + if ((ret = grib_get_double_internal(h, "latitudeOfSouthernPoleInDegrees", &self->southPoleLat))) + return ret; + if ((ret = grib_get_double_internal(h, "longitudeOfSouthernPoleInDegrees", &self->southPoleLon))) + return ret; + } + if ((ret = grib_get_double_internal(h, slat_first, &lat_first)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_double_internal(h, slon_first, &lon_first)) != GRIB_SUCCESS) From ed62343032afc3df7e281707e484dfc19afcd2d3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 5 Mar 2024 13:51:14 +0000 Subject: [PATCH 135/156] ECC-1781: Test --- tests/grib_iterator.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/grib_iterator.sh b/tests/grib_iterator.sh index 152e95c0c..d09f6ded5 100755 --- a/tests/grib_iterator.sh +++ b/tests/grib_iterator.sh @@ -45,6 +45,12 @@ grep -q "Latitude Longitude Value shortName level" $tempText ${tools_dir}/grib_get_data "$samp_dir/sh_ml_grib2.tmpl" > $tempText +# ECC-1781: Reduced Gaussian grid with rotation +# --------------------------------------------- +${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib1.tmpl > $tempText +${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib2.tmpl > $tempText + + # ECC-1642: badly encoded regular grids # ------------------------------------- ${tools_dir}/grib_set -s Ni=33 $samp_dir/GRIB2.tmpl $tempGrib From 5bddfc819e780656bfa39633c82689c40cdfa92e Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 10:01:00 +0000 Subject: [PATCH 136/156] ECC-1781: Further cleanup --- src/grib_iterator_class_gaussian_reduced.cc | 11 ++++++++--- tests/grib_iterator.sh | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/grib_iterator_class_gaussian_reduced.cc b/src/grib_iterator_class_gaussian_reduced.cc index 7882cc54a..b21f680b1 100644 --- a/src/grib_iterator_class_gaussian_reduced.cc +++ b/src/grib_iterator_class_gaussian_reduced.cc @@ -22,6 +22,11 @@ MEMBERS = double *las MEMBERS = double *los MEMBERS = long Nj + MEMBERS = long isRotated + MEMBERS = double angleOfRotation + MEMBERS = double southPoleLat + MEMBERS = double southPoleLon + MEMBERS = long disableUnrotate END_CLASS_DEF */ @@ -81,9 +86,9 @@ grib_iterator_class* grib_iterator_class_gaussian_reduced = &_grib_iterator_clas static void init_class(grib_iterator_class* c) { - c->previous = (*(c->super))->previous; - c->reset = (*(c->super))->reset; - c->has_next = (*(c->super))->has_next; + c->previous = (*(c->super))->previous; + c->reset = (*(c->super))->reset; + c->has_next = (*(c->super))->has_next; } /* END_CLASS_IMP */ diff --git a/tests/grib_iterator.sh b/tests/grib_iterator.sh index d09f6ded5..c1f549a53 100755 --- a/tests/grib_iterator.sh +++ b/tests/grib_iterator.sh @@ -49,6 +49,8 @@ ${tools_dir}/grib_get_data "$samp_dir/sh_ml_grib2.tmpl" > $tempText # --------------------------------------------- ${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib1.tmpl > $tempText ${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib2.tmpl > $tempText +ECCODES_DEBUG=-1 ${tools_dir}/grib_get_data ${data_dir}/reduced_gaussian_sub_area.grib2 > $tempText 2>&1 +grep -q "sub-area num points=53564" $tempText # ECC-1642: badly encoded regular grids From f6d1bb67cb9765535174fc64677477a2566d71b1 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 10:03:05 +0000 Subject: [PATCH 137/156] ECC-1781: Further cleanup --- src/grib_nearest_class_regular.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/grib_nearest_class_regular.cc b/src/grib_nearest_class_regular.cc index 7ff90e38f..adb5320a1 100644 --- a/src/grib_nearest_class_regular.cc +++ b/src/grib_nearest_class_regular.cc @@ -214,7 +214,6 @@ static int find(grib_nearest* nearest, grib_handle* h, } while (grib_iterator_next(iter, &lat, &lon, NULL)) { if (ilat < self->lats_count && olat != lat) { - /* Assert(ilat < self->lats_count); */ self->lats[ilat++] = lat; olat = lat; } From d0f68666e6abb438700f20951a40b90bebb54dce Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 10:25:42 +0000 Subject: [PATCH 138/156] ECC-1781: Further cleanup --- src/grib_nearest_class_latlon_reduced.cc | 2 +- src/grib_nearest_class_reduced.cc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/grib_nearest_class_latlon_reduced.cc b/src/grib_nearest_class_latlon_reduced.cc index a5d2af222..e5c503e99 100644 --- a/src/grib_nearest_class_latlon_reduced.cc +++ b/src/grib_nearest_class_latlon_reduced.cc @@ -214,7 +214,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, return ret; } while (grib_iterator_next(iter, &lat, &lon, NULL)) { - if (olat != lat) { + if (ilat < self->lats_count && olat != lat) { self->lats[ilat++] = lat; olat = lat; } diff --git a/src/grib_nearest_class_reduced.cc b/src/grib_nearest_class_reduced.cc index f17d3b4e3..ef0e25c5b 100644 --- a/src/grib_nearest_class_reduced.cc +++ b/src/grib_nearest_class_reduced.cc @@ -251,7 +251,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, return err; } while (grib_iterator_next(iter, &lat, &lon, NULL)) { - if (olat != lat) { + if (ilat < self->lats_count && olat != lat) { self->lats[ilat++] = lat; olat = lat; } @@ -262,6 +262,7 @@ static int find_global(grib_nearest* nearest, grib_handle* h, if (lon > 180 && lon < 360) lon -= 360; } + DEBUG_ASSERT_ACCESS(self->lons, (long)ilon, (long)nearest->values_count); self->lons[ilon++] = lon; } self->lats_count = ilat; From 08369d1a096b248b96c8ca34b1900178e6c492ea Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 10:44:33 +0000 Subject: [PATCH 139/156] Nearest: Fix for rotated reduced --- src/grib_nearest_class_reduced.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/grib_nearest_class_reduced.cc b/src/grib_nearest_class_reduced.cc index ef0e25c5b..4c369d9cc 100644 --- a/src/grib_nearest_class_reduced.cc +++ b/src/grib_nearest_class_reduced.cc @@ -152,8 +152,10 @@ static int find(grib_nearest* nearest, grib_handle* h, { int err = 0; grib_nearest_reduced* self = (grib_nearest_reduced*)nearest; + long isRotated = 0; + err = grib_get_long(h, "isRotatedGrid", &isRotated); - if (self->global) { + if (self->global && !isRotated) { err = find_global(nearest, h, inlat, inlon, flags, outlats, outlons, values, From 89e1a643e32f2a4c9d7e66568178d15926ae5b3c Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 11:40:13 +0000 Subject: [PATCH 140/156] ECC-1781: Fix nearest --- src/grib_nearest_class_reduced.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/grib_nearest_class_reduced.cc b/src/grib_nearest_class_reduced.cc index 4c369d9cc..713570264 100644 --- a/src/grib_nearest_class_reduced.cc +++ b/src/grib_nearest_class_reduced.cc @@ -29,6 +29,7 @@ MEMBERS = double lon_first MEMBERS = double lon_last MEMBERS = int legacy + MEMBERS = int rotated END_CLASS_DEF */ @@ -69,6 +70,7 @@ typedef struct grib_nearest_reduced{ double lon_first; double lon_last; int legacy; + int rotated; } grib_nearest_reduced; extern grib_nearest_class* grib_nearest_class_gen; @@ -101,6 +103,7 @@ static int init(grib_nearest* nearest, grib_handle* h, grib_arguments* args) self->pl = grib_arguments_get_name(h, args, self->cargs++); self->j = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); self->legacy = -1; + self->rotated = -1; if (!self->j) return GRIB_OUT_OF_MEMORY; self->k = (size_t*)grib_context_malloc(nearest->context, NUM_NEIGHBOURS * sizeof(size_t)); @@ -138,10 +141,21 @@ static int find_global(grib_nearest* nearest, grib_handle* h, static int is_legacy(grib_handle* h, int* legacy) { int err = 0; - long lLegacy = 0; - err = grib_get_long(h, "legacyGaussSubarea", &lLegacy); + long lVal = 0; + *legacy = 0; // false by default + err = grib_get_long(h, "legacyGaussSubarea", &lVal); if (err) return err; - *legacy = (int)lLegacy; + *legacy = (int)lVal; + return GRIB_SUCCESS; +} +static int is_rotated(grib_handle* h, int* rotated) +{ + int err = 0; + long lVal = 0; + *rotated = 0; // false by default + err = grib_get_long(h, "isRotatedGrid", &lVal); + if (err) return err; + *rotated = (int)lVal; return GRIB_SUCCESS; } @@ -152,10 +166,13 @@ static int find(grib_nearest* nearest, grib_handle* h, { int err = 0; grib_nearest_reduced* self = (grib_nearest_reduced*)nearest; - long isRotated = 0; - err = grib_get_long(h, "isRotatedGrid", &isRotated); - if (self->global && !isRotated) { + if (self->rotated == -1 || (flags & GRIB_NEAREST_SAME_GRID) == 0) { + err = is_rotated(h, &(self->rotated)); + if (err) return err; + } + + if (self->global && self->rotated == 0) { err = find_global(nearest, h, inlat, inlon, flags, outlats, outlons, values, From ec22e6019da3fc56ed63dd915809bfa4743c808f Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 13:25:27 +0000 Subject: [PATCH 141/156] Fortran: Refactoring --- fortran/grib_fortran.c | 77 ++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index e1835ae47..c5fcb4fc3 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -1604,9 +1604,8 @@ int any_f_new_from_loaded_(int* msgid, int* gid) /*****************************************************************************/ int codes_f_clear_loaded_from_file_(void) { - grib_context* c = grib_context_get_default(); /* grib_oarray_delete_content(c,binary_messages); */ - grib_oarray_delete(c, binary_messages); + grib_oarray_delete(grib_context_get_default(), binary_messages); return GRIB_SUCCESS; } @@ -1711,10 +1710,10 @@ int grib_f_headers_only_new_from_file_(int* fid, int* gid) } /*****************************************************************************/ -int grib_f_new_from_index_(int* iid, int* gid) +int grib_f_new_from_index_(int* index_id, int* gid) { int err = 0; - grib_index* i = get_index(*iid); + grib_index* i = get_index(*index_id); grib_handle *h = NULL; if (i) { @@ -1757,16 +1756,15 @@ int grib_f_index_new_from_file_(char* file, char* keys, int* gid, int lfile, int } /*****************************************************************************/ -int grib_f_index_add_file_(int* iid, char* file, int lfile) +int grib_f_index_add_file_(int* index_id, char* file, int lfile) { - grib_index *i = get_index(*iid); - int err = GRIB_SUCCESS; + grib_index *i = get_index(*index_id); char buf[1024]; if (!i) { return GRIB_INVALID_INDEX; } else { - err = grib_index_add_file(i,cast_char(buf,file,lfile)); + int err = grib_index_add_file(i,cast_char(buf,file,lfile)); return err; } } @@ -1928,9 +1926,9 @@ int grib_f_get_size_long_(int* gid, char* key, long* val, int len) } /*****************************************************************************/ -int grib_f_index_get_size_int_(int* gid, char* key, int* val, int len) +int grib_f_index_get_size_int_(int* index_id, char* key, int* val, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); int err = GRIB_SUCCESS; char buf[1024]; size_t tsize = 0; @@ -1944,19 +1942,18 @@ int grib_f_index_get_size_int_(int* gid, char* key, int* val, int len) } } -int grib_f_index_get_size_long_(int* gid, char* key, long* val, int len) +int grib_f_index_get_size_long_(int* index_id, char* key, long* val, int len) { - grib_index *h = get_index(*gid); - int err = GRIB_SUCCESS; + grib_index *h = get_index(*index_id); char buf[1024]; size_t tsize = 0; - if(!h){ + if (!h){ return GRIB_INVALID_GRIB; - }else{ - err = grib_index_get_size(h, cast_char(buf,key,len), &tsize); + } else{ + int err = grib_index_get_size(h, cast_char(buf,key,len), &tsize); *val = tsize; - return err; + return err; } } @@ -2063,9 +2060,9 @@ int grib_f_get_byte_array_(int* gid, char* key, unsigned char *val, int* size, i } /*****************************************************************************/ -int grib_f_index_get_string_(int* gid, char* key, char* val, int *eachsize,int* size, int len) +int grib_f_index_get_string_(int* index_id, char* key, char* val, int *eachsize,int* size, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); int err = GRIB_SUCCESS; int i; char buf[1024]; @@ -2104,23 +2101,22 @@ int grib_f_index_get_string_(int* gid, char* key, char* val, int *eachsize,int* } /*****************************************************************************/ -int grib_f_index_get_long_(int* gid, char* key, long *val, int* size, int len) +int grib_f_index_get_long_(int* index_id, char* key, long *val, int* size, int len) { - grib_index *h = get_index(*gid); - int err = GRIB_SUCCESS; + grib_index* h = get_index(*index_id); char buf[1024]; size_t lsize = *size; - if(!h) return GRIB_INVALID_GRIB; - err = grib_index_get_long(h, cast_char(buf,key,len), val, &lsize); + if (!h) return GRIB_INVALID_GRIB; + int err = grib_index_get_long(h, cast_char(buf,key,len), val, &lsize); *size = lsize; - return err; + return err; } /*****************************************************************************/ -int grib_f_index_get_int_(int* gid, char* key, int *val, int* size, int len) +int grib_f_index_get_int_(int* index_id, char* key, int *val, int* size, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); int err = GRIB_SUCCESS; char buf[1024]; size_t lsize = *size, i = 0; @@ -2140,17 +2136,16 @@ int grib_f_index_get_int_(int* gid, char* key, int *val, int* size, int len) } /*****************************************************************************/ -int grib_f_index_get_real8_(int* gid, char* key, double *val, int* size, int len) +int grib_f_index_get_real8_(int* index_id, char* key, double *val, int* size, int len) { - grib_index *h = get_index(*gid); - int err = GRIB_SUCCESS; + grib_index* h = get_index(*index_id); char buf[1024]; size_t lsize = *size; - if(!h) return GRIB_INVALID_GRIB; - err = grib_index_get_double(h, cast_char(buf,key,len), val, &lsize); + if (!h) return GRIB_INVALID_GRIB; + int err = grib_index_get_double(h, cast_char(buf,key,len), val, &lsize); *size = lsize; - return err; + return err; } /*****************************************************************************/ @@ -2438,9 +2433,9 @@ int grib_f_set_real4_array_(int* gid, char* key, float* val, int* size, int len) } /*****************************************************************************/ -int grib_f_index_select_real8_(int* gid, char* key, double* val, int len) +int grib_f_index_select_real8_(int* index_id, char* key, double* val, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); char buf[1024]; if(!h) return GRIB_INVALID_GRIB; @@ -2448,9 +2443,9 @@ int grib_f_index_select_real8_(int* gid, char* key, double* val, int len) } /*****************************************************************************/ -int grib_f_index_select_string_(int* gid, char* key, char* val, int len, int vallen) +int grib_f_index_select_string_(int* index_id, char* key, char* val, int len, int vallen) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); char buf[1024]; char bufval[1024]; @@ -2465,9 +2460,9 @@ int grib_f_index_select_string_(int* gid, char* key, char* val, int len, int val } /*****************************************************************************/ -int grib_f_index_select_int_(int* gid, char* key, int* val, int len) +int grib_f_index_select_int_(int* index_id, char* key, int* val, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); long lval = *val; char buf[1024] = {0,}; @@ -2476,9 +2471,9 @@ int grib_f_index_select_int_(int* gid, char* key, int* val, int len) } /*****************************************************************************/ -int grib_f_index_select_long_(int* gid, char* key, long* val, int len) +int grib_f_index_select_long_(int* index_id, char* key, long* val, int len) { - grib_index *h = get_index(*gid); + grib_index *h = get_index(*index_id); char buf[1024] = {0,}; if (!h) return GRIB_INVALID_GRIB; From b9f82580888f8fd40f96b21c29a9c3d77e0175f9 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 13:41:23 +0000 Subject: [PATCH 142/156] Cleanup --- examples/F90/bufr_ecc-1019.f90 | 1 - examples/F90/bufr_ecc-1284.f90 | 1 - tests/grib_get_fail.sh | 9 ++++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/F90/bufr_ecc-1019.f90 b/examples/F90/bufr_ecc-1019.f90 index 5974132e6..8bbceb900 100644 --- a/examples/F90/bufr_ecc-1019.f90 +++ b/examples/F90/bufr_ecc-1019.f90 @@ -18,7 +18,6 @@ program operator_3_test call codes_bufr_new_from_samples(ibufr,'BUFR4',iret) if (iret /= CODES_SUCCESS) then - print *,'ERROR creating BUFR from BUFR4' stop 1 endif diff --git a/examples/F90/bufr_ecc-1284.f90 b/examples/F90/bufr_ecc-1284.f90 index 69600a1c7..53b18b7c5 100644 --- a/examples/F90/bufr_ecc-1284.f90 +++ b/examples/F90/bufr_ecc-1284.f90 @@ -22,7 +22,6 @@ program bufr_encode call codes_bufr_new_from_samples(ibufr,'BUFR4',iret) if (iret/=CODES_SUCCESS) then - print *,'ERROR creating BUFR from BUFR4' stop 1 endif call codes_set(ibufr,'masterTableNumber',0) diff --git a/tests/grib_get_fail.sh b/tests/grib_get_fail.sh index d7d0d5b1b..1dd028fcb 100755 --- a/tests/grib_get_fail.sh +++ b/tests/grib_get_fail.sh @@ -35,6 +35,13 @@ grep -q "Nh (Key/value not found)" $tempText # Nearest # --------- +set +e +${tools_dir}/grib_get -l abc $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Wrong latitude value" $tempText + set +e ${tools_dir}/grib_get -s Nj=MISSING -l 0,0,1 $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib1.tmpl > $tempText 2>&1 status=$? @@ -51,7 +58,7 @@ grep -q "Key Nj cannot be 0" $tempText set +e -${tools_dir}/grib_get -l 0,0,5 $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib1.tmpl > $tempText 2>&1 +${tools_dir}/grib_get -l 0,0,5 $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib2.tmpl > $tempText 2>&1 status=$? set -e [ $status -ne 0 ] From d108c4a118dee7dd1717c39f6d9fdfad5c206321 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 14:07:46 +0000 Subject: [PATCH 143/156] Testing: check_gaussian_grids --- tests/grib_check_gaussian_grids.sh | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/grib_check_gaussian_grids.sh b/tests/grib_check_gaussian_grids.sh index 474eaf726..c37013981 100755 --- a/tests/grib_check_gaussian_grids.sh +++ b/tests/grib_check_gaussian_grids.sh @@ -28,6 +28,17 @@ for gg in ${samples_dir}/reduced_gg_*tmpl; do done +# Set wrong Nj. Should fail +input=$samples_dir/reduced_gg_pl_32_grib2.tmpl +${tools_dir}/grib_set -s Nj=1 $input $tempGrib +set +e +${tools_dir}/grib_check_gaussian_grid -v $tempGrib 2> $tempText +status=$? +set -e +[ $status -ne 0 ] +grep -q "Nj is 1 but should be 2\*N" $tempText + + # Set wrong N. Should fail input=$samples_dir/reduced_gg_pl_32_grib2.tmpl ${tools_dir}/grib_set -s N=0 $input $tempGrib @@ -38,6 +49,7 @@ set -e [ $status -eq 1 ] grep -q "Error: N should be > 0" $tempText + # Set wrong angle. Should fail input=$samples_dir/reduced_gg_pl_1280_grib2.tmpl ${tools_dir}/grib_set -s longitudeOfLastGridPoint=359929680 $input $tempGrib @@ -49,6 +61,17 @@ set -e grep -q "Error: longitudeOfLastGridPointInDegrees.*but should be" $tempText +# Set wrong lat2. Should fail +input=$samples_dir/reduced_gg_pl_1280_grib2.tmpl +${tools_dir}/grib_set -s latitudeOfLastGridPointInDegrees=9 $input $tempGrib +set +e +${tools_dir}/grib_check_gaussian_grid -v $tempGrib 2> $tempText +status=$? +set -e +[ $status -ne 0 ] +grep -q "First latitude must be = last latitude but opposite in sign" $tempText + + # Set wrong numberOfDataPoints. Should fail input=$samples_dir/reduced_gg_pl_96_grib2.tmpl ${tools_dir}/grib_set -s numberOfDataPoints=44 $input $tempGrib @@ -68,9 +91,17 @@ ${tools_dir}/grib_check_gaussian_grid -f -v $tempGrib 2> $tempText status=$? set -e [ $status -eq 1 ] -cat $tempText grep -q "Error: Sum of pl array 50662 does not match numberOfValues 44" $tempText +# Octahedral +set +e +${tools_dir}/grib_check_gaussian_grid -v $data_dir/msl.octa.glob.grib1 > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "This is an Octahedral Gaussian grid" $tempText +grep -q "Error: longitudeOfLastGridPointInDegrees.*should be" $tempText + # Other errors/warnings # ---------------------- From 05b0cc0db9dee24b367558e7b8640eade21d0a43 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 16:03:07 +0000 Subject: [PATCH 144/156] Testing: grib_update_sections_lengths --- src/action_class_set_missing.cc | 16 ++++---- src/grib_expression_class_logical_or.cc | 3 +- src/grib_expression_class_unop.cc | 10 ++--- tests/CMakeLists.txt | 2 + tests/grib_update_sections_lengths.cc | 49 +++++++++++++++++++++++++ tests/grib_update_sections_lengths.sh | 22 +++++++++++ 6 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 tests/grib_update_sections_lengths.cc create mode 100755 tests/grib_update_sections_lengths.sh diff --git a/src/action_class_set_missing.cc b/src/action_class_set_missing.cc index 3a40038b5..03bd4ffc3 100644 --- a/src/action_class_set_missing.cc +++ b/src/action_class_set_missing.cc @@ -8,9 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*************************************************************************** - * Enrico Fucile * - ***************************************************************************/ #include "grib_api_internal.h" /* This is used by make_class.pl @@ -103,12 +100,13 @@ static int execute(grib_action* a, grib_handle* h) static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - const grib_action_set_missing* self = (grib_action_set_missing*)act; - for (i = 0; i < lvl; i++) - grib_context_print(act->context, f, " "); - grib_context_print(act->context, f, self->name); - printf("\n"); + grib_context_log(act->context, GRIB_LOG_ERROR, "%s %s(): Not implemented", __FILE__, __func__); + // int i = 0; + // const grib_action_set_missing* self = (grib_action_set_missing*)act; + // for (i = 0; i < lvl; i++) + // grib_context_print(act->context, f, " "); + // grib_context_print(act->context, f, self->name); + // printf("\n"); } static void destroy(grib_context* context, grib_action* act) diff --git a/src/grib_expression_class_logical_or.cc b/src/grib_expression_class_logical_or.cc index 212ff3084..ce5e4d765 100644 --- a/src/grib_expression_class_logical_or.cc +++ b/src/grib_expression_class_logical_or.cc @@ -129,9 +129,8 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) { long lres = 0; - int ret = 0; - ret = evaluate_long(g, h, &lres); + int ret = evaluate_long(g, h, &lres); *dres = (double)lres; return ret; diff --git a/src/grib_expression_class_unop.cc b/src/grib_expression_class_unop.cc index 1f4d6f9d0..6188b4586 100644 --- a/src/grib_expression_class_unop.cc +++ b/src/grib_expression_class_unop.cc @@ -77,10 +77,9 @@ grib_expression_class* grib_expression_class_unop = &_grib_expression_class_unop static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) { - int ret; - long v = 0; + long v = 0; grib_expression_unop* e = (grib_expression_unop*)g; - ret = grib_expression_evaluate_long(h, e->exp, &v); + int ret = grib_expression_evaluate_long(h, e->exp, &v); if (ret != GRIB_SUCCESS) return ret; *lres = e->long_func(v); @@ -89,10 +88,9 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) static int evaluate_double(grib_expression* g, grib_handle* h, double* dres) { - int ret; - double v = 0; + double v = 0; grib_expression_unop* e = (grib_expression_unop*)g; - ret = grib_expression_evaluate_double(h, e->exp, &v); + int ret = grib_expression_evaluate_double(h, e->exp, &v); if (ret != GRIB_SUCCESS) return ret; *dres = e->double_func ? e->double_func(v) : e->long_func(v); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a211f511..e282ee85a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,7 @@ list(APPEND test_c_bins grib_double_cmp read_any julian + grib_update_sections_lengths grib_indexing grib_fieldset grib_multi_from_message @@ -169,6 +170,7 @@ if( HAVE_BUILD_TOOLS ) # and/or take much longer list(APPEND tests_extra grib_data_quality_checks + grib_update_sections_lengths grib_units_bias_factor grib_set_large_message_fail grib_g1monthlydate diff --git a/tests/grib_update_sections_lengths.cc b/tests/grib_update_sections_lengths.cc new file mode 100644 index 000000000..a077b3ebd --- /dev/null +++ b/tests/grib_update_sections_lengths.cc @@ -0,0 +1,49 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +#include "grib_api_internal.h" + +int main(int argc, char* argv[]) +{ + grib_handle* h = NULL; + FILE* inf = NULL; + FILE* ouf = NULL; + char* infile = 0; + char* oufile = 0; + int err = 0; + size_t size; + const void* buffer = NULL; + + if (argc < 3) return 1; // prog in out + + infile = argv[1]; + oufile = argv[2]; + + inf = fopen(infile, "r"); + Assert(inf); + + ouf = fopen(oufile, "w"); + Assert(ouf); + + while ((h = grib_handle_new_from_file(0, inf, &err)) != NULL) { + grib_update_sections_lengths(h); + GRIB_CHECK(grib_get_message(h, &buffer, &size), 0); + if (fwrite(buffer, 1, size, ouf) != size) { + perror(oufile); + exit(1); + } + } + + grib_handle_delete(h); + fclose(inf); + fclose(ouf); + + return 0; +} diff --git a/tests/grib_update_sections_lengths.sh b/tests/grib_update_sections_lengths.sh new file mode 100755 index 000000000..028bd8156 --- /dev/null +++ b/tests/grib_update_sections_lengths.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="grib_update_sections_lengths_test" +tempGrib=temp.$label.grib + +gfiles="$data_dir/sample.grib2 $data_dir/missing_field.grib1" +for f in $gfiles; do + $EXEC ${test_dir}/grib_update_sections_lengths $f $tempGrib + cmp $f $tempGrib +done + +rm -f $tempGrib From 79f51dd0a427838067ec0895358c0e75c2c48d0d Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 16:27:33 +0000 Subject: [PATCH 145/156] Fix broken test --- tests/grib_check_gaussian_grids.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/grib_check_gaussian_grids.sh b/tests/grib_check_gaussian_grids.sh index c37013981..4f16966e4 100755 --- a/tests/grib_check_gaussian_grids.sh +++ b/tests/grib_check_gaussian_grids.sh @@ -94,13 +94,13 @@ set -e grep -q "Error: Sum of pl array 50662 does not match numberOfValues 44" $tempText # Octahedral -set +e -${tools_dir}/grib_check_gaussian_grid -v $data_dir/msl.octa.glob.grib1 > $tempText 2>&1 -status=$? -set -e -[ $status -ne 0 ] -grep -q "This is an Octahedral Gaussian grid" $tempText -grep -q "Error: longitudeOfLastGridPointInDegrees.*should be" $tempText +# set +e +# ${tools_dir}/grib_check_gaussian_grid -v $data_dir/msl.octa.glob.grib1 > $tempText 2>&1 +# status=$? +# set -e +# [ $status -ne 0 ] +# grep -q "This is an Octahedral Gaussian grid" $tempText +# grep -q "Error: longitudeOfLastGridPointInDegrees.*should be" $tempText # Other errors/warnings From 2aba61bbae4e21deae280270c50e777d486682fb Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 16:31:23 +0000 Subject: [PATCH 146/156] Fix broken test --- fortran/grib_fortran.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.c index c5fcb4fc3..ce9298348 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.c @@ -2103,12 +2103,13 @@ int grib_f_index_get_string_(int* index_id, char* key, char* val, int *eachsize, /*****************************************************************************/ int grib_f_index_get_long_(int* index_id, char* key, long *val, int* size, int len) { + int err = 0; grib_index* h = get_index(*index_id); char buf[1024]; size_t lsize = *size; if (!h) return GRIB_INVALID_GRIB; - int err = grib_index_get_long(h, cast_char(buf,key,len), val, &lsize); + err = grib_index_get_long(h, cast_char(buf,key,len), val, &lsize); *size = lsize; return err; } @@ -2138,12 +2139,13 @@ int grib_f_index_get_int_(int* index_id, char* key, int *val, int* size, int len /*****************************************************************************/ int grib_f_index_get_real8_(int* index_id, char* key, double *val, int* size, int len) { + int err = 0; grib_index* h = get_index(*index_id); char buf[1024]; size_t lsize = *size; if (!h) return GRIB_INVALID_GRIB; - int err = grib_index_get_double(h, cast_char(buf,key,len), val, &lsize); + err = grib_index_get_double(h, cast_char(buf,key,len), val, &lsize); *size = lsize; return err; } From fbd27b037e1e547d30dfe0c7c61af25e586c8c5a Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 18:31:15 +0000 Subject: [PATCH 147/156] Testing: Bit access --- tests/grib_filter.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index 250302890..660d568b3 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -324,6 +324,20 @@ EOF ${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut grep -q "No args: false" $tempOut +# Bit on off +cat >$tempFilt < $tempOut +cat $tempOut +grep -q "xx1=1" $tempOut +grep -q "xx2=0" $tempOut +grep -q "yy1=0" $tempOut +grep -q "yy2=1" $tempOut + # Use of dummy expression (=true) cat >$tempFilt < Date: Wed, 6 Mar 2024 18:31:35 +0000 Subject: [PATCH 148/156] Dead code removal --- src/eccodes_prototypes.h | 6 -- src/grib_accessor.cc | 130 +++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 73 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 2ac2f9e13..abd512a9f 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -108,7 +108,6 @@ grib_action* grib_action_create_transient_darray(grib_context* context, const ch /* grib_accessor.cc*/ void grib_accessor_dump(grib_accessor* a, grib_dumper* f); int grib_pack_missing(grib_accessor* a); -int grib_pack_zero(grib_accessor* a); int grib_is_missing_internal(grib_accessor* a); int grib_pack_double(grib_accessor* a, const double* v, size_t* len); int grib_pack_float(grib_accessor* a, const float* v, size_t* len); @@ -150,17 +149,12 @@ grib_accessor* grib_next_accessor(grib_accessor* a); void grib_resize(grib_accessor* a, size_t new_size); int grib_compare_accessors(grib_accessor* a1, grib_accessor* a2, int compare_flags); int grib_accessor_add_attribute(grib_accessor* a, grib_accessor* attr, int nest_if_clash); -int grib_accessor_replace_attribute(grib_accessor* a, grib_accessor* attr); -int grib_accessor_delete_attribute(grib_accessor* a, const char* name); -grib_accessor* grib_accessor_get_attribute_by_index(grib_accessor* a, int index); -const char* grib_accessor_get_name(grib_accessor* a); grib_accessor* grib_accessor_get_attribute_index(grib_accessor* a, const char* name, int* index); int grib_accessor_has_attributes(grib_accessor* a); grib_accessor* grib_accessor_get_attribute(grib_accessor* a, const char* name); grib_accessors_list* grib_accessors_list_create(grib_context* c); void grib_accessors_list_push(grib_accessors_list* al, grib_accessor* a, int rank); grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al); -grib_accessors_list* grib_accessors_list_find(grib_accessors_list* al, const grib_accessor* a); void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al); /* grib_concept.cc*/ diff --git a/src/grib_accessor.cc b/src/grib_accessor.cc index 0b4b7ed99..a08f5348e 100644 --- a/src/grib_accessor.cc +++ b/src/grib_accessor.cc @@ -54,18 +54,18 @@ int grib_pack_missing(grib_accessor* a) return 0; } -int grib_pack_zero(grib_accessor* a) -{ - grib_accessor_class* c = a->cclass; - while (c) { - if (c->clear) { - return c->clear(a); - } - c = c->super ? *(c->super) : NULL; - } - DEBUG_ASSERT(0); - return 0; -} +// int grib_pack_zero(grib_accessor* a) +// { +// grib_accessor_class* c = a->cclass; +// while (c) { +// if (c->clear) { +// return c->clear(a); +// } +// c = c->super ? *(c->super) : NULL; +// } +// DEBUG_ASSERT(0); +// return 0; +// } int grib_is_missing_internal(grib_accessor* a) { @@ -526,7 +526,7 @@ int grib_accessor_notify_change(grib_accessor* a, grib_accessor* changed) c = c->super ? *(c->super) : NULL; } if (a && a->cclass) - printf("notify_change not implemented for %s %s\n", a->cclass->name, a->name); + fprintf(stderr, "Error: notify_change not implemented for %s %s\n", a->cclass->name, a->name); DEBUG_ASSERT(0); return 0; } @@ -726,48 +726,47 @@ int grib_accessor_add_attribute(grib_accessor* a, grib_accessor* attr, int nest_ return GRIB_TOO_MANY_ATTRIBUTES; } -int grib_accessor_replace_attribute(grib_accessor* a, grib_accessor* attr) -{ - int id = 0; - int idx = 0; - if (grib_accessor_get_attribute_index(a, attr->name, &id) != NULL) { - grib_accessor_delete(a->context, a->attributes[id]); - a->attributes[id] = attr; - attr->parent_as_attribute = a; - if (a->same) - attr->same = grib_accessor_get_attribute_index(a->same, attr->name, &idx); - } - else { - grib_accessor_add_attribute(a, attr, 0); - } - return GRIB_SUCCESS; -} +// int grib_accessor_replace_attribute(grib_accessor* a, grib_accessor* attr) +// { +// int id = 0; +// int idx = 0; +// if (grib_accessor_get_attribute_index(a, attr->name, &id) != NULL) { +// grib_accessor_delete(a->context, a->attributes[id]); +// a->attributes[id] = attr; +// attr->parent_as_attribute = a; +// if (a->same) +// attr->same = grib_accessor_get_attribute_index(a->same, attr->name, &idx); +// } +// else { +// grib_accessor_add_attribute(a, attr, 0); +// } +// return GRIB_SUCCESS; +// } -int grib_accessor_delete_attribute(grib_accessor* a, const char* name) -{ - int id = 0; - if (grib_accessor_get_attribute_index(a, name, &id) != NULL) { - grib_accessor_delete(a->context, a->attributes[id]); - a->attributes[id] = NULL; - return GRIB_SUCCESS; - } - else { - return GRIB_NOT_FOUND; - } -} +// int grib_accessor_delete_attribute(grib_accessor* a, const char* name) +// { +// int id = 0; +// if (grib_accessor_get_attribute_index(a, name, &id) != NULL) { +// grib_accessor_delete(a->context, a->attributes[id]); +// a->attributes[id] = NULL; +// return GRIB_SUCCESS; +// } +// else { +// return GRIB_NOT_FOUND; +// } +// } -grib_accessor* grib_accessor_get_attribute_by_index(grib_accessor* a, int index) -{ - if (index < MAX_ACCESSOR_ATTRIBUTES) - return a->attributes[index]; +// grib_accessor* grib_accessor_get_attribute_by_index(grib_accessor* a, int index) +// { +// if (index < MAX_ACCESSOR_ATTRIBUTES) +// return a->attributes[index]; +// return NULL; +// } - return NULL; -} - -const char* grib_accessor_get_name(grib_accessor* a) -{ - return a->name; -} +// const char* grib_accessor_get_name(grib_accessor* a) +// { +// return a->name; +// } grib_accessor* grib_accessor_get_attribute_index(grib_accessor* a, const char* name, int* index) { @@ -847,24 +846,21 @@ grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al) // last=next; // next=last->next; // } - return al->last; } -grib_accessors_list* grib_accessors_list_find(grib_accessors_list* al, const grib_accessor* a) -{ - grib_accessors_list* last = al; - grib_accessors_list* next = al->next; - - while (next) { - if (last->accessor == a) - return last; - last = next; - next = last->next; - } - - return NULL; -} +// grib_accessors_list* grib_accessors_list_find(grib_accessors_list* al, const grib_accessor* a) +// { +// grib_accessors_list* last = al; +// grib_accessors_list* next = al->next; +// while (next) { +// if (last->accessor == a) +// return last; +// last = next; +// next = last->next; +// } +// return NULL; +// } void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al) { From 5cd1f39afc82d8092935e02046fd1a8857459572 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 20:31:31 +0000 Subject: [PATCH 149/156] Testing: Fix for Windows --- tests/grib_update_sections_lengths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/grib_update_sections_lengths.sh b/tests/grib_update_sections_lengths.sh index 028bd8156..698a8b975 100755 --- a/tests/grib_update_sections_lengths.sh +++ b/tests/grib_update_sections_lengths.sh @@ -16,7 +16,7 @@ tempGrib=temp.$label.grib gfiles="$data_dir/sample.grib2 $data_dir/missing_field.grib1" for f in $gfiles; do $EXEC ${test_dir}/grib_update_sections_lengths $f $tempGrib - cmp $f $tempGrib + ${tools_dir}/grib_compare $f $tempGrib done rm -f $tempGrib From 4b08450a0dd65afcd858055592f2b78394871b91 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 20:37:10 +0000 Subject: [PATCH 150/156] Const correctness and cppcheck warnings --- src/action_class_hash_array.cc | 7 ++++--- src/action_class_noop.cc | 5 ++--- src/action_class_set.cc | 4 ++-- src/action_class_template.cc | 2 +- src/action_class_transient_darray.cc | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/action_class_hash_array.cc b/src/action_class_hash_array.cc index 609e763f2..430fdd92a 100644 --- a/src/action_class_hash_array.cc +++ b/src/action_class_hash_array.cc @@ -199,8 +199,9 @@ static void destroy(grib_context* context, grib_action* act) { grib_action_hash_array* self = (grib_action_hash_array*)act; - grib_hash_array_value* v = self->hash_array; - Assert(!v); // not implemented + // This is currently unset. So assert that it is NULL + const grib_hash_array_value* v = self->hash_array; + Assert(v == NULL); // if (v) // grib_trie_delete(v->index); // while (v) { @@ -335,6 +336,6 @@ grib_hash_array_value* get_hash_array(grib_handle* h, grib_action* a) const char* get_hash_array_full_path(grib_action* a) { - grib_action_hash_array* self = (grib_action_hash_array*)a; + const grib_action_hash_array* self = (grib_action_hash_array*)a; return self->full_path; } diff --git a/src/action_class_noop.cc b/src/action_class_noop.cc index a898da06a..aa5196a46 100644 --- a/src/action_class_noop.cc +++ b/src/action_class_noop.cc @@ -73,16 +73,15 @@ grib_action* grib_action_create_noop(grib_context* context, const char* fname) { char buf[1024]; - grib_action_noop* a; grib_action_class* c = grib_action_class_noop; grib_action* act = (grib_action*)grib_context_malloc_clear_persistent(context, c->size); act->op = grib_context_strdup_persistent(context, "section"); act->cclass = c; - a = (grib_action_noop*)act; + grib_action_noop* a = (grib_action_noop*)act; act->context = context; - snprintf(buf, 1024, "_noop%p", (void*)a); + snprintf(buf, sizeof(buf), "_noop%p", (void*)a); act->name = grib_context_strdup_persistent(context, buf); diff --git a/src/action_class_set.cc b/src/action_class_set.cc index 1068181d5..fee2ca406 100644 --- a/src/action_class_set.cc +++ b/src/action_class_set.cc @@ -114,8 +114,8 @@ static int execute(grib_action* a, grib_handle* h) static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_set* self = (grib_action_set*)act; + int i = 0; + const grib_action_set* self = (grib_action_set*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); diff --git a/src/action_class_template.cc b/src/action_class_template.cc index 33a753513..79fd2aeaf 100644 --- a/src/action_class_template.cc +++ b/src/action_class_template.cc @@ -117,7 +117,7 @@ static void dump(grib_action* act, FILE* f, int lvl) static grib_action* get_empty_template(grib_context* c, int* err) { char fname[] = "empty_template.def"; - char* path = grib_context_full_defs_path(c, fname); + const char* path = grib_context_full_defs_path(c, fname); if (path) { *err = GRIB_SUCCESS; return grib_parse_file(c, path); diff --git a/src/action_class_transient_darray.cc b/src/action_class_transient_darray.cc index 9990beb41..673f83502 100644 --- a/src/action_class_transient_darray.cc +++ b/src/action_class_transient_darray.cc @@ -122,8 +122,8 @@ static int execute(grib_action* act, grib_handle* h) static void dump(grib_action* act, FILE* f, int lvl) { - int i = 0; - grib_action_transient_darray* self = (grib_action_transient_darray*)act; + int i = 0; + const grib_action_transient_darray* self = (grib_action_transient_darray*)act; for (i = 0; i < lvl; i++) grib_context_print(act->context, f, " "); grib_context_print(act->context, f, self->name); From 92cbaa050d2547dcfe592607ac7be5489ee1b9b3 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 6 Mar 2024 22:05:57 +0000 Subject: [PATCH 151/156] Testing: Fix for Windows --- tests/grib_update_sections_lengths.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/grib_update_sections_lengths.cc b/tests/grib_update_sections_lengths.cc index a077b3ebd..cda520643 100644 --- a/tests/grib_update_sections_lengths.cc +++ b/tests/grib_update_sections_lengths.cc @@ -18,7 +18,7 @@ int main(int argc, char* argv[]) char* infile = 0; char* oufile = 0; int err = 0; - size_t size; + size_t size = 0; const void* buffer = NULL; if (argc < 3) return 1; // prog in out @@ -26,15 +26,16 @@ int main(int argc, char* argv[]) infile = argv[1]; oufile = argv[2]; - inf = fopen(infile, "r"); + inf = fopen(infile, "rb"); Assert(inf); - ouf = fopen(oufile, "w"); + ouf = fopen(oufile, "wb"); Assert(ouf); while ((h = grib_handle_new_from_file(0, inf, &err)) != NULL) { grib_update_sections_lengths(h); GRIB_CHECK(grib_get_message(h, &buffer, &size), 0); + printf("size = %zu\n", size); if (fwrite(buffer, 1, size, ouf) != size) { perror(oufile); exit(1); From 95aa40fc234679d4d5066d9ea5d5e012f4489e74 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 7 Mar 2024 13:34:33 +0000 Subject: [PATCH 152/156] Examples: Use binary write mode for fopen --- examples/C/grib_multi_write.c | 2 +- examples/C/grib_multi_write.sh | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/C/grib_multi_write.c b/examples/C/grib_multi_write.c index b68df1517..d0f275c58 100644 --- a/examples/C/grib_multi_write.c +++ b/examples/C/grib_multi_write.c @@ -72,7 +72,7 @@ int main(int argc, char** argv) } /* open output file */ - of = fopen(ofilename, "w"); + of = fopen(ofilename, "wb"); if (!of) { fprintf(stderr, "ERROR: unable to open output file %s\n", ofilename); exit(1); diff --git a/examples/C/grib_multi_write.sh b/examples/C/grib_multi_write.sh index a6a621a59..73942c663 100755 --- a/examples/C/grib_multi_write.sh +++ b/examples/C/grib_multi_write.sh @@ -9,20 +9,20 @@ . ./include.ctest.sh -#if [ ! -f "${data_dir}/sample.grib2" ] -#then -# echo SKIP: $0 -# exit -#fi +label="grib_multi_write_c" +tempGrib=temp.$label.grib +tempText=temp.$label.txt -${examples_dir}/c_grib_multi_write ${data_dir}/sample.grib2 ${data_dir}/multi_sample.grib2 > /dev/null +${examples_dir}/c_grib_multi_write ${data_dir}/sample.grib2 $tempGrib > /dev/null -${tools_dir}/grib_get -p step ${data_dir}/multi_sample.grib2 > ${data_dir}/multi_step.test +${tools_dir}/grib_get -p step $tempGrib > $tempText -diff ${data_dir}/multi_step.test ${data_dir}/multi_step.txt - -step=`${tools_dir}/grib_get -M -p step ${data_dir}/multi_sample.grib2` +reference=${data_dir}/multi_step.txt +diff $reference $tempText +# -M = Turn multi-field support off +step=`${tools_dir}/grib_get -M -p step $tempGrib` [ $step -eq 12 ] -rm -f ${data_dir}/multi_sample.grib2 ${data_dir}/multi_step.test +# Clean up +rm -f $tempGrib $tempText From 5521445e568146105d35cea13cb7e9bb2aeb134f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 7 Mar 2024 16:00:50 +0000 Subject: [PATCH 153/156] Tools: Check overflow/underflow --- src/grib_accessor_class_variable.cc | 7 ++++++- src/grib_util.cc | 7 +++++++ tests/grib_set_fail.sh | 13 +++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/grib_accessor_class_variable.cc b/src/grib_accessor_class_variable.cc index 13b31706b..1eb04f897 100644 --- a/src/grib_accessor_class_variable.cc +++ b/src/grib_accessor_class_variable.cc @@ -208,11 +208,16 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) const double dval = *val; if (*len != 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values", a->name, 1); + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); *len = 1; return GRIB_ARRAY_TOO_SMALL; } + //if (std::isnan(dval)) { + // grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid number for %s: %g", __func__, a->name, dval); + // return GRIB_INVALID_ARGUMENT; + //} + self->dval = dval; if (dval < (double)LONG_MIN || dval > (double)LONG_MAX) self->type = GRIB_TYPE_DOUBLE; diff --git a/src/grib_util.cc b/src/grib_util.cc index 670dbd8aa..d2c1af775 100644 --- a/src/grib_util.cc +++ b/src/grib_util.cc @@ -1748,6 +1748,13 @@ static void set_value(grib_values* value, char* str, int equal) case GRIB_TYPE_UNDEFINED: value->long_value = strtol(buf, &p, 10); if (*p == 0) { + // check the conversion from string to long + if ((errno == ERANGE && (value->long_value == LONG_MAX || value->long_value == LONG_MIN)) || + (errno != 0 && value->long_value == 0)) { + fprintf(stderr, "ECCODES WARNING : Setting %s=%s causes overflow/underflow\n", value->name, buf); + fprintf(stderr, "ECCODES WARNING : Value adjusted to %ld\n", value->long_value); + //perror("strtol"); + } value->type = GRIB_TYPE_LONG; value->has_value = 1; } diff --git a/tests/grib_set_fail.sh b/tests/grib_set_fail.sh index 1a44b5a3b..e3fd7acd9 100755 --- a/tests/grib_set_fail.sh +++ b/tests/grib_set_fail.sh @@ -19,7 +19,7 @@ temp=${data_dir}/temp.$label.out infile=${data_dir}/regular_gaussian_surface.grib2 -# Set without -s. Expected to fail +# Set without -s # ---------------------------------------------------- set +e ${tools_dir}/grib_set -p levtype $infile $outfile > $temp 2>&1 @@ -28,7 +28,7 @@ set -e [ $status -ne 0 ] grep -q "provide some keys to set" $temp -# Set with empty -s. Expected to fail +# Set with empty -s # ---------------------------------------------------- set +e ${tools_dir}/grib_set -s '' $infile $outfile > $temp 2>&1 @@ -37,7 +37,7 @@ set -e [ $status -ne 0 ] grep -q "provide some keys to set" $temp -# Out-of-bounds value. Expected to fail +# Out-of-bounds value # ---------------------------------------------------- input=${data_dir}/reduced_gaussian_sub_area.grib2 set +e @@ -47,7 +47,7 @@ set -e [ $status -ne 0 ] grep -q "Trying to encode value of 1000 but the maximum allowable value is 255 (number of bits=8)" $temp -# Negative value for an unsigned key. Expected to fail +# Negative value for an unsigned key # ---------------------------------------------------- input=${data_dir}/reduced_gaussian_sub_area.grib2 set +e @@ -181,6 +181,11 @@ set -e [ $status -ne 0 ] grep -q "centre: No such code table entry.*Did you mean.*ecmf" $temp +# Overflow/Underflow +# ------------------------ +input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl +${tools_dir}/grib_set -s missingValue=9223372036854776666 $input $outfile > $temp 2>&1 +grep -q "ECCODES WARNING : Setting .* causes overflow/underflow" $temp # ------------------------ # Unreadable message From 84f23bf5020134ec9bf3fe43cf5c1eb8efe7fc73 Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 7 Mar 2024 16:58:23 +0000 Subject: [PATCH 154/156] ECC-1782: Repacking sample GRIB2.tmpl fails when ECCODES_GRIB_DATA_QUALITY_CHECKS=1 --- samples/GRIB2.tmpl | Bin 179 -> 179 bytes tests/codes_ecc-1698.sh | 4 ++-- tests/grib_data_quality_checks.sh | 17 ++++++++++++++--- tests/grib_decimalPrecision.sh | 8 +++++--- tests/grib_ecc-1271.sh | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/samples/GRIB2.tmpl b/samples/GRIB2.tmpl index 5c7b111ce7bff3a14a194351d67418d3aa6342ce..e2f890a57d52dea5ea01d64c3285a1babd51bab1 100644 GIT binary patch delta 32 gcmdnYxS4UnEJ^2%28ISM1_)qd`wwKWvYP_|0EIXPbN~PV delta 32 gcmdnYxS4UnEJ^zY28ISM1_)qd`wwKWvYP_|0C $tempDir/param_limits.def < 4 -${tools_dir}/grib_set -s paramId=260509,step=12,scaleValuesBy=1000 $sample_g2 $tempGrib2 +# The GRIB2 sample has max values of 273. We need to use 1 for this test +${tools_dir}/grib_set -s paramId=260509,step=12,values=1,scaleValuesBy=1000 $sample_g2 $tempGrib2 # Step of 0 doesn't satisfy the condition so will use 400 +# The GRIB2 sample has max values of 273. We need to use 1 for this test set +e -${tools_dir}/grib_set -s paramId=260509,scaleValuesBy=1000 $sample_g2 $tempGrib2 +${tools_dir}/grib_set -s paramId=260509,values=1,scaleValuesBy=1000 $sample_g2 $tempGrib2 status=$? set -e [ $status -ne 0 ] diff --git a/tests/grib_decimalPrecision.sh b/tests/grib_decimalPrecision.sh index 66a4c6253..afe13ad74 100755 --- a/tests/grib_decimalPrecision.sh +++ b/tests/grib_decimalPrecision.sh @@ -10,6 +10,9 @@ . ./include.ctest.sh +label="grib_decimalPrecision_test" + +temp=temp.$label.grib REDIRECT=/dev/null files="regular_latlon_surface.grib2 \ @@ -29,7 +32,6 @@ for file in $files; do done # ECC-458: spectral_complex packing -temp=temp.grib_decimalPrecision.grib infile=${data_dir}/spectral_complex.grib1 # Catch errors re negative values export ECCODES_FAIL_IF_LOG_MESSAGE=1 @@ -42,7 +44,7 @@ sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl ${tools_dir}/grib_set -s decimalScaleFactor=3 $sample1 $temp grib_check_key_equals $temp min,max,const,decimalScaleFactor,referenceValue '47485.4 47485.4 1 3 47485.4' ${tools_dir}/grib_set -s decimalScaleFactor=3 $sample2 $temp -grib_check_key_equals $temp min,max,const,decimalScaleFactor,referenceValue '1 1 1 3 1' - +grib_check_key_equals $temp min,max,const,decimalScaleFactor,referenceValue '273 273 1 3 273' +# Clean up rm -f $temp diff --git a/tests/grib_ecc-1271.sh b/tests/grib_ecc-1271.sh index 04a25d828..8e9f7ed13 100755 --- a/tests/grib_ecc-1271.sh +++ b/tests/grib_ecc-1271.sh @@ -23,6 +23,6 @@ $sample_grib2 $temp grib_check_key_equals $temp Ni,Nj "16 31" grib_check_key_equals $temp centreLatitudeInDegrees,centreLongitudeInDegrees "0 30" -grib_check_key_equals $temp minimum,maximum "1 1" +grib_check_key_equals $temp minimum,maximum "273 273" rm -f $temp From 017794f8e1c8a9a40e6390c50d684401866fb9f9 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 7 Mar 2024 21:10:30 +0000 Subject: [PATCH 155/156] Refactoring: removal of duplicated code (dump) --- src/grib_accessor_class_bit.cc | 9 ++------- src/grib_accessor_class_bufrdc_expanded_descriptors.cc | 10 ++-------- src/grib_accessor_class_expanded_descriptors.cc | 10 ++-------- src/grib_accessor_class_g1date.cc | 10 ++-------- src/grib_accessor_class_g1monthlydate.cc | 10 ++-------- src/grib_accessor_class_g1verificationdate.cc | 10 ++-------- src/grib_accessor_class_g2date.cc | 10 ++-------- src/grib_accessor_class_g2level.cc | 10 ++-------- src/grib_accessor_class_rdbtime_guess_date.cc | 10 ++-------- src/grib_accessor_class_signed_bits.cc | 10 ++-------- src/grib_accessor_class_spd.cc | 10 ++-------- src/grib_accessor_class_time.cc | 10 ++-------- src/grib_accessor_class_validity_date.cc | 10 ++-------- src/grib_accessor_class_validity_time.cc | 10 ++-------- 14 files changed, 28 insertions(+), 111 deletions(-) diff --git a/src/grib_accessor_class_bit.cc b/src/grib_accessor_class_bit.cc index 17c1d3c8c..e3099d259 100644 --- a/src/grib_accessor_class_bit.cc +++ b/src/grib_accessor_class_bit.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS = const char* owner MEMBERS = int bit_index END_CLASS_DEF @@ -36,7 +36,6 @@ or edit "accessor.class" and rerun ./make_class.pl static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_bit @@ -60,7 +59,7 @@ static grib_accessor_class _grib_accessor_class_bit = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -112,10 +111,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} static int unpack_long(grib_accessor* a, long* val, size_t* len) { diff --git a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/grib_accessor_class_bufrdc_expanded_descriptors.cc index 8476f4708..929e21724 100644 --- a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc +++ b/src/grib_accessor_class_bufrdc_expanded_descriptors.cc @@ -24,7 +24,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long IMPLEMENTS = unpack_string_array -IMPLEMENTS = init;dump;destroy +IMPLEMENTS = init;destroy IMPLEMENTS = value_count MEMBERS = const char* expandedDescriptors MEMBERS = grib_accessor* expandedDescriptorsAccessor @@ -47,7 +47,6 @@ static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string_array(grib_accessor*, char**, size_t* len); static int value_count(grib_accessor*, long*); static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_bufrdc_expanded_descriptors @@ -71,7 +70,7 @@ static grib_accessor_class _grib_accessor_class_bufrdc_expanded_descriptors = { &init, /* init */ 0, /* post_init */ &destroy, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ &value_count, /* get number of values */ @@ -125,11 +124,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static grib_accessor* get_accessor(grib_accessor* a) { grib_accessor_bufrdc_expanded_descriptors* self = (grib_accessor_bufrdc_expanded_descriptors*)a; diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/grib_accessor_class_expanded_descriptors.cc index d515e4dcb..b4cb0ece7 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/grib_accessor_class_expanded_descriptors.cc @@ -26,7 +26,7 @@ SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long IMPLEMENTS = unpack_double IMPLEMENTS = unpack_string_array -IMPLEMENTS = init;dump;destroy +IMPLEMENTS = init;destroy IMPLEMENTS = value_count; get_native_type MEMBERS = const char* unexpandedDescriptors MEMBERS = const char* sequence @@ -59,7 +59,6 @@ static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string_array(grib_accessor*, char**, size_t* len); static int value_count(grib_accessor*, long*); static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_expanded_descriptors @@ -90,7 +89,7 @@ static grib_accessor_class _grib_accessor_class_expanded_descriptors = { &init, /* init */ 0, /* post_init */ &destroy, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ &value_count, /* get number of values */ @@ -180,11 +179,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err); #define BUFR_DESCRIPTORS_ARRAY_USED_SIZE(v) ((v)->n) diff --git a/src/grib_accessor_class_g1date.cc b/src/grib_accessor_class_g1date.cc index 10294a935..c53b3768a 100644 --- a/src/grib_accessor_class_g1date.cc +++ b/src/grib_accessor_class_g1date.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long;unpack_string - IMPLEMENTS = init;dump;value_count + IMPLEMENTS = init;value_count MEMBERS=const char* century MEMBERS=const char* year MEMBERS=const char* month @@ -40,7 +40,6 @@ static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string(grib_accessor*, char*, size_t* len); static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_g1date @@ -66,7 +65,7 @@ static grib_accessor_class _grib_accessor_class_g1date = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ &value_count, /* get number of values */ @@ -122,11 +121,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->day = grib_arguments_get_name(hand, c, n++); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_g1date* self = (grib_accessor_g1date*)a; diff --git a/src/grib_accessor_class_g1monthlydate.cc b/src/grib_accessor_class_g1monthlydate.cc index 503d0daa4..57c3ea729 100644 --- a/src/grib_accessor_class_g1monthlydate.cc +++ b/src/grib_accessor_class_g1monthlydate.cc @@ -22,7 +22,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* date END_CLASS_DEF @@ -39,7 +39,6 @@ or edit "accessor.class" and rerun ./make_class.pl */ static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_g1monthlydate @@ -62,7 +61,7 @@ static grib_accessor_class _grib_accessor_class_g1monthlydate = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -115,11 +114,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_g1monthlydate* self = (grib_accessor_g1monthlydate*)a; diff --git a/src/grib_accessor_class_g1verificationdate.cc b/src/grib_accessor_class_g1verificationdate.cc index a3272acc2..03c871617 100644 --- a/src/grib_accessor_class_g1verificationdate.cc +++ b/src/grib_accessor_class_g1verificationdate.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* date MEMBERS=const char* time MEMBERS=const char* step @@ -36,7 +36,6 @@ or edit "accessor.class" and rerun ./make_class.pl */ static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_g1verificationdate @@ -61,7 +60,7 @@ static grib_accessor_class _grib_accessor_class_g1verificationdate = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -117,11 +116,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_g1verificationdate* self = (grib_accessor_g1verificationdate*)a; diff --git a/src/grib_accessor_class_g2date.cc b/src/grib_accessor_class_g2date.cc index c85e86b9e..698cd4a26 100644 --- a/src/grib_accessor_class_g2date.cc +++ b/src/grib_accessor_class_g2date.cc @@ -16,7 +16,7 @@ START_CLASS_DEF CLASS = accessor SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long;init;dump + IMPLEMENTS = unpack_long;pack_long;init MEMBERS=const char* century MEMBERS=const char* year MEMBERS=const char* month @@ -37,7 +37,6 @@ or edit "accessor.class" and rerun ./make_class.pl static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_g2date @@ -63,7 +62,7 @@ static grib_accessor_class _grib_accessor_class_g2date = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -116,11 +115,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { const grib_accessor_g2date* self = (grib_accessor_g2date*)a; diff --git a/src/grib_accessor_class_g2level.cc b/src/grib_accessor_class_g2level.cc index e1d8aaa38..39bd79033 100644 --- a/src/grib_accessor_class_g2level.cc +++ b/src/grib_accessor_class_g2level.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_long;pack_long;init;dump;is_missing + IMPLEMENTS = unpack_long;pack_long;init;is_missing MEMBERS=const char* type_first MEMBERS=const char* scale_first MEMBERS=const char* value_first @@ -41,7 +41,6 @@ static int pack_double(grib_accessor*, const double* val, size_t* len); static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_double(grib_accessor*, double* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_g2level @@ -67,7 +66,7 @@ static grib_accessor_class _grib_accessor_class_g2level = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -126,11 +125,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static bool is_tigge(grib_handle* h) { long productionStatus = 0; diff --git a/src/grib_accessor_class_rdbtime_guess_date.cc b/src/grib_accessor_class_rdbtime_guess_date.cc index 7bd8a3c4a..8a3bfa2a1 100644 --- a/src/grib_accessor_class_rdbtime_guess_date.cc +++ b/src/grib_accessor_class_rdbtime_guess_date.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* typicalYear MEMBERS=const char* typicalMonth MEMBERS=const char* typicalDay @@ -39,7 +39,6 @@ or edit "accessor.class" and rerun ./make_class.pl static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_rdbtime_guess_date @@ -66,7 +65,7 @@ static grib_accessor_class _grib_accessor_class_rdbtime_guess_date = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -124,11 +123,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_rdbtime_guess_date* self = (grib_accessor_rdbtime_guess_date*)a; diff --git a/src/grib_accessor_class_signed_bits.cc b/src/grib_accessor_class_signed_bits.cc index 1750af3eb..dc8ccf488 100644 --- a/src/grib_accessor_class_signed_bits.cc +++ b/src/grib_accessor_class_signed_bits.cc @@ -16,7 +16,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init IMPLEMENTS = next_offset IMPLEMENTS = byte_count IMPLEMENTS = value_count @@ -45,7 +45,6 @@ static long byte_count(grib_accessor*); static long byte_offset(grib_accessor*); static long next_offset(grib_accessor*); static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); static void update_size(grib_accessor*, size_t); @@ -70,7 +69,7 @@ static grib_accessor_class _grib_accessor_class_signed_bits = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ &next_offset, /* next_offset */ 0, /* get length of string */ &value_count, /* get number of values */ @@ -152,11 +151,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args) a->length = compute_byte_count(a); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; diff --git a/src/grib_accessor_class_spd.cc b/src/grib_accessor_class_spd.cc index 22fa03dc5..734c0bc89 100644 --- a/src/grib_accessor_class_spd.cc +++ b/src/grib_accessor_class_spd.cc @@ -16,7 +16,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init IMPLEMENTS = next_offset IMPLEMENTS = byte_count IMPLEMENTS = value_count @@ -45,7 +45,6 @@ static long byte_count(grib_accessor*); static long byte_offset(grib_accessor*); static long next_offset(grib_accessor*); static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); static void update_size(grib_accessor*, size_t); @@ -70,7 +69,7 @@ static grib_accessor_class _grib_accessor_class_spd = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ &next_offset, /* next_offset */ 0, /* get length of string */ &value_count, /* get number of values */ @@ -153,11 +152,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args) a->length = compute_byte_count(a); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_spd* self = (grib_accessor_spd*)a; diff --git a/src/grib_accessor_class_time.cc b/src/grib_accessor_class_time.cc index 36aa290c9..3251fdd33 100644 --- a/src/grib_accessor_class_time.cc +++ b/src/grib_accessor_class_time.cc @@ -18,7 +18,7 @@ SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long;pack_long IMPLEMENTS = unpack_string - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* hour MEMBERS=const char* minute MEMBERS=const char* second @@ -39,7 +39,6 @@ or edit "accessor.class" and rerun ./make_class.pl static int pack_long(grib_accessor*, const long* val, size_t* len); static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_time @@ -64,7 +63,7 @@ static grib_accessor_class _grib_accessor_class_time = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -119,11 +118,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->second = grib_arguments_get_name(hand, c, n++); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { const grib_accessor_time* self = (grib_accessor_time*)a; diff --git a/src/grib_accessor_class_validity_date.cc b/src/grib_accessor_class_validity_date.cc index 8182228ae..760b7bccd 100644 --- a/src/grib_accessor_class_validity_date.cc +++ b/src/grib_accessor_class_validity_date.cc @@ -17,7 +17,7 @@ CLASS = accessor SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* date MEMBERS=const char* time MEMBERS=const char* step @@ -40,7 +40,6 @@ or edit "accessor.class" and rerun ./make_class.pl */ static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_validity_date @@ -69,7 +68,7 @@ static grib_accessor_class _grib_accessor_class_validity_date = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -165,11 +164,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; diff --git a/src/grib_accessor_class_validity_time.cc b/src/grib_accessor_class_validity_time.cc index 0b2c9697f..34eb78128 100644 --- a/src/grib_accessor_class_validity_time.cc +++ b/src/grib_accessor_class_validity_time.cc @@ -18,7 +18,7 @@ SUPER = grib_accessor_class_long IMPLEMENTS = unpack_long IMPLEMENTS = unpack_string - IMPLEMENTS = init;dump + IMPLEMENTS = init MEMBERS=const char* date MEMBERS=const char* time MEMBERS=const char* step @@ -41,7 +41,6 @@ or edit "accessor.class" and rerun ./make_class.pl static int unpack_long(grib_accessor*, long* val, size_t* len); static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); static void init(grib_accessor*, const long, grib_arguments*); typedef struct grib_accessor_validity_time @@ -69,7 +68,7 @@ static grib_accessor_class _grib_accessor_class_validity_time = { &init, /* init */ 0, /* post_init */ 0, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* next_offset */ 0, /* get length of string */ 0, /* get number of values */ @@ -164,11 +163,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - static int unpack_long(grib_accessor* a, long* val, size_t* len) { grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; From 13e38aae9222a8b102e5653cb568d06982203708 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 7 Mar 2024 21:11:32 +0000 Subject: [PATCH 156/156] Deprecated travis yaml --- .travis.yml => deprecated/.travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yml => deprecated/.travis.yml (100%) diff --git a/.travis.yml b/deprecated/.travis.yml similarity index 100% rename from .travis.yml rename to deprecated/.travis.yml