Merge branch 'eccodes' of ssh://software.ecmwf.int:7999/GRIB/grib_api into eccodes

This commit is contained in:
Shahram Najm 2015-02-06 14:49:29 +00:00
commit 5e1b47a639
13 changed files with 283 additions and 18 deletions

View File

@ -37,6 +37,7 @@ list( APPEND test_bins
bufr_get_keys
bufr_print_header
bufr_print_data
bufr_set_keys
bufr_subset
)
foreach( tool ${test_bins} )
@ -71,6 +72,7 @@ list( APPEND tests
bufr_get_keys
bufr_print_header
bufr_print_data
bufr_set_keys
bufr_subset
)
foreach( test ${tests} )

View File

@ -4,14 +4,15 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@
TESTS = iterator.sh get.sh print_data.sh set.sh keys_iterator.sh multi.sh multi_write.sh \
precision.sh list.sh large_grib1.sh get_data.sh sections_copy.sh set_missing.sh clone.sh set_pv.sh \
check_gaussian_grids.sh \
bufr_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_print_header.sh bufr_print_data.sh bufr_subset.sh
bufr_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_print_header.sh bufr_print_data.sh \
bufr_set_keys.sh bufr_subset.sh
noinst_PROGRAMS = nearest set_bitmap iterator get print_data set set_missing keys_iterator \
set_data mars_param values_check box multi multi2 multi_write precision \
set_pv list sections_copy large_grib1 get_data iterator_bitmap clone new_sample \
check_gaussian_grid ensemble_index points \
bufr_clone bufr_expanded bufr_get_keys bufr_print_header bufr_print_data \
bufr_subset
bufr_get_keys bufr_subset
#bin_PROGRAMS = points
box_SOURCES = box.c
@ -45,6 +46,7 @@ bufr_expanded_SOURCES = bufr_expanded.c
bufr_get_keys_SOURCES = bufr_get_keys.c
bufr_print_header_SOURCES = bufr_print_header.c
bufr_print_data_SOURCES = bufr_print_data.c
bufr_set_keys_SOURCES = bufr_set_keys.c
bufr_subset_SOURCES = bufr_subset.c
INCLUDES = -I$(top_builddir)/src

View File

@ -13,8 +13,8 @@
label="bufr_clone_test_c"
#Prepare tmp file
fTmp=${label}.cloned
rm -f $fTmp | true
fBufrTmp=${label}.cloned.bufr
rm -f $fBufrTmp | true
#We clone a bufr file with multiple messages
f=${data_dir}/bufr/syno_multi.bufr
@ -22,11 +22,11 @@ f=${data_dir}/bufr/syno_multi.bufr
REDIRECT=/dev/null
#Clone the bufr messages
${examples_dir}/bufr_clone $f $fTmp >$REDIRECT 2> $REDIRECT
${examples_dir}/bufr_clone $f $fBufrTmp >$REDIRECT 2> $REDIRECT
#Compare clone to the original
set +e
${tools_dir}/bufr_compare $f $fTmp >$REDIRECT 2> $REDIRECT
${tools_dir}/bufr_compare $f $fBufrTmp >$REDIRECT 2> $REDIRECT
#Check if clone is different
if [ $? -eq 0 ]; then
@ -37,8 +37,8 @@ fi
set -e
#Check if clone has the same number of messages
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fTmp` ]
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fBufrTmp` ]
#Clean up
rm -f ${fTmp} | true
rm -f ${fBufrTmp} | true

View File

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

104
examples/C/bufr_set_keys.c Normal file
View File

@ -0,0 +1,104 @@
/*
* 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.
*/
/*
* C Implementation: bufr_set_keys
*
* Description: how to set different type of keys from BUFR messages.
*
*/
#include "eccodes.h"
void usage(char* prog) {
printf("usage: %s infile\n",prog);
exit(1);
}
int main(int argc,char* argv[])
{
FILE* in = NULL;
FILE* out = NULL;
/* message handle. Required in all the eccodes calls acting on a message.*/
codes_handle* h=NULL;
long longVal;
double doubleVal;
int i, err=0;
int cnt=0;
size_t size = 0;
char* infile = "../../data/bufr/syno_multi.bufr";
const void *buffer = NULL;
if (argc != 2) {
usage(argv[0]);
return 1;
}
in = fopen(infile,"r");
out = fopen(argv[1],"w");
if (!in || !out) {
perror("ERROR: unable to open files");
fclose(out);
fclose(in);
return 1;
}
/* loop over the messages in the bufr file */
while ((h = bufr_new_from_file(NULL,in,&err)) != NULL || err != CODES_SUCCESS)
{
if (h == NULL) {
printf("Error: unable to create handle for message %d\n",cnt);
cnt++;
continue;
}
printf("message: %d\n",cnt);
/* we need to instruct ecCodes to expand the descriptors
i.e. unpack the data values */
/*CODES_CHECK(codes_set_long(h,"unpack",1),0);*/
/* This is the place where you may wish to modify the message*/
/*E.g. we change the centre and 2m temperature */
/* set centre */
longVal=222;
CODES_CHECK(codes_set_long(h, "centre", longVal),0);
printf(" set centre to: %ld\n",longVal);
/* check centre */
CODES_CHECK(codes_get_long(h,"centre",&longVal),0);
printf(" centre's new value is: %ld\n",longVal);
/*doubleVal=240.+i*2.;
CODES_CHECK(codes_set_double(h,"airTemperatureAt2M",doubleVal),0);
printf(" set airTemperatureAt2M to: %f\n",doubleVal);*/
/* get the modified message in a buffer */
CODES_CHECK(codes_get_message(h,&buffer,&size),0);
/* write the buffer to a file */
if(fwrite(buffer,1,size,out) != size) {
perror(argv[0]);
return 1;
}
/* delete handle */
codes_handle_delete(h);
cnt++;
}
fclose(in);
return 0;
}

46
examples/C/bufr_set_keys.sh Executable file
View File

@ -0,0 +1,46 @@
#!/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_set_keys_test_c"
#Define tmp file
fBufrTmp=${label}.tmp.bufr
rm -f $fBufrTmp | true
#We check "syno_multi.bufr". The path is
#hardcoded in the example
f=${data_dir}/bufr/syno_multi.bufr
REDIRECT=/dev/null
#
${examples_dir}/bufr_set_keys $fBufrTmp 2> $REDIRECT > $REDIRECT
#Compare modified to the original
set +e
${tools_dir}/bufr_compare $f $fBufrTmp >$REDIRECT 2> $REDIRECT
#Check if modified is different
if [ $? -eq 0 ]; then
echo "cloning produced identical files " >&2
exit 1
fi
set -e
#Check if modified has the same number of messages
[ `${tools_dir}/bufr_count $f` -eq `${tools_dir}/bufr_count ${fBufrTmp}` ]
#Clean up
rm -f $fBufrTmp | true

View File

@ -55,7 +55,7 @@ int main(int argc,char* argv[])
/* we need to instruct ecCodes to expand all the descriptors i.e. unpack the data values */
CODES_CHECK(codes_set_long(h,"unpack",1),0);
/* find ou the number of subsets */
/* find out the number of subsets */
CODES_CHECK(codes_get_long(h,"numberOfSubsets",&numberOfSubsets),0);
printf(" numberOfSubsets: %ld\n",numberOfSubsets);

View File

@ -34,6 +34,7 @@ list( APPEND tests
bufr_get_keys
bufr_print_header
bufr_print_data
bufr_set_keys
)
# Simplify tests: no need to build executable and then test. All in one

View File

@ -4,13 +4,13 @@ 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_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_print_header.sh bufr_print_data.sh
bufr_clone.sh bufr_expanded.sh bufr_get_keys.sh bufr_print_header.sh bufr_print_data.sh f_bufr_set_keys.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_clone f_bufr_expanded f_bufr_get_keys \
f_bufr_print_header f_bufr_print_data
f_bufr_print_header f_bufr_print_data f_bufr_set_keys
f_index_SOURCES=index.f90
f_copy_message_SOURCES=copy_message.f90
@ -42,6 +42,7 @@ f_bufr_expanded_SOURCES=bufr_expanded.f90
f_bufr_get_keys_SOURCES=bufr_get_keys.f90
f_bufr_print_header_SOURCES=bufr_print_header.f90
f_bufr_print_data_SOURCES=bufr_print_data.f90
f_bufr_set_keys_SOURCES=bufr_set_keys.f90
INCLUDES = -I$(top_builddir)/src

View File

@ -13,8 +13,8 @@
label="bufr_clone_test_f"
#Prepare tmp file
fTmp=${label}.clone.bufr
rm -f $fTmp | true
fBufrTmp=${label}.clone.bufr
rm -f $fBufrTmp | true
#We clone a bufr file with multiple messages.
f=${data_dir}/bufr/syno_multi.bufr
@ -26,7 +26,7 @@ ${examples_dir}/f_bufr_clone >$REDIRECT 2> $REDIRECT
#Compare clone to the original
set +e
${tools_dir}/bufr_compare $f $fTmp >$REDIRECT 2> $REDIRECT
${tools_dir}/bufr_compare $f $fBufrTmp >$REDIRECT 2> $REDIRECT
#Check if clone is different
if [ $? -eq 0 ]; then
@ -37,7 +37,7 @@ fi
set -e
#Check if clone has the same number of messages
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fTmp` ]
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count $fBufrTmp` ]
#Clean up
rm -f ${fTmp} | true
rm -f ${fBufrTmp} | true

View File

@ -99,7 +99,6 @@ character(len=9) :: typicalDate
call grib_get(ibufr,'typicalDate',typicalDate)
write(*,*) ' typicalDate:',typicalDate
! free arrays
deallocate(values)
deallocate(descriptors)

View File

@ -0,0 +1,67 @@
! 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_set_keys
!
! Description: Description: how to set different type of keys from BUFR messages.
!
!
program bufr_set_keys
use eccodes
implicit none
integer :: err,i,iret
integer :: infile,outfile
integer :: ibufr
integer :: count=0
integer(kind=4) :: centre, centreNew
double precision, dimension(:,:), allocatable :: field2D
! open input file
call codes_open_file(infile,'../../data/bufr/syno_multi.bufr','r')
! open output file
call codes_open_file(outfile,'bufr_set_keys_test_f.tmp.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,iret)
do while (iret/=CODES_END_OF_FILE)
write(*,*) 'message: ',count
! This is the place where you may wish to modify the message
! E.g. we change the centre and 2m temperature
! set centre
centre=222
call codes_set(ibufr,'centre',222)
write(*,*) ' set centre to:',centre
! check centre's new value
centreNew=0
call codes_get(ibufr,'centre',centreNew)
write(*,*) ' centre''s new value:',centreNew
! write modified message to a file
call codes_write(ibufr,outfile)
! relase the handle
call codes_release(ibufr)
! next message from source
call codes_bufr_new_from_file(infile,ibufr,iret)
count=count+1
end do
call codes_close_file(infile)
call codes_close_file(outfile)
end program bufr_set_keys

43
examples/F90/bufr_set_keys.sh Executable file
View File

@ -0,0 +1,43 @@
#!/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_set_keys_test_f"
#Prepare tmp file
fBufrTmp=${label}.tmp.bufr
rm -f $fBufrTmp | true
#We clone a bufr file with multiple messages.
f=${data_dir}/bufr/syno_multi.bufr
REDIRECT=/dev/null
#The input ($f) and output ($fBufrTmp) are hardcoded in the f90 example!!!
${examples_dir}/f_bufr_set_keys >$REDIRECT 2> $REDIRECT
#Compare modified file to the original
set +e
${tools_dir}/bufr_compare $f $fBufrTmp >$REDIRECT 2> $REDIRECT
#Check if they are different
if [ $? -eq 0 ]; then
echo "cloning produced identical files " >&2
exit 1
fi
set -e
#Check if modified file has the same number of messages
[ `${tools_dir}/bufr_count $f` = `${tools_dir}/bufr_count ${fBufrTmp}` ]
#Clean up
rm -f ${fBufrTmp} | true