Skip to content

Commit 446dca7

Browse files
Merge pull request #517 from NOAA-EMC/delayed_error
issue #513 delayed error
2 parents 671a517 + 5cae017 commit 446dca7

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/Sec3.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ extern enum output_order_type output_order;
4444
/** New line character. */
4545
extern char *nl;
4646

47+
/** used by delayed error */
48+
extern unsigned int last_message;
49+
50+
extern int decode; /**< Decode grib file flag */
51+
52+
4753
static void print_stagger(int scan, char *inv_out);
4854

4955
/** Number of variable dimensions. */
@@ -283,8 +289,13 @@ int get_nxny_(unsigned char **sec, unsigned int *nx, unsigned int *ny, unsigned
283289

284290

285291
if ((*nx != 0 || *ny != 0) && GB2_Sec3_npts(sec) != npoints && GDS_Scan_staggered_storage(*scan) == 0) {
286-
fprintf(stderr,"two values for number of points %u (GDS) %u (calculated)\n",
287-
GB2_Sec3_npts(sec), npoints);
292+
if (decode) {
293+
fatal_error("two values for number of points %u (GDS-octet 7-10) and %u (thinned grid calculation)",
294+
GB2_Sec3_npts(sec), npoints);
295+
}
296+
fprintf(stdout,"FATAL ERROR (delayed): two values for number of points %u (GDS-octet 7-10) and %u (thinned grid calculation)\n",
297+
GB2_Sec3_npts(sec), npoints);
298+
last_message |= DELAYED_GRID_SIZE_ERR;
288299
}
289300

290301
/*

src/wgrib2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ int wgrib2(int argc, const char **argv) {
499499
(GB2_ParmNum(sec) >= 192 && GB2_ParmNum(sec) <= 254) ||
500500
(GB2_ParmCat(sec) >= 192 && GB2_ParmCat(sec) <= 254) ||
501501
(GB2_Discipline(sec) >= 192 && GB2_Discipline(sec) <= 255) ) {
502-
fprintf(stderr,"\n*** DELATED FATAL ERROR, local grib table=255, replaced by 1 in %s\n", in_file.filename);
502+
fprintf(stderr,"\n*** FATAL ERROR (delayed), local grib table=255, replaced by 1 in %s\n", in_file.filename);
503503
GB2_LocalTable(sec) = 1;
504504
last_message |= DELAYED_LOCAL_GRIBTABLE_ERR;
505505
}

tests/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ copy_test_data(ref_new_grid_gdt_32769.grib2)
116116
copy_test_data(png_4bits.png)
117117
copy_test_data(large_png.grb2)
118118
copy_test_data(ref_c3_overflow.grib2)
119+
copy_test_data(delayed_error.grib2)
119120

120121
# Run these shell tests.
121122
shell_test(run_wgrib2_tests)
@@ -124,6 +125,7 @@ shell_test(run_wgrib2_update_table_tests)
124125

125126
shell_test(run_wgrib2_png_tests)
126127
shell_test(run_gmerge_tests)
128+
shell_test(run_wgrib2_delayed_err_tests)
127129

128130
if (USE_NETCDF)
129131
shell_test(run_wgrib2_netcdf4_tests)
@@ -256,4 +258,4 @@ if (FTP_TEST_FILES)
256258
copy_test_data(ref_rrfs.t18z.prslev.f000.grib2.inv)
257259
shell_test(run_ftp_extra_large_tests)
258260
endif()
259-
endif()
261+
endif()

tests/data/delayed_error.grib2

182 Bytes
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# This script tests delayed errors
3+
#
4+
# 1. badly encoded GDS for thinned grids
5+
#
6+
# w. ebisuzaki 5/2026
7+
8+
set -ex
9+
echo ""
10+
echo "*** Running wgrib2 delayed error tests"
11+
wgrib2='../src/wgrib2'
12+
# wgrib2=wgrib2
13+
14+
file='data/delayed_error.grib2'
15+
16+
# check if fatal error
17+
set +e
18+
$wgrib2 $file
19+
err=$?
20+
if [ "$err" -ne 1 ] ; then
21+
echo "failed test 1a"
22+
exit 1
23+
fi
24+
25+
# echo check if reset_delayed_error works
26+
set -e
27+
$wgrib2 $file -reset_delayed_error
28+
err=$?
29+
if [ "$err" -ne 0 ] ; then
30+
echo "failed test 1b"
31+
exit 1
32+
fi
33+
34+
echo "*** SUCCESS!"
35+
exit 0

0 commit comments

Comments
 (0)