From 366bd1ff3dcd490fc50ce08278548ff00dcec1c8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 29 Jun 2016 16:40:28 +0100 Subject: [PATCH] ECC-283: Add functions to Python interface --- examples/python/samples.sh | 4 +-- python/eccodes.py | 2 ++ python/grib_interface.c | 12 +++++++++ python/grib_interface.h | 2 ++ python/gribapi.py | 21 ++++++++++++++++ python/gribapi_swig.i | 2 ++ python/swig_wrap_array.c | 51 ++++++++++++++++++++++++++++++++++++++ python/swig_wrap_array.py | 9 +++++++ python/swig_wrap_numpy.c | 51 ++++++++++++++++++++++++++++++++++++++ python/swig_wrap_numpy.py | 9 +++++++ 10 files changed, 161 insertions(+), 2 deletions(-) diff --git a/examples/python/samples.sh b/examples/python/samples.sh index c73154c46..66fec128e 100755 --- a/examples/python/samples.sh +++ b/examples/python/samples.sh @@ -3,5 +3,5 @@ . ./include.sh REDIRECT=/dev/null -$PYTHON $examples_src/samples.py 2> $REDIRECT > $REDIRECT -rm -f out.samples.grib || true +$PYTHON $examples_src/samples.py +rm -f out.samples.grib diff --git a/python/eccodes.py b/python/eccodes.py index 44c57557e..1695494fe 100644 --- a/python/eccodes.py +++ b/python/eccodes.py @@ -92,5 +92,7 @@ from gribapi import grib_gts_header as codes_gts_header from gribapi import grib_get_api_version as codes_get_api_version from gribapi import grib_get_message as codes_get_message from gribapi import grib_new_from_message as codes_new_from_message +from gribapi import grib_set_definitions_path as codes_set_definitions_path +from gribapi import grib_set_samples_path as codes_set_samples_path from gribapi import GribInternalError as CodesInternalError diff --git a/python/grib_interface.c b/python/grib_interface.c index a29a00a78..701812a94 100644 --- a/python/grib_interface.c +++ b/python/grib_interface.c @@ -2114,3 +2114,15 @@ int grib_c_get_message(int *gid, const void **msg, size_t *size) grib_handle *h = get_handle(*gid); return grib_get_message(h,msg,size); } + +void grib_c_set_definitions_path(const char* path) +{ + grib_context *c = grib_context_get_default(); + grib_context_set_definitions_path(c, path); +} + +void grib_c_set_samples_path(const char* path) +{ + grib_context *c = grib_context_get_default(); + grib_context_set_samples_path(c, path); +} diff --git a/python/grib_interface.h b/python/grib_interface.h index a5e9d849f..c9a3665b9 100644 --- a/python/grib_interface.h +++ b/python/grib_interface.h @@ -108,5 +108,7 @@ void grib_c_gts_header_on(void); void grib_c_gts_header_off(void); int grib_c_get_message(int *gid, const void **msg, size_t *size); int grib_c_get_string_length(int* gid, char* key, size_t* val); +void grib_c_set_definitions_path(const char* path); +void grib_c_set_samples_path(const char* path); #endif diff --git a/python/gribapi.py b/python/gribapi.py index fe30dd892..69c48c1ef 100644 --- a/python/gribapi.py +++ b/python/gribapi.py @@ -1868,3 +1868,24 @@ def grib_new_from_message(message): error, gribid = _internal.grib_c_new_from_message(0, message, len(message)) GRIB_CHECK(error) return gribid + + +@require(defs_path=str) +def grib_set_definitions_path(defs_path): + """ + @brief Set the definitions path + + @param defs_path definitions path + """ + _internal.grib_c_set_definitions_path(defs_path) + + +@require(samples_path=str) +def grib_set_samples_path(samples_path): + """ + @brief Set the samples path + + @param samples_path samples path + """ + _internal.grib_c_set_samples_path(samples_path) + diff --git a/python/gribapi_swig.i b/python/gribapi_swig.i index 80e961341..95b1f9ff0 100644 --- a/python/gribapi_swig.i +++ b/python/gribapi_swig.i @@ -212,3 +212,5 @@ void no_fail_on_wrong_length(int flag); long grib_c_get_api_version(); void grib_c_gts_header_on(); void grib_c_gts_header_off(); +void grib_c_set_definitions_path(const char* path); +void grib_c_set_samples_path(const char* path); diff --git a/python/swig_wrap_array.c b/python/swig_wrap_array.c index 484d261a2..5644b6d3d 100644 --- a/python/swig_wrap_array.c +++ b/python/swig_wrap_array.c @@ -7807,6 +7807,54 @@ fail: } +SWIGINTERN PyObject *_wrap_grib_c_set_definitions_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:grib_c_set_definitions_path",&obj0)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "grib_c_set_definitions_path" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = (char *)(buf1); + grib_c_set_definitions_path((char const *)arg1); + resultobj = SWIG_Py_Void(); + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_grib_c_set_samples_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:grib_c_set_samples_path",&obj0)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "grib_c_set_samples_path" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = (char *)(buf1); + grib_c_set_samples_path((char const *)arg1); + resultobj = SWIG_Py_Void(); + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, { (char *)"cdata", _wrap_cdata, METH_VARARGS, NULL}, @@ -7932,6 +7980,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"grib_c_get_api_version", _wrap_grib_c_get_api_version, METH_VARARGS, NULL}, { (char *)"grib_c_gts_header_on", _wrap_grib_c_gts_header_on, METH_VARARGS, NULL}, { (char *)"grib_c_gts_header_off", _wrap_grib_c_gts_header_off, METH_VARARGS, NULL}, + { (char *)"grib_c_set_definitions_path", _wrap_grib_c_set_definitions_path, METH_VARARGS, NULL}, + { (char *)"grib_c_set_samples_path", _wrap_grib_c_set_samples_path, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; @@ -8662,6 +8712,7 @@ SWIG_init(void) { SWIG_Python_SetConstant(d, "GRIB_TOO_MANY_ATTRIBUTES",SWIG_From_int((int)(-62))); SWIG_Python_SetConstant(d, "GRIB_ATTRIBUTE_NOT_FOUND",SWIG_From_int((int)(-63))); SWIG_Python_SetConstant(d, "GRIB_UNSUPPORTED_EDITION",SWIG_From_int((int)(-64))); + SWIG_Python_SetConstant(d, "GRIB_OUT_OF_RANGE",SWIG_From_int((int)(-65))); #if PY_VERSION_HEX >= 0x03000000 return m; #else diff --git a/python/swig_wrap_array.py b/python/swig_wrap_array.py index a7ebc5e2d..21614bebf 100644 --- a/python/swig_wrap_array.py +++ b/python/swig_wrap_array.py @@ -139,6 +139,7 @@ GRIB_ATTRIBUTE_CLASH = _gribapi_swig.GRIB_ATTRIBUTE_CLASH GRIB_TOO_MANY_ATTRIBUTES = _gribapi_swig.GRIB_TOO_MANY_ATTRIBUTES GRIB_ATTRIBUTE_NOT_FOUND = _gribapi_swig.GRIB_ATTRIBUTE_NOT_FOUND GRIB_UNSUPPORTED_EDITION = _gribapi_swig.GRIB_UNSUPPORTED_EDITION +GRIB_OUT_OF_RANGE = _gribapi_swig.GRIB_OUT_OF_RANGE class intp(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, intp, name, value) @@ -608,4 +609,12 @@ def grib_c_gts_header_off(): return _gribapi_swig.grib_c_gts_header_off() grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off +def grib_c_set_definitions_path(*args): + return _gribapi_swig.grib_c_set_definitions_path(*args) +grib_c_set_definitions_path = _gribapi_swig.grib_c_set_definitions_path + +def grib_c_set_samples_path(*args): + return _gribapi_swig.grib_c_set_samples_path(*args) +grib_c_set_samples_path = _gribapi_swig.grib_c_set_samples_path + diff --git a/python/swig_wrap_numpy.c b/python/swig_wrap_numpy.c index 1a1f531b1..5135d16d3 100644 --- a/python/swig_wrap_numpy.c +++ b/python/swig_wrap_numpy.c @@ -8631,6 +8631,54 @@ fail: } +SWIGINTERN PyObject *_wrap_grib_c_set_definitions_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:grib_c_set_definitions_path",&obj0)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "grib_c_set_definitions_path" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = (char *)(buf1); + grib_c_set_definitions_path((char const *)arg1); + resultobj = SWIG_Py_Void(); + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_grib_c_set_samples_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:grib_c_set_samples_path",&obj0)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "grib_c_set_samples_path" "', argument " "1"" of type '" "char const *""'"); + } + arg1 = (char *)(buf1); + grib_c_set_samples_path((char const *)arg1); + resultobj = SWIG_Py_Void(); + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return resultobj; +fail: + if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); + return NULL; +} + + static PyMethodDef SwigMethods[] = { { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, { (char *)"cdata", _wrap_cdata, METH_VARARGS, NULL}, @@ -8762,6 +8810,8 @@ static PyMethodDef SwigMethods[] = { { (char *)"grib_c_get_api_version", _wrap_grib_c_get_api_version, METH_VARARGS, NULL}, { (char *)"grib_c_gts_header_on", _wrap_grib_c_gts_header_on, METH_VARARGS, NULL}, { (char *)"grib_c_gts_header_off", _wrap_grib_c_gts_header_off, METH_VARARGS, NULL}, + { (char *)"grib_c_set_definitions_path", _wrap_grib_c_set_definitions_path, METH_VARARGS, NULL}, + { (char *)"grib_c_set_samples_path", _wrap_grib_c_set_samples_path, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; @@ -9492,6 +9542,7 @@ SWIG_init(void) { SWIG_Python_SetConstant(d, "GRIB_TOO_MANY_ATTRIBUTES",SWIG_From_int((int)(-62))); SWIG_Python_SetConstant(d, "GRIB_ATTRIBUTE_NOT_FOUND",SWIG_From_int((int)(-63))); SWIG_Python_SetConstant(d, "GRIB_UNSUPPORTED_EDITION",SWIG_From_int((int)(-64))); + SWIG_Python_SetConstant(d, "GRIB_OUT_OF_RANGE",SWIG_From_int((int)(-65))); import_array(); diff --git a/python/swig_wrap_numpy.py b/python/swig_wrap_numpy.py index d41752f9d..30dcb3d0e 100644 --- a/python/swig_wrap_numpy.py +++ b/python/swig_wrap_numpy.py @@ -139,6 +139,7 @@ GRIB_ATTRIBUTE_CLASH = _gribapi_swig.GRIB_ATTRIBUTE_CLASH GRIB_TOO_MANY_ATTRIBUTES = _gribapi_swig.GRIB_TOO_MANY_ATTRIBUTES GRIB_ATTRIBUTE_NOT_FOUND = _gribapi_swig.GRIB_ATTRIBUTE_NOT_FOUND GRIB_UNSUPPORTED_EDITION = _gribapi_swig.GRIB_UNSUPPORTED_EDITION +GRIB_OUT_OF_RANGE = _gribapi_swig.GRIB_OUT_OF_RANGE class intp(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, intp, name, value) @@ -632,4 +633,12 @@ def grib_c_gts_header_off(): return _gribapi_swig.grib_c_gts_header_off() grib_c_gts_header_off = _gribapi_swig.grib_c_gts_header_off +def grib_c_set_definitions_path(*args): + return _gribapi_swig.grib_c_set_definitions_path(*args) +grib_c_set_definitions_path = _gribapi_swig.grib_c_set_definitions_path + +def grib_c_set_samples_path(*args): + return _gribapi_swig.grib_c_set_samples_path(*args) +grib_c_set_samples_path = _gribapi_swig.grib_c_set_samples_path +