Moved bufr_read_header to examples/C

This commit is contained in:
Shahram Najm 2015-01-24 19:00:15 +00:00
parent 98c1617850
commit e5585348ed
6 changed files with 107 additions and 9 deletions

View File

@ -32,6 +32,7 @@ list( APPEND test_bins
clone
check_gaussian_grid
ensemble_index
bufr_read_header
)
foreach( tool ${test_bins} )
ecbuild_add_executable( TARGET ${tool}
@ -41,7 +42,7 @@ foreach( tool ${test_bins} )
)
endforeach()
# Now add each test
# Now add each test (shell scripts)
#################################################
list( APPEND tests
iterator
@ -60,6 +61,7 @@ list( APPEND tests
sections_copy
set_pv
check_gaussian_grids
bufr_read_header
)
foreach( test ${tests} )
ecbuild_add_test( TARGET c_${test}

View File

@ -3,12 +3,12 @@ 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 sections_copy.sh set_missing.sh clone.sh set_pv.sh \
check_gaussian_grids.sh
check_gaussian_grids.sh bufr_read_header.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 \
set_pv list sections_copy large_grib1 get_data iterator_bitmap clone new_sample \
check_gaussian_grid ensemble_index points
check_gaussian_grid ensemble_index points bufr_read_header
#bin_PROGRAMS = points
box_SOURCES = box.c
@ -37,6 +37,7 @@ clone_SOURCES = clone.c
new_sample_SOURCES = new_sample.c
check_gaussian_grid_SOURCES = check_gaussian_grid.c
ensemble_index_SOURCES = ensemble_index.c
bufr_read_header_SOURCES = bufr_read_header.c
INCLUDES = -I$(top_builddir)/src

View File

@ -0,0 +1,68 @@
/*
* 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;
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 for 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: %ld\n",longVal);
/*From section 1 */
CODES_CHECK(codes_get_long(h,"centre",&longVal),0);
printf("\tcentre: %ld\n",longVal);
/*From section 2 */
CODES_CHECK(codes_get_long(h,"rdbtimeDay",&longVal),0);
printf("\trdbtimeDay: %ld\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;
}

30
examples/C/bufr_read_header.sh Executable file
View File

@ -0,0 +1,30 @@
#!/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
#Enter data dir
cd ${data_dir}/bufr
#-----------------------------------------------------
# Test reading the header only from a BUFR
# file with multiple messages
#----------------------------------------------------
f="syno_multi.bufr"
fRef=$f".header.ref"
fRes=$f".header.test"
REDIRECT=/dev/null
#Write the values into a file and compare with reference
${examples_dir}/bufr_read_header ${data_dir}/bufr/$f 2> $REDIRECT > $fRes
diff $fRef $fRes >$REDIRECT 2> $REDIRECT
rm -f $fRes

View File

@ -13,7 +13,6 @@ list( APPEND test_bins
read_index
unit_tests
gauss_sub
bufr_read_header
)
foreach( tool ${test_bins} )
@ -25,7 +24,7 @@ foreach( tool ${test_bins} )
)
endforeach()
# Now add each test
# Now add each test (shell scripts)
#################################################
list( APPEND tests
definitions
@ -35,7 +34,6 @@ list( APPEND tests
bufrdc_ref
bufr_json
bufr_ls
bufr_read_header
ieee
grib1to2
grib2to1

View File

@ -1,5 +1,5 @@
TESTS = definitions.sh calendar.sh \
bufrdc_desc_ref.sh bufrdc_ref.sh bufr_dump.sh bufr_json.sh bufr_read_header.sh bufr_ls.sh \
bufrdc_desc_ref.sh bufrdc_ref.sh bufr_dump.sh bufr_json.sh bufr_ls.sh \
ieee.sh grib1to2.sh \
unit_tests.sh \
grib2to1.sh badgrib.sh ls.sh filter.sh \
@ -16,7 +16,7 @@ TESTS = definitions.sh calendar.sh \
noinst_PROGRAMS = packing_check gauss_sub read_any double_cmp packing pack_unpack \
multi_from_message julian read_index index gribex_perf\
jpeg_perf ccsds_perf so_perf png_perf bpv_limit laplacian \
unit_tests bufr_read_header
unit_tests
multi_from_message_SOURCES = multi_from_message.c
laplacian_SOURCES = laplacian.c
@ -35,7 +35,6 @@ png_perf_SOURCES = png_perf.c
ccsds_perf_SOURCES = ccsds_perf.c
gribex_perf_SOURCES = gribex_perf.c
gauss_sub_SOURCES = gauss_sub.c
bufr_read_header_SOURCES = bufr_read_header.c
LDADD = $(top_builddir)/src/libgrib_api.la $(EMOS_LIB)