mirror of https://github.com/ecmwf/eccodes.git
Make C, Fortran and Python examples ECC-15
This commit is contained in:
parent
80f4d08ab5
commit
e235318c6e
|
@ -37,6 +37,7 @@ list( APPEND test_bins
|
|||
bufr_expanded
|
||||
bufr_get_keys
|
||||
bufr_keys_iterator
|
||||
bufr_missing
|
||||
bufr_print_header
|
||||
bufr_print_data
|
||||
bufr_set_keys
|
||||
|
@ -74,6 +75,7 @@ list( APPEND tests
|
|||
bufr_expanded
|
||||
bufr_get_keys
|
||||
bufr_keys_iterator
|
||||
bufr_missing
|
||||
bufr_print_header
|
||||
bufr_print_data
|
||||
bufr_set_keys
|
||||
|
|
|
@ -5,14 +5,14 @@ TESTS = iterator.sh get.sh print_data.sh set.sh keys_iterator.sh multi.sh multi_
|
|||
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_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_subset.sh bufr_keys_iterator.sh
|
||||
bufr_set_keys.sh bufr_subset.sh bufr_keys_iterator.sh bufr_missing.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_attributes bufr_clone bufr_expanded bufr_get_keys bufr_print_header bufr_print_data \
|
||||
bufr_get_keys bufr_subset bufr_keys_iterator bufr_set_keys
|
||||
bufr_get_keys bufr_subset bufr_keys_iterator bufr_set_keys bufr_missing
|
||||
#bin_PROGRAMS = points
|
||||
|
||||
box_SOURCES = box.c
|
||||
|
@ -46,6 +46,7 @@ bufr_clone_SOURCES = bufr_clone.c
|
|||
bufr_expanded_SOURCES = bufr_expanded.c
|
||||
bufr_get_keys_SOURCES = bufr_get_keys.c
|
||||
bufr_keys_iterator = bufr_keys_iterator.c
|
||||
bufr_missing = bufr_missing.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
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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_missing
|
||||
*
|
||||
* Description: how to handle missing values in BUFR messages.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "eccodes.h"
|
||||
|
||||
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
FILE* in = NULL;
|
||||
|
||||
/* message handle. Required in all the eccodes calls acting on a message.*/
|
||||
codes_handle* h=NULL;
|
||||
|
||||
char* units= NULL;
|
||||
char* unitsPercent= NULL;
|
||||
long longVal;
|
||||
double doubleVal;
|
||||
size_t values_len=0, desc_len=0, len=0;
|
||||
int i, err=0;
|
||||
int cnt=0;
|
||||
char* infile = "../../data/bufr/syno_1.bufr";
|
||||
|
||||
in=fopen(infile,"r");
|
||||
if (!in) {
|
||||
printf("ERROR: unable to open file %s\n", infile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* loop over the messages in the bufr file */
|
||||
while ((h = codes_handle_new_from_file(NULL,in,PRODUCT_BUFR,&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 value is missing */
|
||||
CODES_CHECK(codes_get_double(h,"relativeHumidity",&doubleVal),&err);
|
||||
printf(" relativeHumidity: %.2f %ld\n",doubleVal,err);
|
||||
|
||||
/* This value exists */
|
||||
CODES_CHECK(codes_get_double(h,"airTemperatureAt2M",&doubleVal),&err);
|
||||
printf(" airTemperatureAt2M: %.2f %ld\n",doubleVal,err);
|
||||
|
||||
/*longVal=10;
|
||||
err=codes_is_missing(h,"relativeHumidity",&longVal);
|
||||
printf(" missing: %ld %ld\n",longVal,err);
|
||||
|
||||
err=codes_is_missing(h,"airTemperatureAt2M",&longVal);
|
||||
printf(" missing: %ld %ld\n",longVal,err);*/
|
||||
|
||||
/* delete handle */
|
||||
codes_handle_delete(h);
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
|
@ -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_missing_test_c"
|
||||
|
||||
#Define tmp file
|
||||
fTmp=${label}.tmp.txt
|
||||
rm -f $fTmp | true
|
||||
|
||||
#We check "syno_1.bufr". The path is
|
||||
#hardcoded in the example
|
||||
|
||||
REDIRECT=/dev/null
|
||||
|
||||
#Write the key values into a file
|
||||
${examples_dir}/bufr_missing #2> $REDIRECT > $fTmp
|
||||
|
||||
#TODO: check the results
|
||||
|
||||
#cat $fTmp
|
||||
|
||||
#Clean up
|
||||
rm -f $fTmp | true
|
Loading…
Reference in New Issue