mirror of https://github.com/ecmwf/eccodes.git
Add bufr_clone F90 example ECC-15
This commit is contained in:
parent
5791d19cff
commit
e4069a0422
|
@ -50,6 +50,7 @@ int main(int argc, char *argv[])
|
|||
/* loop over the messages in the source bufr and clone them */
|
||||
while ((source_handle = bufr_new_from_file(0,in,&err))!=NULL)
|
||||
{
|
||||
/* clone the current handle */
|
||||
codes_handle *clone_handle = codes_handle_clone(source_handle);
|
||||
|
||||
if (clone_handle == NULL) {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
|
||||
f=${data_dir}/bufr/syno_multi.bufr
|
||||
fTmp=${f}.cloned
|
||||
fTmp=${f}.c.cloned
|
||||
|
||||
REDIRECT=/dev/null
|
||||
|
||||
|
@ -21,6 +21,7 @@ ${examples_dir}/bufr_clone $f $fTmp >$REDIRECT 2> $REDIRECT
|
|||
set +e
|
||||
${tools_dir}/bufr_compare $f $fTmp >$REDIRECT 2> $REDIRECT
|
||||
|
||||
#Check if clone is different
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "cloning produced identical files " >&2
|
||||
exit 1
|
||||
|
@ -28,5 +29,9 @@ fi
|
|||
|
||||
set -e
|
||||
|
||||
#Check if clone has the same number of messages
|
||||
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fTmp` ]
|
||||
|
||||
|
||||
#Clean up
|
||||
rm -f $fTmp
|
||||
|
|
|
@ -29,6 +29,7 @@ list( APPEND tests
|
|||
read_from_file
|
||||
get_set_uuid
|
||||
clone
|
||||
bufr_clone
|
||||
bufr_print_header
|
||||
)
|
||||
|
||||
|
|
|
@ -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_print_header.sh
|
||||
bufr_clone.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_print_header
|
||||
f_copy_namespace f_get_set_uuid f_set_gvc f_clone f_bufr_clone f_bufr_print_header
|
||||
|
||||
f_index_SOURCES=index.f90
|
||||
f_copy_message_SOURCES=copy_message.f90
|
||||
|
@ -36,6 +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_clone_SOURCES=bufr_clone.f90
|
||||
f_bufr_print_header_SOURCES=bufr_print_header.f90
|
||||
|
||||
INCLUDES = -I$(top_builddir)/src
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
! 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.
|
||||
!
|
||||
!
|
||||
!
|
||||
! Description: how to create a new BUFR message by cloning
|
||||
! an existing message.
|
||||
!
|
||||
!
|
||||
!
|
||||
program bufr_clone
|
||||
use eccodes
|
||||
implicit none
|
||||
integer :: err,i,iret
|
||||
integer :: nx, ny
|
||||
integer :: infile,outfile
|
||||
integer :: ibufr_in
|
||||
integer :: ibufr_out
|
||||
character(len=2) :: step
|
||||
double precision, dimension(:,:), allocatable :: field2D
|
||||
|
||||
!open source file
|
||||
call codes_open_file(infile,'../../data/bufr/syno_multi.bufr','r')
|
||||
|
||||
! open target file
|
||||
call codes_open_file(outfile,'out.clone.f.bufr','w')
|
||||
|
||||
! 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(infile,ibufr_in,iret)
|
||||
|
||||
do while (iret/=CODES_END_OF_FILE)
|
||||
|
||||
! clone the current handle
|
||||
call codes_clone(ibufr_in, ibufr_out)
|
||||
|
||||
! This is the place where you may wish to modify the clone
|
||||
! E.g. we change the centre
|
||||
call codes_set(ibufr_out,'centre',250)
|
||||
|
||||
! write cloned messages to a file
|
||||
call codes_write(ibufr_out,outfile)
|
||||
|
||||
! relase the clone's handle
|
||||
call codes_release(ibufr_out)
|
||||
|
||||
! relase the sources 's handle
|
||||
call codes_release(ibufr_in)
|
||||
|
||||
! next message from source
|
||||
call codes_bufr_new_from_file(infile,ibufr_in,iret)
|
||||
|
||||
end do
|
||||
|
||||
call codes_close_file(infile)
|
||||
call codes_close_file(outfile)
|
||||
|
||||
end program bufr_clone
|
|
@ -0,0 +1,36 @@
|
|||
#!/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
|
||||
|
||||
#These files are hardcoded in the f90 example
|
||||
f=${data_dir}/bufr/syno_multi.bufr #input
|
||||
fTmp=out.clone.f.bufr #output
|
||||
|
||||
REDIRECT=/dev/null
|
||||
|
||||
#Write the values into a file and compare with reference
|
||||
${examples_dir}/f_bufr_clone >$REDIRECT 2> $REDIRECT
|
||||
|
||||
#Check if clone is different
|
||||
set +e
|
||||
${tools_dir}/bufr_compare $f $fTmp >$REDIRECT 2> $REDIRECT
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "cloning produced identical files " >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
#Check if clone has the same number of messages
|
||||
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fTmp` ]
|
||||
|
||||
#Clean up
|
||||
rm -f $fTmp
|
Loading…
Reference in New Issue