ECC-221: add tests for 'new_from_message' functions (Part 1)

This commit is contained in:
Shahram Najm 2016-03-29 18:56:11 +01:00
parent 128d233f3f
commit cbe07a5456
5 changed files with 95 additions and 13 deletions

View File

@ -10,6 +10,7 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_S
list( APPEND tests
grib_index
copy_message
bufr_copy_message
grib_get_keys
get_data
get_pl

View File

@ -0,0 +1,56 @@
! Copyright 2005-2016 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 copy a BUFR message in memory
!
!
!
program copy
use eccodes
implicit none
integer :: err, sub_centre
integer(kind=kindOfSize) :: byte_size
integer :: infile,outfile
integer :: ibufr_in
integer :: ibufr_out
character(len=1), dimension(:), allocatable :: message
character(len=32) :: product_kind
call codes_open_file(infile,'../../data/bufr/syno_1.bufr', 'r')
call codes_open_file(outfile,'out.copy.bufr', 'w')
! A new BUFR message is loaded from file
! ibufr_in is the BUFR id to be used in subsequent calls
call codes_bufr_new_from_file(infile, ibufr_in)
call codes_get_message_size(ibufr_in, byte_size)
allocate(message(byte_size), stat=err)
call codes_copy_message(ibufr_in, message)
call codes_new_from_message(ibufr_out, message)
call codes_get(ibufr_out, 'kindOfProduct', product_kind)
write(*,*) 'kindOfProduct=',product_kind
sub_centre=80
call codes_set(ibufr_out,'bufrHeaderSubCentre', sub_centre)
! Write message to a file
call codes_write(ibufr_out, outfile)
call codes_release(ibufr_out)
call codes_release(ibufr_in)
call codes_close_file(infile)
call codes_close_file(outfile)
deallocate(message)
end program copy

View File

@ -0,0 +1,18 @@
#!/bin/sh
# Copyright 2005-2016 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
INPUT="../../data/bufr/syno_1.bufr"
OUTPUT=out.copy.bufr
${examples_dir}eccodes_f_bufr_copy_message > /dev/null
${tools_dir}/bufr_compare -b bufrHeaderSubCentre $INPUT $OUTPUT
rm -f $OUTPUT

View File

@ -8,7 +8,7 @@
!
!
!
! Description: how to copy a message in memory
! Description: how to copy a GRIB message in memory
!
!
!
@ -21,32 +21,34 @@ program copy
integer :: igrib_in
integer :: igrib_out
character(len=1), dimension(:), allocatable :: message
character(len=32) :: product_kind
call codes_open_file(infile,'../../data/constant_field.grib1','r')
call codes_open_file(outfile,'out.copy.grib1','w')
! a new grib message is loaded from file
! igrib is the grib id to be used in subsequent calls
call codes_grib_new_from_file(infile,igrib_in)
! A new GRIB message is loaded from file
! igrib_in is the GRIB id to be used in subsequent calls
call codes_grib_new_from_file(infile, igrib_in)
call codes_get_message_size(igrib_in, byte_size)
allocate(message(byte_size), stat=err)
call codes_copy_message(igrib_in,message)
call codes_copy_message(igrib_in, message)
call codes_new_from_message(igrib_out, message)
centre=80
call codes_set(igrib_out,"centre",centre)
call codes_get(igrib_out, 'kindOfProduct', product_kind)
write(*,*) 'kindOfProduct=',product_kind
! write messages to a file
call codes_write(igrib_out,outfile)
centre=80
call codes_set(igrib_out, 'centre', centre)
! Write message to a file
call codes_write(igrib_out, outfile)
call codes_release(igrib_out)
call codes_release(igrib_in)
call codes_close_file(infile)
call codes_close_file(outfile)
deallocate(message)

View File

@ -9,5 +9,10 @@
. ./include.sh
INPUT="../../data/constant_field.grib1"
OUTPUT=out.copy.grib1
${examples_dir}eccodes_f_copy_message > /dev/null
rm -f out.copy.grib1
${tools_dir}/grib_compare -b centre $INPUT $OUTPUT
rm -f $OUTPUT