From c791ee1c82cac024100f9c9c4b7779ba4bd6721b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 4 Nov 2016 17:11:30 +0000 Subject: [PATCH 1/4] Testing: add test for C ensemble index example --- examples/C/CMakeLists.txt | 1 + examples/C/grib_ensemble_index.c | 4 +++- examples/C/grib_ensemble_index.sh | 13 +++++++++++++ examples/python/grib_index.sh | 5 ++--- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100755 examples/C/grib_ensemble_index.sh diff --git a/examples/C/CMakeLists.txt b/examples/C/CMakeLists.txt index 691937607..7dd423816 100644 --- a/examples/C/CMakeLists.txt +++ b/examples/C/CMakeLists.txt @@ -70,6 +70,7 @@ list( APPEND tests grib_precision grib_clone grib_copy_message + grib_ensemble_index grib_set_pv grib_set_bitmap grib_list diff --git a/examples/C/grib_ensemble_index.c b/examples/C/grib_ensemble_index.c index b17ad63cf..10d7b0cd3 100644 --- a/examples/C/grib_ensemble_index.c +++ b/examples/C/grib_ensemble_index.c @@ -30,9 +30,11 @@ int main(int argc, char * argv[]) double min=1e13,max=-1e13,avg=0; codes_index* index; codes_handle* h=NULL; + + if (argc<2) return 1; /* create index of file contents for paramId and number */ - index = codes_index_new_from_file(0, "eps", "paramId,number",&ret); + index = codes_index_new_from_file(0, argv[1], "paramId,number",&ret); CODES_CHECK(ret,0); /* get size of "paramId" list */ diff --git a/examples/C/grib_ensemble_index.sh b/examples/C/grib_ensemble_index.sh new file mode 100755 index 000000000..b21379669 --- /dev/null +++ b/examples/C/grib_ensemble_index.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright 2005-2016 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 + +input="../../data/index.grib" +${examples_dir}c_grib_ensemble_index $input diff --git a/examples/python/grib_index.sh b/examples/python/grib_index.sh index 9e1a44e6e..110dde63f 100755 --- a/examples/python/grib_index.sh +++ b/examples/python/grib_index.sh @@ -2,6 +2,5 @@ . ./include.sh -REDIRECT=/dev/null -$PYTHON $examples_src/grib_index.py 2> $REDIRECT > $REDIRECT -rm my.idx || true +$PYTHON $examples_src/grib_index.py +rm -f my.idx From a260817da6dd6eb783f6efb5d09feebcd368411b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 4 Nov 2016 17:47:30 +0000 Subject: [PATCH 2/4] ECC-378: Reading a file of 0 bytes does not generate any error and eventually crashes --- src/grib_index.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/grib_index.c b/src/grib_index.c index 64b2c26cb..3e9b32946 100644 --- a/src/grib_index.c +++ b/src/grib_index.c @@ -940,6 +940,7 @@ int _codes_index_add_file(grib_index* index,const char* filename,int message_typ { double dval; size_t svallen; + size_t message_count = 0; long length,lval; char buf[1024]={0,}; int err=0; @@ -990,6 +991,7 @@ int _codes_index_add_file(grib_index* index,const char* filename,int message_typ index_key=index->keys; field_tree=index->fields; index_key->value[0]=0; + message_count++; while (index_key) { if (index_key->type==GRIB_TYPE_UNDEFINED) { @@ -1071,7 +1073,6 @@ int _codes_index_add_file(grib_index* index,const char* filename,int message_typ if (err) return err; field->length=length; - if (field_tree->field) { grib_field* pfield=field_tree->field; while (pfield->next) pfield=pfield->next; @@ -1080,15 +1081,17 @@ int _codes_index_add_file(grib_index* index,const char* filename,int message_typ field_tree->field=field; if (h) grib_handle_delete(h); - } grib_file_close(file->name, 0, &err); if (err) return err; index->rewind=1; + if (message_count == 0) { + grib_context_log(c,GRIB_LOG_ERROR,"File %s contains no messages", filename); + return GRIB_END_OF_FILE; + } return GRIB_SUCCESS; - } #if 0 From 07b7d581db2b959a5fc0e74cdf01a5aaaa0de0c9 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 4 Nov 2016 17:53:49 +0000 Subject: [PATCH 3/4] ECC-378: Added test --- examples/C/grib_ensemble_index.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/C/grib_ensemble_index.sh b/examples/C/grib_ensemble_index.sh index b21379669..c78ac14f8 100755 --- a/examples/C/grib_ensemble_index.sh +++ b/examples/C/grib_ensemble_index.sh @@ -11,3 +11,13 @@ input="../../data/index.grib" ${examples_dir}c_grib_ensemble_index $input + +# ECC-378: Empty input file +temp=temp_index.empty.grib +touch $temp +set +e +${examples_dir}c_grib_ensemble_index $temp 2>/dev/null +status=$? +set -e +[ $status -ne 0 ] +rm -f $temp From 74ceb08ef831e6dbd4aeb130afa5f58f8eaadba4 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 7 Nov 2016 17:25:50 +0000 Subject: [PATCH 4/4] ECC-272: Flat JSON dump of some BUFR files doesn't contain the last element --- src/grib_dumper_class.c | 7 ++----- tests/bufr_json.sh | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/grib_dumper_class.c b/src/grib_dumper_class.c index b3773291c..f1ba75f95 100644 --- a/src/grib_dumper_class.c +++ b/src/grib_dumper_class.c @@ -64,12 +64,9 @@ void grib_dump_accessors_block(grib_dumper* dumper,grib_block_of_accessors* bloc void grib_dump_accessors_list(grib_dumper* dumper,grib_accessors_list* al) { grib_accessors_list* cur=al; - grib_accessors_list* next=al->next; - - while(next) { + while(cur) { grib_accessor_dump(cur->accessor,dumper); - cur=next; - next=cur->next; + cur = cur->next; } } diff --git a/tests/bufr_json.sh b/tests/bufr_json.sh index 824d4a9d5..2290b4675 100755 --- a/tests/bufr_json.sh +++ b/tests/bufr_json.sh @@ -45,3 +45,5 @@ for c in 1 3 1/3; do fi done +# ECC-272 +${tools_dir}bufr_dump -jf aaen_55.bufr | grep -q -w channelRadiance