mirror of https://github.com/ecmwf/eccodes.git
Testing: grib_copy_key (arrays)
This commit is contained in:
parent
ff4e751cf0
commit
05de92a8f1
|
@ -25,6 +25,7 @@ list( APPEND test_bins
|
|||
grib_list
|
||||
grib_get_data
|
||||
grib_sections_copy
|
||||
grib_copy_keys
|
||||
grib_iterator_bitmap
|
||||
grib_clone
|
||||
grib_copy_message
|
||||
|
@ -65,6 +66,7 @@ if( HAVE_BUILD_TOOLS )
|
|||
grib_set_data
|
||||
large_grib1
|
||||
grib_sections_copy
|
||||
grib_copy_keys
|
||||
get_product_kind_samples)
|
||||
list(APPEND tests_extra
|
||||
grib_iterator
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* (C) Copyright 2005- 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 "eccodes.h"
|
||||
#include <ctype.h>
|
||||
|
||||
static void usage(const char* prog)
|
||||
{
|
||||
printf("usage: %s in1.grib in2.grib\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
codes_handle *hfrom, *hto;
|
||||
FILE* in;
|
||||
char *in_name1, *in_name2;
|
||||
int i = 0, err = 0;
|
||||
const char* keys[] = { "gridType", "pl", "values" };
|
||||
const int keys_count = sizeof(keys) / sizeof(keys[0]);
|
||||
|
||||
if (argc != 3) usage(argv[0]);
|
||||
|
||||
in_name1 = argv[1];
|
||||
in_name2 = argv[2];
|
||||
|
||||
in = fopen(in_name1, "rb");
|
||||
if (!in) {
|
||||
perror(in_name1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
hfrom = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||
CODES_CHECK(err, 0);
|
||||
fclose(in);
|
||||
|
||||
in = fopen(in_name2, "rb");
|
||||
if (!in) {
|
||||
perror(in_name2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
hto = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
|
||||
CODES_CHECK(err, 0);
|
||||
fclose(in);
|
||||
|
||||
for (i = 0; i < keys_count; i++) {
|
||||
printf("Copy key: %s\n", keys[i]);
|
||||
err = codes_copy_key(hfrom, hto, keys[i], GRIB_TYPE_UNDEFINED);
|
||||
CODES_CHECK(err, 0);
|
||||
}
|
||||
|
||||
// codes_write_message(hto, "temp.out", "w"); CODES_CHECK(err, 0);
|
||||
{
|
||||
int dump_flags = GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY;
|
||||
codes_dump_content(hto, stdout, "wmo", dump_flags, NULL);
|
||||
}
|
||||
|
||||
codes_handle_delete(hfrom);
|
||||
codes_handle_delete(hto);
|
||||
|
||||
return err;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
# (C) Copyright 2005- 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.ctest.sh
|
||||
|
||||
FROM_FILE=$ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl
|
||||
TO_FILE=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||
|
||||
${examples_dir}/c_grib_copy_keys $FROM_FILE $TO_FILE
|
Loading…
Reference in New Issue