Make C, Fortran and Python examples ECC-15

This commit is contained in:
Sandor Kertesz 2015-03-26 13:08:22 +00:00
parent 57048c342d
commit 0443f8e0f4
9 changed files with 151 additions and 27 deletions

View File

@ -23,7 +23,7 @@ rm -f $fTmp | true
REDIRECT=/dev/null
#Write the values into a file and compare with reference
${examples_dir}c_bufr_subset 2> $REDIRECT > $fTmp
${examples_dir}c_bufr_subset #2> $REDIRECT > $fTmp
#TODO: add a proper check when subsets are properly implemented

View File

@ -41,7 +41,6 @@ character(len=9) :: typicalDate
! i.e. unpack the data values
call codes_set(ibufr,"unpack",1);
! get as character
call codes_get(ibufr,'typicalDate',typicalDate)
write(*,*) ' typicalDate:',typicalDate
@ -58,7 +57,6 @@ character(len=9) :: typicalDate
call codes_get(ibufr,'airTemperatureAt2M',t2m);
write(*,*) ' airTemperatureAt2M:',t2m
! ---- array of integer ----------------
! get the exapanded descriptors

View File

@ -24,7 +24,7 @@ rm -f $fTmp | true
REDIRECT=/dev/null
#Write the key values into a file
${examples_dir}/f_bufr_read_scatterometer #2> $REDIRECT > $fTmp
${examples_dir}/f_bufr_read_scatterometer 2> $REDIRECT > $fTmp
#TODO: check the results

View File

@ -45,6 +45,7 @@ list( APPEND tests
bufr_get_keys
bufr_keys_iterator
bufr_read_header
bufr_read_scatterometer
bufr_read_synop
bufr_read_temp
bufr_set_keys

View File

@ -6,7 +6,7 @@ TESTS = grib_clone.sh count_messages.sh grib_get_keys.sh grib_index.sh grib_iter
samples.sh grib_set_keys.sh set_missing.sh binary_message.sh grib_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
bufr_attributes.sh get_product_kind.sh bufr_read_temp.sh bufr_read_scatterometer.sh
TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir) PYTHON=$(PYTHON)
noinst_PROGRAMS = p_grib_keys_iterator p_grib_print_data p_grib_iterator p_count_messages
@ -25,6 +25,6 @@ EXTRA_DIST = $(TESTS) include.sh grib_clone.py count_messages.py grib_get_keys.p
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 \
get_product_kind.py bufr_read_temp.py bufr_read_scatterometer.py \
CMakeLists.txt include.ctest.sh.in
endif

View File

@ -0,0 +1,101 @@
# 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.
#
# Python implementation: bufr_read_scatterometer
#
# Description: how to read data for a given beam from scatterometer BUFR messages.
#
# Please note that scatterometer data can be encoded in various ways in BUFR. Therefore the code
# below might not work directly for other types of messages than the one used in the
# example. It is advised to use bufr_dump first to understand the structure of these messages.
#
import traceback
import sys
from eccodes import *
INPUT='../../data/bufr/asca_139.bufr'
VERBOSE=1 # verbose error reporting
def example():
# open bufr file
f = open(INPUT)
cnt=0
# loop for the messages in the file
while 1:
# get handle for message
gid = codes_bufr_new_from_file(f)
if gid is None: break
print "message: %s" % cnt
# we need to instruct ecCodes to expand all the descriptors
# i.e. unpack the data values
codes_set(gid,'unpack',1)
# The BUFR file contains a single message with 2016 subsets in a compressed form.
# It means each subset has exactly the same structure: they store one location with
# several beams and one backscatter value in each beam.
#
# To print the backScatter values for beamIdentifier=2 from all the subsets
# we will simply access the key by condition (see below)
# Get the total number of subsets.
numObs=codes_get(gid,"numberOfSubsets")
print ' Number of values: %ld' % (numObs)
#Get latitude (for all the subsets)
lat=codes_get_double_array(gid,"latitude")
#Get longitude (for all the subsets)
lon=codes_get_double_array(gid,"longitude")
#Get backScatter for beam two. We use an access by condition for this key.
#(for all the subsets)
bscat=codes_get_double_array(gid,"/beamIdentifier=2/backscatter")
# Check that all arrays are same size
if len(lat) != numObs or len(lon) != numObs or len(bscat) != numObs :
print 'inconsistent array dimension'
return 1
# Print the values
print "pixel lat lon backscatter"
print "-------------------------------"
for i in xrange(numObs):
print "%3d %.2f %.2f %.2f" % (i+1,lat[i],lon[i],bscat[i])
cnt+=1
# delete handle
codes_release(gid)
# close the file
f.close()
def main():
try:
example()
except CodesInternalError,err:
if VERBOSE:
traceback.print_exc(file=sys.stderr)
else:
print >>sys.stderr,err.msg
return 1
if __name__ == "__main__":
sys.exit(main())

View File

@ -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
#Define a common label for all the tmp files
label="bufr_read_scatterometer_p"
#Define tmp file
fTmp=${label}.tmp.txt
rm -f $fTmp | true
#We check "asca_1391.bufr". The path is
#hardcoded in the example
REDIRECT=/dev/null
#Write the key values into a file
$PYTHON bufr_read_scatterometer.py 2> $REDIRECT > $fTmp
#TODO: check the results
#cat $fTmp
#Clean up
rm -f $fTmp | true

View File

@ -62,35 +62,23 @@ def example():
print ' Number of temperature significant levels %ld' % (numSigT)
# Get pressure
sigt_pres=codes_get_double_array(gid,"/verticalSoundingSignificance=4/pressure")
# Get gepotential
sigt_geo=codes_get_double_array(gid,"/verticalSoundingSignificance=4/geopotential")
if len(sigt_geo) != numSigT :
print "inconstitent number of geopotential values found!"
return 1
# Get temperature
sigt_t=codes_get_double_array(gid,"/verticalSoundingSignificance=4/airTemperature")
if len(sigt_t) != numSigT :
print "inconstitent number of temprature values found!"
return 1
# Get dew point
sigt_td=codes_get_double_array(gid,"/verticalSoundingSignificance=4/dewpointTemperature")
if len(sigt_td) != numSigT:
print "inconstitent number of dewpoint temperature values found!"
# Check that all arrays are same size
if len(sigt_pres) != numSigT or len(sigt_geo) != numSigT or len(sigt_t) != numSigT or len(sigt_td) != numSigT :
print 'inconsistent array dimension'
return 1
# Print the values
print "lev pres geo t td"
print "-------------------------------"

View File

@ -31,11 +31,13 @@ def example():
if gid is None: break
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))
if codes_is_defined(gid,"A_very_silly_girl"): raise Exception("Key was defined")
try:
print ' %s: %s' % (key,codes_get(gid,key))
except CodesInternalError,err:
print 'Error with key="%s" : %s' % (key,err.msg)
if codes_is_defined(gid,"A_very_silly_key"): raise Exception("Key was defined")
print 'There are %d values, average is %f, min is %f, max is %f' % (
codes_get_size(gid,'values'),
codes_get(gid,'average'),