BUFR: added test for reading bufr header in C ECC-24

This commit is contained in:
Sandor Kertesz 2015-01-22 10:05:13 +00:00
parent 2fd5b42d1b
commit bd423aa499
4 changed files with 117 additions and 0 deletions

View File

@ -403,6 +403,7 @@ set(bufr_refs_to_download
wavb_134.bufr.desc.ref
aaen_55.bufr.ls.ref
syno_multi.bufr.header.ref
)
foreach( f ${bufr_files_to_download} ${bufr_refs_to_download} )

View File

@ -13,6 +13,7 @@ list( APPEND test_bins
read_index
unit_tests
gauss_sub
bufr_read_header
)
foreach( tool ${test_bins} )
@ -34,6 +35,7 @@ list( APPEND tests
bufrdc_ref
bufr_json
bufr_ls
bufr_read_header
ieee
grib1to2
grib2to1

73
tests/bufr_read_header.c Normal file
View File

@ -0,0 +1,73 @@
/*
* Copyright 2005-2015 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"
void usage(char* prog) {
printf("usage: %s infile\n",prog);
exit(1);
}
int main(int argc,char* argv[]) {
char* filename;
FILE* f;
codes_handle* h=NULL;
long longVal;
double doubleVal;
int count;
int err=0;
int header_only=1;
if (argc!=2) usage(argv[0]);
filename=argv[1];
f=fopen(filename,"r");
if (!f) {
perror(filename);
exit(1);
}
count=1;
while((h=bufr_new_from_file(NULL,f,header_only,&err)) != NULL)
{
/* Check of errors after reading a message. */
if (err != CODES_SUCCESS) CODES_CHECK(err,0);
printf("=======================================\n");
printf("message no: %d\n",count);
/*From section 0 */
CODES_CHECK(codes_get_long(h,"totalLength",&longVal),0);
printf("\ttotalLength: %d\n",longVal);
/*From section 1 */
CODES_CHECK(codes_get_long(h,"centre",&longVal),0);
printf("\tcentre: %d\n",longVal);
/*From section 2 */
CODES_CHECK(codes_get_long(h,"rdbtimeDay",&longVal),0);
printf("\trdbtimeDay: %d\n",longVal);
/*From section 3 */
/*CODES_CHECK(codes_get_long(h,"numberOfSubsets",&longVal),0);
printf("\tnumberOfSubsets: %d\n",longVal);*/
count++;
codes_handle_delete(h);
}
fclose(f);
return 0;
}

41
tests/bufr_read_header.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
# Copyright 2005-2015 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
set -x
#Remember work dir
dWork=`pwd`
#Enter data dir
cd ${data_dir}/bufr
fTmp="tmp.txt"
rm -f $fTmp | true
#-----------------------------------------------------
# Test reading the header only from a
# file with multiple messages
#----------------------------------------------------
f="syno_multi.bufr"
fRef=$f".header.ref"
fRes=$f".header.test"
REDIRECT=/dev/null
${test_dir}/bufr_read_header ${data_dir}/bufr/$f 2> $REDIRECT > $fRes
#Write the values into a file and compare to ref
diff $fRef $fRes >$REDIRECT 2> $REDIRECT
[ $? -eq 0 ]
#Go back to workdir
cd $dWork