Skip to content

Commit f6a19f7

Browse files
committed
Merge branch 'hotfix/2.40.1'
2 parents 5ab3e6c + 15ef546 commit f6a19f7

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.40.0
1+
2.40.1

src/grib_handle.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ static bool can_create_clone_headers_only(const grib_handle* h)
338338
int err = grib_get_long(h, "isGridded", &isGridded);
339339
if (err || !isGridded) return false;
340340

341+
// ECC-2045: Input is already headers_only
342+
long bitsPerValue = 0;
343+
err = grib_get_long(h, "bitsPerValue", &bitsPerValue);
344+
if (err || bitsPerValue == 0) return false;
345+
341346
return true;
342347
}
343348

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ list(APPEND test_c_bins
4747
grib_ecc-1433
4848
grib_ecc-1764
4949
grib_ecc-2019
50+
grib_ecc-2045
5051
bufr_ecc-517
5152
bufr_ecc-1288
5253
bufr_ecc-2011
@@ -292,6 +293,7 @@ if( HAVE_BUILD_TOOLS )
292293
grib_ecc-2002
293294
grib_ecc-2006
294295
grib_ecc-2019
296+
grib_ecc-2045
295297
grib_modelName
296298
grib_sub_hourly
297299
grib_set_bytes

tests/grib_ecc-2045.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* (C) Copyright 2005- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8+
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9+
*/
10+
#include "grib_api_internal.h"
11+
12+
int main(int argc, char* argv[])
13+
{
14+
int err = 0;
15+
long lVal=0;
16+
17+
ECCODES_ASSERT(argc == 2);
18+
19+
printf("\nDoing file %s...\n", argv[1]);
20+
FILE* in = fopen(argv[1], "rb");
21+
ECCODES_ASSERT(in);
22+
23+
grib_handle* handle = grib_handle_new_from_file(0, in, &err);
24+
ECCODES_ASSERT(handle);
25+
ECCODES_ASSERT(!err);
26+
27+
grib_handle* c = grib_handle_clone_headers_only(handle);
28+
ECCODES_ASSERT(c);
29+
lVal=-1; GRIB_CHECK( grib_get_long(c, "isMessageValid", &lVal), 0); printf("0. isMessageValid=%ld\n", lVal);
30+
printf("0. /////// dump the 1st clone (grib1 headers_only)\n");
31+
grib_dump_content(c, stdout, "wmo", 0, 0);
32+
33+
printf("\nSetting edition=2...\n");
34+
GRIB_CHECK( grib_set_long(c, "edition", 2), 0);
35+
printf("1. /////// dump the 1st clone (grib2 headers_only)\n");
36+
grib_dump_content(c, stdout, "wmo", 0, 0);
37+
lVal=-1; GRIB_CHECK( grib_get_long(c, "isMessageValid", &lVal), 0); printf("1. isMessageValid=%ld\n", lVal);
38+
39+
printf("\nClone the clone...\n");
40+
grib_handle* c2 = grib_handle_clone_headers_only(c);
41+
ECCODES_ASSERT(c2);
42+
printf("2. /////// dump the 2nd clone (grib2 headers_only)\n");
43+
grib_dump_content(c2, stdout, "wmo", 0, 0);
44+
lVal=-1; GRIB_CHECK( grib_get_long(c2, "isMessageValid", &lVal), 0); printf("2. isMessageValid=%ld\n", lVal);
45+
46+
grib_handle_delete(handle);
47+
grib_handle_delete(c);
48+
grib_handle_delete(c2);
49+
fclose(in);
50+
printf("All OK.\n");
51+
return 0;
52+
}

tests/grib_ecc-2045.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
# (C) Copyright 2005- ECMWF.
3+
#
4+
# This software is licensed under the terms of the Apache Licence Version 2.0
5+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8+
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9+
#
10+
11+
. ./include.ctest.sh
12+
13+
# ---------------------------------------------------------
14+
# This is the test for the JIRA issue ECC-2045
15+
# GRIB: cannot clone repeatedly with headers only
16+
# ---------------------------------------------------------
17+
18+
REDIRECT=/dev/null
19+
20+
label="grib_ecc-2045_test"
21+
tempGrib=temp.$label.grib
22+
tempLog=temp.$label.log
23+
24+
infiles="GRIB1.tmpl GRIB2.tmpl sh_ml_grib1.tmpl sh_ml_grib2.tmpl"
25+
for f in $infiles; do
26+
$EXEC $test_dir/grib_ecc-2045 $ECCODES_SAMPLES_PATH/$f
27+
done
28+
29+
# infile=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
30+
# $EXEC $test_dir/grib_ecc-2045 $infile
31+
32+
# infile=$ECCODES_SAMPLES_PATH/sh_ml_grib1.tmpl
33+
# $EXEC $test_dir/grib_ecc-2045 $infile
34+
35+
# infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
36+
# $EXEC $test_dir/grib_ecc-2045 $infile
37+
38+
# infile=$ECCODES_SAMPLES_PATH/sh_ml_grib2.tmpl
39+
# $EXEC $test_dir/grib_ecc-2045 $infile
40+
41+
42+
# Clean up
43+
rm -f $tempGrib $tempLog

0 commit comments

Comments
 (0)