diff --git a/examples/C/bufr_print_header.c b/examples/C/bufr_print_header.c index ee4295191..a9a7e0eee 100644 --- a/examples/C/bufr_print_header.c +++ b/examples/C/bufr_print_header.c @@ -60,32 +60,32 @@ int main(int argc,char* argv[]) /* get and print some keys form the BUFR header */ CODES_CHECK(codes_get_long(h,"dataCategory",&longVal),0); - printf("\tdataCategory: %ld\n",longVal); + printf(" dataCategory: %ld\n",longVal); CODES_CHECK(codes_get_long(h,"dataSubCategory",&longVal),0); - printf("\tdataSubCategory: %ld\n",longVal); + printf(" dataSubCategory: %ld\n",longVal); /* string value */ CODES_CHECK(codes_get_length(h, "typicalDate", &len), 0); typicalDate = (char*)malloc(len*sizeof(char)); grib_get_string(h, "typicalDate", typicalDate, &len); - printf("\ttypicalDate: %s\n", typicalDate); + printf(" typicalDate: %s\n", typicalDate); free(typicalDate); CODES_CHECK(codes_get_long(h,"centre",&longVal),0); - printf("\tcentre: %ld\n",longVal); + printf(" centre: %ld\n",longVal); CODES_CHECK(codes_get_long(h,"subCentre",&longVal),0); - printf("\tsubCentre: %ld\n",longVal); + printf(" subCentre: %ld\n",longVal); CODES_CHECK(codes_get_long(h,"masterTablesVersionNumber",&longVal),0); - printf("\tmasterTablesVersionNumber: %ld\n",longVal); + printf(" masterTablesVersionNumber: %ld\n",longVal); CODES_CHECK(codes_get_long(h,"localTablesVersionNumber",&longVal),0); - printf("\tlocalTablesVersionNumber: %ld\n",longVal); + printf(" localTablesVersionNumber: %ld\n",longVal); CODES_CHECK(codes_get_long(h,"numberOfSubsets",&longVal),0); - printf("\tnumberOfSubsets: %ld\n",longVal); + printf(" numberOfSubsets: %ld\n",longVal); /* delete handle */ codes_handle_delete(h); diff --git a/examples/C/bufr_print_header.sh b/examples/C/bufr_print_header.sh index 3545a6ed7..0b4a4f402 100755 --- a/examples/C/bufr_print_header.sh +++ b/examples/C/bufr_print_header.sh @@ -10,22 +10,22 @@ . ./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" +f=${data_dir}"/bufr/syno_multi.bufr" fRef=$f".header.ref" -fRes=$f".header.test" +fRes=$f".header.test.c" REDIRECT=/dev/null #Write the values into a file and compare with reference -${examples_dir}/bufr_print_header ${data_dir}/bufr/$f 2> $REDIRECT > $fRes -#diff $fRef $fRes >$REDIRECT 2> $REDIRECT +${examples_dir}/bufr_print_header $f 2> $REDIRECT > $fRes + +#We compare output to the reference by ignoring the whitespaces +diff -w $fRef $fRes >$REDIRECT 2> $REDIRECT #cat $fRes +#Clean up rm -f $fRes diff --git a/examples/F90/CMakeLists.txt b/examples/F90/CMakeLists.txt index a5d70e30c..153c6e94e 100644 --- a/examples/F90/CMakeLists.txt +++ b/examples/F90/CMakeLists.txt @@ -29,7 +29,7 @@ list( APPEND tests read_from_file get_set_uuid clone - bufr_read_header + bufr_print_header ) # Simplify tests: no need to build executable and then test. All in one diff --git a/examples/F90/Makefile.am b/examples/F90/Makefile.am index 43191652f..5d42f7249 100644 --- a/examples/F90/Makefile.am +++ b/examples/F90/Makefile.am @@ -4,12 +4,12 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ @FORCE_32_CFLAGS@ TESTS = copy_message.sh get.sh get_data.sh get_pl.sh get_pv.sh keys_iterator.sh \ nearest.sh precision.sh multi_write.sh multi.sh print_data.sh set.sh set_bitmap.sh set_missing.sh \ set_pv.sh samples.sh count_messages.sh read_message.sh read_from_file.sh index.sh get_set_uuid.sh \ - bufr_read_header.sh + bufr_print_header.sh noinst_PROGRAMS = f_index f_copy_message f_get f_get_data f_get_pl f_get_pv f_keys_iterator \ f_multi_write f_multi f_nearest f_precision f_print_data f_set f_set_bitmap f_set_missing \ f_set_pv f_samples f_count_messages f_read_message f_read_from_file f_new_from_file \ - f_copy_namespace f_get_set_uuid f_set_gvc f_clone f_bufr_read_header + f_copy_namespace f_get_set_uuid f_set_gvc f_clone f_bufr_print_header f_index_SOURCES=index.f90 f_copy_message_SOURCES=copy_message.f90 @@ -36,7 +36,7 @@ f_copy_namespace_SOURCES=copy_namespace.f90 f_get_set_uuid_SOURCES=get_set_uuid.f90 f_set_gvc_SOURCES=set_gvc.f90 f_clone_SOURCES=clone.f90 -f_bufr_read_header_SOURCES=bufr_read_header.f90 +f_bufr_print_header_SOURCES=bufr_print_header.f90 INCLUDES = -I$(top_builddir)/src diff --git a/examples/F90/bufr_print_header.f90 b/examples/F90/bufr_print_header.f90 new file mode 100644 index 000000000..2f852a2f9 --- /dev/null +++ b/examples/F90/bufr_print_header.f90 @@ -0,0 +1,77 @@ +! +!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. +! +! +! FOTRAN 90 Implementation: bufr_print_header +! +! Description: how to read/print the header of BUFR messages. +! +! +program bufr_print_header +use eccodes +implicit none +integer :: ifile +integer :: iret +integer :: ibufr +integer :: count=0 +integer(kind=4) :: dataCategory,dataSubCategory,typicalDate +integer(kind=4) :: centre,subcentre +integer(kind=4) :: masterversion,localversion +integer(kind=4) :: numberofsubsets + + call codes_open_file(ifile,'../../data/bufr/syno_multi.bufr','r') + +! the first bufr message is loaded from file +! ibufr is the bufr id to be used in subsequent calls + call codes_bufr_new_from_file(ifile,ibufr,iret) + + do while (iret/=CODES_END_OF_FILE) + + ! get and print some keys form the BUFR header + write(*,*) 'message: ',count + + call codes_get(ibufr,'dataCategory',dataCategory); + write(*,*) ' dataCategory:',dataCategory + + call codes_get(ibufr,'dataSubCategory',dataSubCategory); + write(*,*) ' dataSubCategory:',dataSubCategory + + call codes_get(ibufr,'typicalDate',typicalDate); + write(*,*) ' typicalDate:',typicalDate + + call codes_get(ibufr,'centre',centre); + write(*,*) ' centre:',centre + + call codes_get(ibufr,'subCentre',subcentre) + write(*,*) ' subCentre:',subcentre + + call codes_get(ibufr,'masterTablesVersionNumber',masterversion) + write(*,*) ' masterTablesVersionNumber:',masterversion + + call codes_get(ibufr,'localTablesVersionNumber',localversion) + write(*,*) ' localTablesVersionNumber:',localversion + + call codes_get(ibufr,'numberOfSubsets',numberofsubsets) + write(*,*) ' numberOfSubsets:',numberofsubsets + + ! release the bufr message + call codes_release(ibufr) + + ! load the next bufr message + call codes_bufr_new_from_file(ifile,ibufr,iret) + + count=count+1 + + end do + +! close file + call codes_close_file(ifile) + + +end program bufr_print_header diff --git a/examples/F90/bufr_print_header.sh b/examples/F90/bufr_print_header.sh new file mode 100755 index 000000000..02bb9a83b --- /dev/null +++ b/examples/F90/bufr_print_header.sh @@ -0,0 +1,34 @@ +#!/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 + + +#----------------------------------------------------- +# Test reading the header only from a BUFR +# file with multiple messages. +#---------------------------------------------------- + +#The bufr filename is hardcoded in the python example +f=${data_dir}"/bufr/syno_multi.bufr" + +fRef=$f".header.ref" +fRes=$f".header.test.f" +REDIRECT=/dev/null + +#Write the values into a file and compare with reference +${examples_dir}/f_bufr_print_header 2> $REDIRECT > $fRes + +#We compare output to the reference by ignoring the whitespaces +diff -w $fRef $fRes >$REDIRECT 2> $REDIRECT + +#cat $fRes + +rm -f $fRes + diff --git a/examples/F90/bufr_read_header.f90 b/examples/F90/bufr_read_header.f90 deleted file mode 100644 index 82518d373..000000000 --- a/examples/F90/bufr_read_header.f90 +++ /dev/null @@ -1,55 +0,0 @@ -! -!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. -! -! -! FOTRAN 90 Implementation: bufr_read_header -! -! Description: how to read the header of BUFR messages. -! -! -program bufr_read_header -use eccodes -implicit none -integer :: ifile -integer :: iret -integer :: ibufr -integer(kind=4) :: centre,subcentre -integer(kind=4) :: masterversion,localversion -integer(kind=4) :: numberofsubsets - - call codes_open_file(ifile,'../../data/bufr/aaen_55.bufr','r') - -! the first bufr message is loaded from file -! igrib is the grib id to be used in subsequent calls - call codes_bufr_new_from_file(ifile,ibufr,iret) - -! get and print some keys form the BUFR header - - call codes_get(ibufr,'centre',centre); - write(*,*) ' centre=',centre - - call codes_get(ibufr,'subCentre',subcentre) - write(*,*) ' subCentre=',subcentre - - call codes_get(ibufr,'masterTablesVersionNumber',masterversion) - write(*,*) ' masterTablesVersionNumbe',masterversion - - call codes_get(ibufr,'localTablesVersionNumber',localversion) - write(*,*) ' localTablesVersionNumber',localversion - - call codes_get(ibufr,'numberOfSubsets',numberofsubsets) - write(*,*) ' numberOfSubsets',numberofsubsets - - call codes_release(ibufr) - -! close file - call codes_close_file(ifile) - - -end program bufr_read_header diff --git a/examples/F90/bufr_read_header.sh b/examples/F90/bufr_read_header.sh deleted file mode 100755 index 99a2b96fc..000000000 --- a/examples/F90/bufr_read_header.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/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 - -REDIRECT=/dev/null - -${examples_dir}/f_bufr_read_header 2> $REDIRECT > $REDIRECT - diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index 2a0183fec..e48269468 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -22,7 +22,6 @@ foreach( tool ${test_bins} ) list( APPEND ptools p_${tool} ) endforeach() - # Now add each test ################################################# list( APPEND tests @@ -40,7 +39,7 @@ list( APPEND tests set_missing binary_message set_bitmap - bufr_read_header + bufr_print_header ) foreach( test ${tests} ) ecbuild_add_test( TARGET p_${test}_test diff --git a/examples/python/Makefile.am b/examples/python/Makefile.am index 43bb39a4d..59ecd9e68 100644 --- a/examples/python/Makefile.am +++ b/examples/python/Makefile.am @@ -2,7 +2,7 @@ if WITH_PYTHON AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ TESTS = clone.sh count_messages.sh get.sh index.sh iterator.sh keys_iterator.sh multi_write.sh nearest.sh print_data.sh \ - samples.sh set.sh set_missing.sh binary_message.sh set_bitmap.sh bufr_read_header.sh + samples.sh set.sh set_missing.sh binary_message.sh set_bitmap.sh bufr_print_header.sh TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir) PYTHON=$(PYTHON) noinst_PROGRAMS = p_keys_iterator p_print_data p_iterator p_count_messages @@ -16,6 +16,6 @@ DEPENDENCIES = $(LDADD) EXTRA_DIST = $(TESTS) include.sh clone.py count_messages.py get.py index.py iterator.py keys_iterator.py multi_write.py \ nearest.py print_data.py samples.py set.py set_missing.py binary_message.py set_pv.py set_bitmap.py \ - bufr_read_header.py \ + bufr_print_header.py \ CMakeLists.txt include.ctest.sh.in endif diff --git a/examples/python/bufr_read_header.py b/examples/python/bufr_print_header.py similarity index 75% rename from examples/python/bufr_read_header.py rename to examples/python/bufr_print_header.py index 80de4f6f1..ecaef59f6 100644 --- a/examples/python/bufr_read_header.py +++ b/examples/python/bufr_print_header.py @@ -11,26 +11,35 @@ import sys from eccodes import * -INPUT='../../data/bufr/aaen_55.bufr' +INPUT='../../data/bufr/syno_multi.bufr' VERBOSE=1 # verbose error reporting def example(): f = open(INPUT) keys = [ + 'dataCategory', + 'dataSubCategory', + 'typicalDate', 'centre', 'subCentre', - 'masterTableVersionNumber', + 'masterTablesVersionNumber', + 'localTablesVersionNumber', 'numberOfSubsets', ] + cnt=0 while 1: - gid = codes_new_from_file(f) + gid = codes_bufr_new_from_file(f) if gid is None: break + print "message: %s" % cnt + for key in keys: if not codes_is_defined(gid,key): raise Exception("Key was not defined") - print '%s=%s' % (key,codes_get(gid,key)) + print ' %s: %s' % (key,codes_get(gid,key)) + + cnt+=1 codes_release(gid) diff --git a/examples/python/bufr_print_header.sh b/examples/python/bufr_print_header.sh new file mode 100755 index 000000000..1b0ceec0b --- /dev/null +++ b/examples/python/bufr_print_header.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +. ./include.sh + +#----------------------------------------------------- +# Test reading the header only from a BUFR +# file with multiple messages +#---------------------------------------------------- + +#The bufr filename is hardcoded in the python example +f=${data_dir}"/bufr/syno_multi.bufr" +fRef=$f".header.ref" +fRes=$f".header.test.p" +REDIRECT=/dev/null + +#Write the values into a file and compare with reference +$PYTHON bufr_print_header.py 2> $REDIRECT > $fRes + +#We compare output to the reference by ignoring the whitespaces +diff -w $fRef $fRes >$REDIRECT 2> $REDIRECT + +#cat $fRes + +#Clean up +rm -f $fRes diff --git a/examples/python/bufr_read_header.sh b/examples/python/bufr_read_header.sh deleted file mode 100755 index ff43b6c0d..000000000 --- a/examples/python/bufr_read_header.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -. ./include.sh - -REDIRECT=/dev/null -$PYTHON bufr_read_header.py - -#2> $REDIRECT > $REDIRECT - -# Rerun test with no type check decorator (See GRIB-51) -#export GRIB_API_PYTHON_NO_TYPE_CHECKS=1 -#$PYTHON bufr_read_header.py 2> $REDIRECT > $REDIRECT