source: storm_surge/pyvolution/util_ext.h @ 1

Last change on this file since 1 was 1, checked in by duncan, 20 years ago

initial import

File size: 1.3 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
17double max(double x, double y) { 
18  //Return maximum of two doubles
19 
20  if (x > y) return x;
21  else return y;
22}
23
24
25double min(double x, double y) { 
26  //Return minimum of two doubles
27 
28  if (x < y) return x;
29  else return y;
30}
31
32
33int _gradient(double x0, double y0, 
34              double x1, double y1, 
35              double x2, double y2, 
36              double q0, double q1, double q2, 
37              double *a, double *b) {
38
39  double det;
40 
41  det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0);
42
43  *a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0);
44  *a /= det;
45
46  *b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0);
47  *b /= det;
48
49  return 0;
50}
51
52
53void print_numeric_array(PyArrayObject *x) { 
54  int i, j;
55  for (i=0; i<x->dimensions[0]; i++) { 
56    for (j=0; j<x->dimensions[1]; j++) {
57      printf("%f ", *(double*) (x->data + i*x->strides[0] + j*x->strides[1]));
58    }
59    printf("\n"); 
60  }
61  printf("\n");   
62}
63
64void print_numeric_vector(PyArrayObject *x) { 
65  int i;
66  for (i=0; i<x->dimensions[0]; i++) {
67    printf("%f ", *(double*) (x->data + i*x->strides[0])); 
68  }
69  printf("\n"); 
70}
Note: See TracBrowser for help on using the repository browser.