mirror of https://github.com/ecmwf/eccodes.git
Make C, Fortran and Python examples ECC-15
This commit is contained in:
parent
34592d71c5
commit
9cebda8b47
|
@ -15,6 +15,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Please note that SYNOP reports can be encoded in various ways in BUFR. Therefore the code
|
||||
* below might not work directly for other types of SYNOP messages than the one used in the
|
||||
* example.
|
||||
*/
|
||||
|
||||
|
||||
#include "eccodes.h"
|
||||
|
||||
void usage(char* prog) {
|
||||
|
@ -55,20 +62,35 @@ int main(int argc,char* argv[])
|
|||
/* we need to instruct ecCodes to unpack the data values */
|
||||
CODES_CHECK(codes_set_long(h,"unpack",1),0);
|
||||
|
||||
/* read and print some data values. This example was written for a SYNOP
|
||||
BUFR file!! */
|
||||
|
||||
/* station id*/
|
||||
CODES_CHECK(codes_get_long(h,"blockNumber",&longVal),0);
|
||||
printf(" blockNumber: %ld\n",longVal);
|
||||
|
||||
CODES_CHECK(codes_get_long(h,"stationNumber",&longVal),0);
|
||||
printf(" stationNumber: %ld\n",longVal);
|
||||
|
||||
/* in the current BUFR message this key represents the 2m temperature.
|
||||
it might not be available in other type of SYNOP messages */
|
||||
/* location*/
|
||||
CODES_CHECK(codes_get_double(h,"latitude",&doubleVal),0);
|
||||
printf(" latitude: %f\n",doubleVal);
|
||||
|
||||
CODES_CHECK(codes_get_double(h,"longitude",&doubleVal),0);
|
||||
printf(" longitude: %f\n",doubleVal);
|
||||
|
||||
/* 2m temperature */
|
||||
CODES_CHECK(codes_get_double(h,"airTemperatureAt2M",&doubleVal),0);
|
||||
printf(" airTemperatureAt2M %f\n",doubleVal);
|
||||
|
||||
/* 2m dewpoint temperature */
|
||||
CODES_CHECK(codes_get_double(h,"dewpointTemperatureAt2M",&doubleVal),0);
|
||||
printf(" dewpointTemperatureAt2M %f\n",doubleVal);
|
||||
|
||||
/* 10 wind */
|
||||
CODES_CHECK(codes_get_double(h,"windSpeedAt10M",&doubleVal),0);
|
||||
printf(" windSpeedAt10M %f\n",doubleVal);
|
||||
|
||||
CODES_CHECK(codes_get_double(h,"windDirectionAt10M",&doubleVal),0);
|
||||
printf(" windDirectionAt10M %f\n",doubleVal);
|
||||
|
||||
/* delete handle */
|
||||
codes_handle_delete(h);
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ list( APPEND tests
|
|||
bufr_expanded
|
||||
bufr_get_keys
|
||||
bufr_keys_iterator
|
||||
bufr_print_header
|
||||
bufr_print_data
|
||||
bufr_read_header
|
||||
bufr_read_synop
|
||||
bufr_read_temp
|
||||
bufr_set_keys
|
||||
bufr_subset
|
||||
|
|
|
@ -4,14 +4,14 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ @FORCE_32_CFLAGS@
|
|||
TESTS = copy_message.sh grib_get_keys.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_attributes.sh bufr_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_print_header.sh bufr_print_data.sh bufr_set_keys.sh \
|
||||
bufr_attributes.sh bufr_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_read_header.sh bufr_read_synop.sh bufr_set_keys.sh \
|
||||
bufr_keys_iterator.sh bufr_subset.sh get_product_kind.sh bufr_read_temp.sh
|
||||
|
||||
noinst_PROGRAMS = f_index f_copy_message f_grib_get_keys 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_grib_clone f_bufr_clone f_bufr_expanded f_bufr_get_keys \
|
||||
f_bufr_print_header f_bufr_print_data f_bufr_set_keys f_bufr_keys_iterator f_bufr_subset f_bufr_attributes \
|
||||
f_bufr_read_header f_bufr_read_synop f_bufr_set_keys f_bufr_keys_iterator f_bufr_subset f_bufr_attributes \
|
||||
f_get_product_kind f_bufr_read_temp
|
||||
|
||||
f_index_SOURCES=index.f90
|
||||
|
@ -44,8 +44,8 @@ f_bufr_clone_SOURCES=bufr_clone.f90
|
|||
f_bufr_expanded_SOURCES=bufr_expanded.f90
|
||||
f_bufr_get_keys_SOURCES=bufr_get_keys.f90
|
||||
f_bufr_keys_iterator_SOURCES=bufr_keys_iterator.f90
|
||||
f_bufr_print_header_SOURCES=bufr_print_header.f90
|
||||
f_bufr_print_data_SOURCES=bufr_print_data.f90
|
||||
f_bufr_read_header_SOURCES=bufr_read_header.f90
|
||||
f_bufr_read_synop_SOURCES=bufr_read_synop.f90
|
||||
f_bufr_read_temp_SOURCES=bufr_read_temp.f90
|
||||
f_bufr_set_keys_SOURCES=bufr_set_keys.f90
|
||||
f_bufr_subset_SOURCES=bufr_subset.f90
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
! Description: how to read the header of BUFR messages.
|
||||
!
|
||||
!
|
||||
program bufr_print_header
|
||||
program bufr_read_header
|
||||
use eccodes
|
||||
implicit none
|
||||
integer :: ifile
|
||||
|
@ -74,4 +74,4 @@ integer(kind=4) :: numberofsubsets
|
|||
call codes_close_file(ifile)
|
||||
|
||||
|
||||
end program bufr_print_header
|
||||
end program bufr_read_header
|
|
@ -10,7 +10,7 @@
|
|||
. ./include.sh
|
||||
|
||||
#Define a common label for all the tmp files
|
||||
label="bufr_print_header_test_f"
|
||||
label="bufr_read_header_test_f"
|
||||
|
||||
#Prepare tmp file
|
||||
fTmp=${label}.tmp.txt
|
||||
|
@ -27,7 +27,7 @@ fRef=${f}.header.ref
|
|||
REDIRECT=/dev/null
|
||||
|
||||
#Write the values into a file and compare with reference
|
||||
${examples_dir}/f_bufr_print_header $f 2> $REDIRECT > $fTmp
|
||||
${examples_dir}/f_bufr_read_header $f 2> $REDIRECT > $fTmp
|
||||
|
||||
#We compare output to the reference by ignoring the whitespaces
|
||||
diff -w $fRef $fTmp >$REDIRECT 2> $REDIRECT
|
|
@ -8,12 +8,18 @@
|
|||
! virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
!
|
||||
!
|
||||
! FOTRAN 90 Implementation: bufr_print_data
|
||||
! FOTRAN 90 Implementation: bufr_read_synop
|
||||
!
|
||||
! Description: how to read data values from BUFR messages.
|
||||
! Description: how to read SYNOP BUFR messages.
|
||||
|
||||
! Please note that SYNOP reports can be encoded in various ways in BUFR. Therefore the code
|
||||
! below might not work directly for other types of SYNOP messages than the one used in the
|
||||
! example.
|
||||
|
||||
|
||||
!
|
||||
!
|
||||
program bufr_print_data
|
||||
program bufr_read_synop
|
||||
use eccodes
|
||||
implicit none
|
||||
integer :: ifile
|
||||
|
@ -21,7 +27,7 @@ integer :: iret
|
|||
integer :: ibufr
|
||||
integer :: count=0
|
||||
integer(kind=4) :: blockNumber,stationNumber
|
||||
real(kind=8) :: t2m
|
||||
real(kind=8) :: lat,lon,t2m,td2m,ws,wdir
|
||||
|
||||
call codes_open_file(ifile,'../../data/bufr/syno_multi.bufr','r')
|
||||
|
||||
|
@ -35,24 +41,42 @@ real(kind=8) :: t2m
|
|||
|
||||
! we need to instruct ecCodes to expand all the descriptors
|
||||
! i.e. unpack the data values
|
||||
call codes_set(ibufr,"unpack",1);
|
||||
call codes_set(ibufr,"unpack",1)
|
||||
|
||||
!read and print some data values. This example was written
|
||||
! for a SYNOP BUFR file!
|
||||
|
||||
! get wmo block number
|
||||
call codes_get(ibufr,'blockNumber',blockNumber);
|
||||
! wmo block number
|
||||
call codes_get(ibufr,'blockNumber',blockNumber)
|
||||
write(*,*) ' blockNumber:',blockNumber
|
||||
|
||||
! get station number
|
||||
call codes_get(ibufr,'stationNumber',stationNumber);
|
||||
! station number
|
||||
call codes_get(ibufr,'stationNumber',stationNumber)
|
||||
write(*,*) ' stationNumber:',stationNumber
|
||||
|
||||
! in the current BUFR message this key represents the 2m temperature.
|
||||
! it might not be available in other type of SYNOP messages
|
||||
! location
|
||||
call codes_get(ibufr,'latitude',lat)
|
||||
write(*,*) ' latitude:',lat
|
||||
|
||||
call codes_get(ibufr,'longitude',lat)
|
||||
write(*,*) ' longitude:',lat
|
||||
|
||||
! 2m temperature
|
||||
call codes_get(ibufr,'airTemperatureAt2M',t2m);
|
||||
write(*,*) ' airTemperatureAt2M:',t2m
|
||||
|
||||
! 2m dewpoint temperature
|
||||
call codes_get(ibufr,'dewpointTemperatureAt2M',td2m);
|
||||
write(*,*) ' dewpointTemperatureAt2M:',td2m
|
||||
|
||||
! 10m wind
|
||||
call codes_get(ibufr,'windSpeedAt10M',ws);
|
||||
write(*,*) ' windSpeedAt10M:',ws
|
||||
|
||||
call codes_get(ibufr,'windDirectionAt10M',wdir);
|
||||
write(*,*) ' windDirectionAt10M',wdir
|
||||
|
||||
|
||||
! release the bufr message
|
||||
call codes_release(ibufr)
|
||||
|
||||
|
@ -67,4 +91,5 @@ real(kind=8) :: t2m
|
|||
call codes_close_file(ifile)
|
||||
|
||||
|
||||
end program bufr_print_data
|
||||
end program bufr_read_synop
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
|
||||
#Define a common label for all the tmp files
|
||||
label="bufr_print_data_test_f"
|
||||
label="bufr_read_synop_test_f"
|
||||
|
||||
#Define tmp file
|
||||
fTmp=${label}".tmp.txt"
|
||||
|
@ -24,7 +24,7 @@ rm -f $fTmp | true
|
|||
REDIRECT=/dev/null
|
||||
|
||||
#Write the values into a file and compare with reference
|
||||
${examples_dir}/f_bufr_print_data 2> $REDIRECT > $fTmp
|
||||
${examples_dir}/f_bufr_read_synop #2> $REDIRECT > $fTmp
|
||||
|
||||
#TODO: check the output
|
||||
|
|
@ -44,8 +44,8 @@ list( APPEND tests
|
|||
bufr_expanded
|
||||
bufr_get_keys
|
||||
bufr_keys_iterator
|
||||
bufr_print_header
|
||||
bufr_print_data
|
||||
bufr_read_header
|
||||
bufr_read_synop
|
||||
bufr_read_temp
|
||||
bufr_set_keys
|
||||
bufr_subset
|
||||
|
|
|
@ -2,7 +2,7 @@ if WITH_PYTHON
|
|||
AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@
|
||||
|
||||
TESTS = grib_clone.sh count_messages.sh grib_get_keys.sh index.sh grib_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_print_header.sh bufr_print_data.sh \
|
||||
samples.sh set.sh set_missing.sh binary_message.sh set_bitmap.sh bufr_read_header.sh bufr_read_synop.sh \
|
||||
bufr_clone.sh bufr_get_keys.sh bufr_set_keys.sh bufr_expanded.sh bufr_keys_iterator.sh bufr_subset.sh \
|
||||
bufr_attributes.sh get_product_kind.sh bufr_read_temp.sh
|
||||
TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir) PYTHON=$(PYTHON)
|
||||
|
@ -19,7 +19,7 @@ DEPENDENCIES = $(LDADD)
|
|||
EXTRA_DIST = $(TESTS) include.sh grib_clone.py count_messages.py grib_get_keys.py index.py grib_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_print_header.py bufr_print_data.py bufr_clone.py bufr_get_keys.py bufr_set_keys.py \
|
||||
bufr_read_header.py bufr_read_synop.py bufr_clone.py bufr_get_keys.py bufr_set_keys.py \
|
||||
bufr_expanded.py bufr_keys_iterator.py bufr_subset.py bufr_attributes.py \
|
||||
get_product_kind.py bufr_read_temp.py \
|
||||
CMakeLists.txt include.ctest.sh.in
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
#
|
||||
# Python implementation: bufr_print_header
|
||||
# Python implementation: bufr_read_header
|
||||
#
|
||||
# Description: how to read the header from BUFR messages.
|
||||
#
|
|
@ -14,12 +14,12 @@ 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
|
||||
$PYTHON bufr_read_header.py 2> $REDIRECT > $fRes
|
||||
|
||||
#We compare output to the reference by ignoring the whitespaces
|
||||
diff -w $fRef $fRes >$REDIRECT 2> $REDIRECT
|
||||
|
||||
#cat $fRes
|
||||
cat $fRes
|
||||
|
||||
#Clean up
|
||||
rm -f $fRes
|
|
@ -7,10 +7,15 @@
|
|||
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
|
||||
#
|
||||
# Python implementation: bufr_print_data
|
||||
# Python implementation: bufr_read_synop
|
||||
#
|
||||
# Description: how to read data values from BUFR messages.
|
||||
#
|
||||
|
||||
#
|
||||
# Please note that SYNOP reports can be encoded in various ways in BUFR. Therefore the code
|
||||
# below might not work directly for other types of SYNOP messages than the one used in the
|
||||
# example.
|
||||
#
|
||||
|
||||
import traceback
|
||||
|
@ -30,7 +35,12 @@ def example():
|
|||
keys = [
|
||||
'blockNumber',
|
||||
'stationNumber',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'airTemperatureAt2M',
|
||||
'dewpointTemperatureAt2M',
|
||||
'windSpeedAt10M',
|
||||
'windDirectionAt10M'
|
||||
]
|
||||
|
||||
cnt=0
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
|
||||
#Define a common label for all the tmp files
|
||||
label="bufr_print_data_test_p"
|
||||
label="bufr_read_synop_test_p"
|
||||
|
||||
#Define tmp file
|
||||
fTmp=${label}".tmp.txt"
|
||||
|
@ -24,7 +24,7 @@ rm -f $fTmp | true
|
|||
REDIRECT=/dev/null
|
||||
|
||||
#Write the values into a file and compare with reference
|
||||
$PYTHON bufr_print_data.py 2> $REDIRECT > $fTmp
|
||||
$PYTHON bufr_read_synop.py #2> $REDIRECT > $fTmp
|
||||
|
||||
#TODO: check the output
|
||||
|
Loading…
Reference in New Issue