source: inundation/ga/storm_surge/pyvolution/util_ext.c @ 643

Last change on this file since 643 was 258, checked in by ole, 20 years ago

Added C-headers to share code
Removed length and distance from util

File size: 1.5 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#include "Python.h"
13#include "Numeric/arrayobject.h"
14#include "math.h"
15
16//Shared snippets
17#include "util_ext.h"
18
19
20// Gateway to Python
21PyObject *gradient(PyObject *self, PyObject *args) {
22  //
23  // a,b = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2)
24  //
25 
26  double x0, y0, x1, y1, x2, y2, q0, q1, q2, a, b;
27  PyObject *result;
28 
29  // Convert Python arguments to C 
30  if (!PyArg_ParseTuple(args, "ddddddddd", &x0, &y0, &x1, &y1, &x2, &y2,
31                        &q0, &q1, &q2)) 
32    return NULL;
33
34 
35  // Call underlying routine
36  _gradient(x0, y0, x1, y1, x2, y2, 
37            q0, q1, q2, &a, &b);
38
39  // Return values a and b
40  result = Py_BuildValue("dd", a, b);
41  return result;
42}
43
44
45// Method table for python module
46static struct PyMethodDef MethodTable[] = {
47  /* The cast of the function is necessary since PyCFunction values
48   * only take two PyObject* parameters, and rotate() takes
49   * three.
50   */
51 
52  //{"rotate", (PyCFunction)rotate, METH_VARARGS | METH_KEYWORDS, "Print out"}, 
53  {"gradient", gradient, METH_VARARGS, "Print out"},   
54  {NULL, NULL, 0, NULL}   /* sentinel */
55};
56
57
58
59// Module initialisation   
60void initutil_ext(void){
61  Py_InitModule("util_ext", MethodTable);
62 
63  import_array();     //Necessary for handling of NumPY structures 
64}
65
Note: See TracBrowser for help on using the repository browser.