diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index caf10725d..d7ef267a7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,6 +30,7 @@ list(APPEND test_bins bufr_ecc-517 bufr_get_element bufr_extract_headers + extract_offsets bufr_check_descriptors grib_sh_ieee64 ieee @@ -116,6 +117,7 @@ if( HAVE_BUILD_TOOLS ) bufr_get_element bufr_wmo_tables bufr_extract_headers + extract_offsets bufr_ecc-673 bufr_ecc-428 bufr_ecc-286 diff --git a/tests/extract_offsets.c b/tests/extract_offsets.c new file mode 100644 index 000000000..37eabecfa --- /dev/null +++ b/tests/extract_offsets.c @@ -0,0 +1,36 @@ +/* + * (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 "eccodes.h" +#include + + +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_ANY, &offsets, &num_messages, strict_mode); + if (err) return err; + + for (i = 0; i < num_messages; ++i) { + printf("%lu\n", offsets[i]); + } + free(offsets); + return 0; +} diff --git a/tests/extract_offsets.sh b/tests/extract_offsets.sh new file mode 100755 index 000000000..47cad316e --- /dev/null +++ b/tests/extract_offsets.sh @@ -0,0 +1,41 @@ +#!/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.sh + +# Define a common label for all the tmp files +label="bufr_extract_offsets_test" +temp1="temp.${label}.1" +temp2="temp.${label}.2" + +echo "Multi-message BUFR..." +# --------------------------- +input=${data_dir}/bufr/aeolus_wmo_26.bufr +$EXEC ${test_dir}/extract_offsets $input > $temp1 +${tools_dir}/bufr_get -p offset:i $input > $temp2 +diff $temp1 $temp2 + +echo "Multi-message GRIB..." +# -------------------------- +input=${data_dir}/mixed.grib +$EXEC ${test_dir}/extract_offsets $input > $temp1 +${tools_dir}/grib_get -p offset:i $input > $temp2 +diff $temp1 $temp2 + + +echo "Test with invalid inputs..." +# --------------------------------- +set +e +$EXEC ${test_dir}/extract_offsets ${data_dir} +status=$? +set -e +[ $status -ne 0 ] + +rm -f $temp1 $temp2