From 19a30034f5fb9155f246273ecb50e9a7ee41e6ab Mon Sep 17 00:00:00 2001 From: "Oleg E. Peil" Date: Tue, 17 Feb 2015 21:34:50 +0100 Subject: [PATCH] * Replaced direct compilation in Makefile by 'setup.py' from 'distutils' * NO_DEPRECATED_API flag was added and now 'c_plocar_io.c' does not compile --- python/converters/vasp/c/plocar_io/c_plocar_io.c | 11 +++++++---- python/converters/vasp/c/plocar_io/makefile.darwin | 3 ++- python/converters/vasp/c/plocar_io/makefile.linux | 3 ++- python/converters/vasp/c/plocar_io/setup.py | 9 +++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 python/converters/vasp/c/plocar_io/setup.py diff --git a/python/converters/vasp/c/plocar_io/c_plocar_io.c b/python/converters/vasp/c/plocar_io/c_plocar_io.c index 0d9d000c..01b97147 100644 --- a/python/converters/vasp/c/plocar_io/c_plocar_io.c +++ b/python/converters/vasp/c/plocar_io/c_plocar_io.c @@ -1,6 +1,9 @@ #include -#include + +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION + +#include #include #include @@ -32,7 +35,7 @@ static PyMethodDef c_plocar_io[] = { }; PyMODINIT_FUNC -initc_plocar_io() +initc_plocar_io(void) { (void) Py_InitModule("c_plocar_io", c_plocar_io); import_array(); @@ -58,7 +61,7 @@ io_read_plocar(PyObject *self, PyObject *args) FILE* fh; - int isdouble, prec; + int prec; t_params params; if(!PyArg_ParseTuple(args, "|s", &fname)) @@ -271,7 +274,7 @@ int read_arrays(FILE* fh, t_params* p, PyArrayObject* py_plo, PyArrayObject* py_ ind1 = 0; ind2 = 0; for(ion = 0; ion < p->nion; ion++) { - fread(&nlm, 4, 1, fh); + if(fread(&nlm, 4, 1, fh) < 1) goto error; // printf(" nlm = %d\n", nlm); for(is = 0; is < p->ns; is++) for(ik = 0; ik < p->nk; ik++) diff --git a/python/converters/vasp/c/plocar_io/makefile.darwin b/python/converters/vasp/c/plocar_io/makefile.darwin index b2d8a5e5..931e2077 100644 --- a/python/converters/vasp/c/plocar_io/makefile.darwin +++ b/python/converters/vasp/c/plocar_io/makefile.darwin @@ -4,5 +4,6 @@ INC_FLAGS=-I/opt/local/Library/Frameworks/Python.framework/Versions/Current/incl LIB_FLAGS=-L/opt/local/Library/Frameworks/Python.framework/Versions/Current/lib/python2.7 c_plocar_io.so: c_plocar_io.c - $(CC) $< -fPIC -shared -o $@ $(INC_FLAGS) $(LIB_FLAGS) -lpython2.7 +# $(CC) $< -fPIC -shared -o $@ $(INC_FLAGS) $(LIB_FLAGS) -lpython2.7 + python setup.py build_ext --inplace diff --git a/python/converters/vasp/c/plocar_io/makefile.linux b/python/converters/vasp/c/plocar_io/makefile.linux index c4450516..f46a56e0 100644 --- a/python/converters/vasp/c/plocar_io/makefile.linux +++ b/python/converters/vasp/c/plocar_io/makefile.linux @@ -4,5 +4,6 @@ INC_FLAGS=-I/usr/include/python2.7 -I/usr/lib/python2.7/dist-packages/numpy/core LIB_FLAGS=-L/usr/lib/python2.7 c_plocar_io.so: c_plocar_io.c - $(CC) $< -fPIC -shared -o $@ $(INC_FLAGS) $(LIB_FLAGS) -lpython2.7 +# $(CC) $< -fPIC -shared -o $@ $(INC_FLAGS) $(LIB_FLAGS) -lpython2.7 + python setup.py build_ext --inplace diff --git a/python/converters/vasp/c/plocar_io/setup.py b/python/converters/vasp/c/plocar_io/setup.py new file mode 100644 index 00000000..ebf624cf --- /dev/null +++ b/python/converters/vasp/c/plocar_io/setup.py @@ -0,0 +1,9 @@ + +from distutils.core import setup, Extension +import numpy + +c_plocar_io_mod = Extension('c_plocar_io', sources=['c_plocar_io.c'], + include_dirs=[numpy.get_include()]) + +setup(ext_modules=[c_plocar_io_mod]) +