forked from gozwei/pySeismicFMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3DFMMmodule.cpp
109 lines (87 loc) · 2.51 KB
/
3DFMMmodule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_10_API_VERSION
#include <numpy/arrayobject.h>
#include "3DFMM.h"
struct module_state {
PyObject *error;
};
#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
static PyObject* FMM3D(PyObject* self, PyObject* args)
{
PyArrayObject *model_obj;
PyArrayObject *time_obj;
PyArrayObject *accepted_obj;
PyArrayObject *lat_obj;
PyArrayObject *lon_obj;
PyArrayObject *h_obj;
PyArrayObject *trace_obj;
int N;
if (!PyArg_ParseTuple(args, "OOOOOOOi", &model_obj, &time_obj, &accepted_obj, &lat_obj, &lon_obj, &h_obj, &trace_obj, &N))
{
Py_INCREF(Py_None);
return Py_None;
}
float *MODEL = static_cast<float *>(PyArray_DATA(model_obj));
float *TIME = static_cast<float *>(PyArray_DATA(time_obj));
bool *ACCEPTED = static_cast<bool *>(PyArray_DATA(accepted_obj));
double *LAT = static_cast<double *>(PyArray_DATA(lat_obj));
double *LON = static_cast<double *>(PyArray_DATA(lon_obj));
double *H = static_cast<double *>(PyArray_DATA(h_obj));
int *TRACE = static_cast<int *>(PyArray_DATA(trace_obj));
_FMM3D(MODEL, TIME, ACCEPTED, LAT, LON, H, TRACE, N);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject* SetModelSize(PyObject* self, PyObject* args)
{
int _size_lat, _size_lon, _size_z;
double _dlat, _dlon, _dz;
if (!PyArg_ParseTuple(args, "iiiddd", &_size_lat, &_size_lon, &_size_z, &_dlat, &_dlon, &_dz))
{
Py_INCREF(Py_None);
return Py_None;
}
_SetModelSize(_size_lat, _size_lon, _size_z, _dlat, _dlon, _dz);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef FMMMethods[] = {
{"FMM3D", FMM3D, METH_VARARGS, "..."},
{"SetModelSize", SetModelSize, METH_VARARGS, "..."},
{NULL, NULL, 0, NULL}
};
static int FMM_traverse(PyObject *m, visitproc visit, void *arg) {
Py_VISIT(GETSTATE(m)->error);
return 0;
}
static int FMM_clear(PyObject *m) {
Py_CLEAR(GETSTATE(m)->error);
return 0;
}
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"FMM3D",
NULL,
sizeof(struct module_state),
FMMMethods,
NULL,
FMM_traverse,
FMM_clear,
NULL
};
extern "C" PyObject * PyInit_FMM3D(void)
{
PyObject *module = PyModule_Create(&moduledef);
if (module == NULL)
return NULL;
struct module_state *st = GETSTATE(module);
st->error = PyErr_NewException("FMM3D.Error", NULL, NULL);
if (st->error == NULL)
{
Py_DECREF(module);
return NULL;
}
import_array();
Py_INCREF(module);
return module;
}