// Python - C extension for finite_volumes util module. // // To compile (Python2.3): // gcc -c util_ext.c -I/usr/include/python2.3 -o util_ext.o -Wall -O // gcc -shared util_ext.o -o util_ext.so // // See the module util.py // // // Ole Nielsen, GA 2004 #include "Python.h" #include "Numeric/arrayobject.h" #include "math.h" //Shared snippets #include "util_ext.h" // Gateway to Python PyObject *gradient(PyObject *self, PyObject *args) { // // a,b = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2) // double x0, y0, x1, y1, x2, y2, q0, q1, q2, a, b; PyObject *result; // Convert Python arguments to C if (!PyArg_ParseTuple(args, "ddddddddd", &x0, &y0, &x1, &y1, &x2, &y2, &q0, &q1, &q2)) return NULL; // Call underlying routine _gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2, &a, &b); // Return values a and b result = Py_BuildValue("dd", a, b); return result; } // Method table for python module static struct PyMethodDef MethodTable[] = { /* The cast of the function is necessary since PyCFunction values * only take two PyObject* parameters, and rotate() takes * three. */ //{"rotate", (PyCFunction)rotate, METH_VARARGS | METH_KEYWORDS, "Print out"}, {"gradient", gradient, METH_VARARGS, "Print out"}, {NULL, NULL, 0, NULL} /* sentinel */ }; // Module initialisation void initutil_ext(void){ Py_InitModule("util_ext", MethodTable); import_array(); //Necessary for handling of NumPY structures }