From 5e4005251156a8b7cdfbf5b9b626d2a15e09336d Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 12 Mar 2015 18:04:42 +0000 Subject: [PATCH] ECC-80: Python example/test --- examples/python/CMakeLists.txt | 1 + examples/python/Makefile.am | 3 ++- python/eccode_swig.i | 1 + python/eccodes.py | 6 ++++++ python/grib_interface.c | 18 ++++++++++++++++++ python/grib_interface.h | 1 + python/gribapi_swig.i | 1 + 7 files changed, 30 insertions(+), 1 deletion(-) diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index ce8a22ab9..225dc96ba 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -48,6 +48,7 @@ list( APPEND tests bufr_print_data bufr_set_keys bufr_subset + get_product_kind ) foreach( test ${tests} ) ecbuild_add_test( TARGET p_${test}_test diff --git a/examples/python/Makefile.am b/examples/python/Makefile.am index 3fbeebfc6..9b968a51e 100644 --- a/examples/python/Makefile.am +++ b/examples/python/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = @WARN_PEDANTIC@ @WERROR@ TESTS = clone.sh count_messages.sh get.sh index.sh iterator.sh keys_iterator.sh multi_write.sh nearest.sh print_data.sh \ samples.sh set.sh set_missing.sh binary_message.sh set_bitmap.sh bufr_print_header.sh bufr_print_data.sh \ bufr_clone.sh bufr_get_keys.sh bufr_set_keys.sh bufr_expanded.sh bufr_keys_iterator.sh bufr_subset.sh \ - bufr_attributes.sh + bufr_attributes.sh get_product_kind.sh TESTS_ENVIRONMENT = TOPBUILDDIR=$(top_builddir) PYTHON=$(PYTHON) noinst_PROGRAMS = p_keys_iterator p_print_data p_iterator p_count_messages @@ -20,5 +20,6 @@ EXTRA_DIST = $(TESTS) include.sh clone.py count_messages.py get.py index.py iter nearest.py print_data.py samples.py set.py set_missing.py binary_message.py set_pv.py set_bitmap.py \ bufr_print_header.py bufr_print_data.py bufr_clone.py bufr_get_keys.py bufr_set_keys.py \ bufr_expanded.py bufr_keys_iterator.py bufr_subset.py bufr_attributes.py \ + get_product_kind.py \ CMakeLists.txt include.ctest.sh.in endif diff --git a/python/eccode_swig.i b/python/eccode_swig.i index 1b546ca4f..a39f71bb5 100644 --- a/python/eccode_swig.i +++ b/python/eccode_swig.i @@ -40,6 +40,7 @@ import_array(); // creation int grib_c_new_from_file(FILE* f, int* INOUT, int headers_only); +int grib_c_new_any_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_new_bufr_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_new_gts_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_iterator_new(int* INPUT, int* OUTPUT, int* INPUT); diff --git a/python/eccodes.py b/python/eccodes.py index a63d2d9d8..c32568f1b 100644 --- a/python/eccodes.py +++ b/python/eccodes.py @@ -1,6 +1,12 @@ from gribapi import GRIB_CHECK as CODES_CHECK +from gribapi import CODES_PRODUCT_GRIB +from gribapi import CODES_PRODUCT_BUFR +from gribapi import CODES_PRODUCT_ANY + from gribapi import grib_new_from_file as codes_grib_new_from_file from gribapi import bufr_new_from_file as codes_bufr_new_from_file +from gribapi import any_new_from_file as codes_any_new_from_file +from gribapi import codes_new_from_file from gribapi import grib_count_in_file as codes_count_in_file from gribapi import grib_multi_support_on as codes_grib_multi_support_on diff --git a/python/grib_interface.c b/python/grib_interface.c index 8b50c2ffa..85f53eb0b 100644 --- a/python/grib_interface.c +++ b/python/grib_interface.c @@ -1000,6 +1000,24 @@ int grib_c_new_gts_from_file(FILE* f,int headers_only, int* gid){ return GRIB_INVALID_FILE; } +int grib_c_new_any_from_file(FILE* f,int headers_only,int* gid){ + grib_handle *h = NULL; + int err = 0; + if(f){ + h = codes_handle_new_from_file(0,f,PRODUCT_ANY, &err); + if(h){ + push_handle(h,gid); + return GRIB_SUCCESS; + } else { + *gid=-1; + return GRIB_END_OF_FILE; + } + } + + *gid=-1; + return GRIB_INVALID_FILE; +} + int grib_c_new_bufr_from_file(FILE* f,int headers_only,int* gid){ grib_handle *h = NULL; int err = 0; diff --git a/python/grib_interface.h b/python/grib_interface.h index ee6a91372..763830363 100644 --- a/python/grib_interface.h +++ b/python/grib_interface.h @@ -31,6 +31,7 @@ int grib_c_clone(int *gidsrc, int *giddest); int grib_c_copy_namespace(int *gidsrc, char *name, int *giddest); int grib_c_count_in_file(FILE *f, int *n); int grib_c_new_from_file(FILE *f, int *gid, int headers_only); +int grib_c_new_any_from_file(FILE *f, int headers_only,int *gid); int grib_c_new_bufr_from_file(FILE *f, int headers_only,int *gid); int grib_c_new_gts_from_file(FILE *f,int headers_only, int *gid); int grib_c_new_from_index(int *iid, int *gid); diff --git a/python/gribapi_swig.i b/python/gribapi_swig.i index c00860026..6c0796ee8 100644 --- a/python/gribapi_swig.i +++ b/python/gribapi_swig.i @@ -40,6 +40,7 @@ import_array(); // creation int grib_c_new_from_file(FILE* f, int* INOUT, int headers_only); +int grib_c_new_any_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_new_bufr_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_new_gts_from_file(FILE* f, int headers_only, int* INOUT); int grib_c_iterator_new(int* INPUT, int* OUTPUT, int* INPUT);