mirror of https://github.com/ecmwf/eccodes.git
GRIB message validity checker: Sections
This commit is contained in:
parent
c59047f34f
commit
ef506078b5
|
@ -9,6 +9,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "grib_accessor_class_message_is_valid.h"
|
#include "grib_accessor_class_message_is_valid.h"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
grib_accessor_message_is_valid_t _grib_accessor_message_is_valid{};
|
grib_accessor_message_is_valid_t _grib_accessor_message_is_valid{};
|
||||||
grib_accessor* grib_accessor_message_is_valid = &_grib_accessor_message_is_valid;
|
grib_accessor* grib_accessor_message_is_valid = &_grib_accessor_message_is_valid;
|
||||||
|
@ -103,8 +104,30 @@ static int check_geoiterator(grib_handle* h)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_sections(grib_handle* h)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
long edition = 0;
|
||||||
|
err = grib_get_long_internal(h, "edition", &edition);
|
||||||
|
if (err) return err;
|
||||||
|
if (edition == 2) {
|
||||||
|
// sections 3 thru to 8 should exist
|
||||||
|
// section 2 is optional
|
||||||
|
for (size_t i=3; i<9; ++i) {
|
||||||
|
char sname[16] = {0,};
|
||||||
|
snprintf(sname, sizeof(sname), "section_%zu", i);
|
||||||
|
if (!grib_is_defined(h, sname)) {
|
||||||
|
grib_context_log(h->context, GRIB_LOG_ERROR, "Section %zu is missing!", i);
|
||||||
|
return GRIB_INVALID_MESSAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GRIB_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
typedef int (*proj_func)(grib_handle*);
|
typedef int (*proj_func)(grib_handle*);
|
||||||
static proj_func check_functions[] = {
|
static proj_func check_functions[] = {
|
||||||
|
check_sections,
|
||||||
check_field_values,
|
check_field_values,
|
||||||
check_grid_pl_array,
|
check_grid_pl_array,
|
||||||
check_geoiterator
|
check_geoiterator
|
||||||
|
|
|
@ -14,8 +14,18 @@ tempGrib=temp.$label.grib
|
||||||
tempText=temp.$label.txt
|
tempText=temp.$label.txt
|
||||||
tempFilt=temp.$label.filt
|
tempFilt=temp.$label.filt
|
||||||
|
|
||||||
sample=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
|
grib_check_key_equals $ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl isMessageValid 1
|
||||||
grib_check_key_equals $sample isMessageValid 1
|
grib_check_key_equals $ECCODES_SAMPLES_PATH/GRIB2.tmpl isMessageValid 1
|
||||||
|
|
||||||
|
|
||||||
|
# Bad sections
|
||||||
|
# ---------------
|
||||||
|
# Correct key order: NV=6,PVPresent=1
|
||||||
|
${tools_dir}/grib_set -s PVPresent=1,NV=6 $ECCODES_SAMPLES_PATH/reduced_gg_pl_128_grib2.tmpl $tempGrib
|
||||||
|
grib_check_key_equals $tempGrib isMessageValid 0 2>$tempText
|
||||||
|
grep -q "Section 5 is missing" $tempText
|
||||||
|
grep -q "Error instantiating iterator gaussian_reduced" $tempText
|
||||||
|
|
||||||
|
|
||||||
# Check regular lat/lon
|
# Check regular lat/lon
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
@ -26,6 +36,7 @@ grep -q "Regular grid Geoiterator" $tempText
|
||||||
|
|
||||||
# Check reduced Gaussian grid Ni
|
# Check reduced Gaussian grid Ni
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
sample=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
|
||||||
cat >$tempFilt<<EOF
|
cat >$tempFilt<<EOF
|
||||||
set Ni = 0; # illegal
|
set Ni = 0; # illegal
|
||||||
assert ( isMessageValid == 0 );
|
assert ( isMessageValid == 0 );
|
||||||
|
@ -39,8 +50,10 @@ grep -q "Invalid Ni" $tempText
|
||||||
grib_check_key_equals $tempGrib isMessageValid 0
|
grib_check_key_equals $tempGrib isMessageValid 0
|
||||||
grib_check_key_equals $sample isMessageValid 1
|
grib_check_key_equals $sample isMessageValid 1
|
||||||
|
|
||||||
|
|
||||||
# Check reduced Gaussian grid pl
|
# Check reduced Gaussian grid pl
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
sample=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
|
||||||
cat >$tempFilt<<EOF
|
cat >$tempFilt<<EOF
|
||||||
meta pl_elem4 element(pl, 4);
|
meta pl_elem4 element(pl, 4);
|
||||||
set pl_elem4 = 0;
|
set pl_elem4 = 0;
|
||||||
|
|
Loading…
Reference in New Issue