From 5d96b407afd8c93b8cccd7a10d7879e2f08043a6 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 23 Sep 2013 15:57:42 +0100 Subject: [PATCH] Unit test for grib_util_sections_copy --- examples/C/Makefile.am | 2 +- examples/C/sections_copy.c | 6 +++++- examples/C/sections_copy.sh | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/C/Makefile.am b/examples/C/Makefile.am index 7b5117afe..b743fcd71 100644 --- a/examples/C/Makefile.am +++ b/examples/C/Makefile.am @@ -2,7 +2,7 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ TESTS = iterator.sh get.sh print_data.sh set.sh keys_iterator.sh multi.sh multi_write.sh \ - precision.sh list.sh large_grib1.sh get_data.sh + precision.sh list.sh large_grib1.sh get_data.sh sections_copy.sh noinst_PROGRAMS = nearest set_bitmap iterator get print_data set set_missing keys_iterator \ set_data mars_param values_check box multi multi2 multi_write precision \ diff --git a/examples/C/sections_copy.c b/examples/C/sections_copy.c index ef8097bd1..744bc8ff6 100644 --- a/examples/C/sections_copy.c +++ b/examples/C/sections_copy.c @@ -11,6 +11,9 @@ void usage(char* prog) { printf("usage: %s in1.grib in2.grib out.grib\n",prog); + printf("in1.grib\t The grib in whose sections we are interested, i.e. the source of the sections (read-only)\n"); + printf("in2.grib\t The input grib (read-only)\n"); + printf("out.grib\t The output file\n"); exit(1); } @@ -47,7 +50,8 @@ int main ( int argc, char* argv[]) { GRIB_CHECK(err,0); fclose(in); - what=GRIB_SECTION_PRODUCT | GRIB_SECTION_LOCAL; + /*what=GRIB_SECTION_PRODUCT | GRIB_SECTION_LOCAL;*/ + what=GRIB_SECTION_GRID; h=grib_util_sections_copy(hfrom,hto,what,&err); GRIB_CHECK(err,0); diff --git a/examples/C/sections_copy.sh b/examples/C/sections_copy.sh index 572d048c2..88133bc83 100755 --- a/examples/C/sections_copy.sh +++ b/examples/C/sections_copy.sh @@ -9,6 +9,21 @@ . ./include.sh -${examples_dir}sections_copy ../../data/in_copy.grib ../../data/out_copy.grib +REGUL_GRID_FILE=../../samples/regular_ll_sfc_grib2.tmpl +GAUSS_GRID_FILE=../../samples/reduced_gg_pl_640_grib2.tmpl +OUTPUT=temp.sections.grib + +${examples_dir}sections_copy $REGUL_GRID_FILE $GAUSS_GRID_FILE $OUTPUT +# Now the output should have a regular grid i.e. gridDefinitionTemplateNumber==0 +# but its date should be the same as the Gaussian grid sample +grid_tmpl=`${tools_dir}grib_get -p gridDefinitionTemplateNumber,date $OUTPUT` +[ "$grid_tmpl" = "0 20100912" ] +${examples_dir}sections_copy $GAUSS_GRID_FILE $REGUL_GRID_FILE $OUTPUT +# Now the output should have a reduced gaussian grid i.e. gridDefinitionTemplateNumber==40 +# but its date should be the same as the Regular grid sample +grid_tmpl=`${tools_dir}grib_get -p gridDefinitionTemplateNumber,date $OUTPUT` +[ "$grid_tmpl" = "40 20070323" ] + +rm -f $OUTPUT