// 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" double max(double x, double y) { //Return maximum of two doubles if (x > y) return x; else return y; } double min(double x, double y) { //Return minimum of two doubles if (x < y) return x; else return y; } int _gradient(double x0, double y0, double x1, double y1, double x2, double y2, double q0, double q1, double q2, double *a, double *b) { double det; det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0); *a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0); *a /= det; *b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0); *b /= det; return 0; } void print_numeric_array(PyArrayObject *x) { int i, j; for (i=0; idimensions[0]; i++) { for (j=0; jdimensions[1]; j++) { printf("%f ", *(double*) (x->data + i*x->strides[0] + j*x->strides[1])); } printf("\n"); } printf("\n"); } void print_numeric_vector(PyArrayObject *x) { int i; for (i=0; idimensions[0]; i++) { printf("%f ", *(double*) (x->data + i*x->strides[0])); } printf("\n"); }