source: inundation-numpy-branch/utilities/util_ext.c @ 2545

Last change on this file since 2545 was 2545, checked in by ole, 18 years ago

Got utilities to compile and pass all tests using numpy

File size: 2.0 KB
Line 
1// Python - C extension for finite_volumes util module.
2//
3// To compile (Python2.3):
4//  gcc -c util_ext.c -I/usr/include/python2.3 -o util_ext.o -Wall -O
5//  gcc -shared util_ext.o  -o util_ext.so
6//
7// See the module util.py
8//
9//
10// Ole Nielsen, GA 2004
11//
12//NOTE: On 64 bit systems use long* instead of int* for Numeric arrays
13//this will also work on 32 bit systems
14
15
16#include "Python.h"
17#include "arrayobject.h"
18#include "math.h"
19
20//Shared snippets
21#include "util_ext.h"
22
23
24
25PyObject *gradient(PyObject *self, PyObject *args) {
26  //
27  // a,b = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2)
28  //
29
30  double x0, y0, x1, y1, x2, y2, q0, q1, q2, a, b;
31  PyObject *result;
32
33  // Convert Python arguments to C
34  if (!PyArg_ParseTuple(args, "ddddddddd", &x0, &y0, &x1, &y1, &x2, &y2,
35                        &q0, &q1, &q2))
36    return NULL;
37
38
39  // Call underlying routine
40  _gradient(x0, y0, x1, y1, x2, y2,
41            q0, q1, q2, &a, &b);
42
43  // Return values a and b
44  result = Py_BuildValue("dd", a, b);
45  return result;
46}
47
48PyObject *gradient2(PyObject *self, PyObject *args) {
49  //
50  // a,b = gradient2(x0, y0, x1, y1, q0, q1)
51  //
52
53  double x0, y0, x1, y1, q0, q1, a, b;
54  PyObject *result;
55
56  // Convert Python arguments to C
57  if (!PyArg_ParseTuple(args, "dddddd", &x0, &y0, &x1, &y1, &q0, &q1))
58    return NULL;
59
60
61  // Call underlying routine
62  _gradient2(x0, y0, x1, y1, q0, q1, &a, &b);
63
64  // Return values a and b
65  result = Py_BuildValue("dd", a, b);
66  return result;
67}
68
69// Method table for python module
70static struct PyMethodDef MethodTable[] = {
71  /* The cast of the function is necessary since PyCFunction values
72   * only take two PyObject* parameters, and rotate() takes
73   * three.
74   */
75
76  //{"rotate", (PyCFunction)rotate, METH_VARARGS | METH_KEYWORDS, "Print out"},
77  {"gradient", gradient, METH_VARARGS, "Print out"},
78  {"gradient2", gradient2, METH_VARARGS, "Print out"}, 
79  {NULL, NULL, 0, NULL}   /* sentinel */
80};
81
82
83
84// Module initialisation
85void initutil_ext(void){
86  Py_InitModule("util_ext", MethodTable);
87
88  import_array();     //Necessary for handling of NumPY structures
89}
90
91
92
93
Note: See TracBrowser for help on using the repository browser.