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 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/* Input file for creating Python wrappers for Vgrid via swig
Author: Todd Dolinsky
Email: todd@ccb.wustl.edu
Header files:
-----------------------
*/
%module apbslib
%{
#include "routines.h"
#include "mg/vgrid.h"
%}
#define VEXTERNC extern
// Generic array of doubles:
%inline %{
double *null_array(){
return NULL;
}
%}
typedef struct {
Vgrid();
~Vgrid();
int nx;
int ny;
int nz;
double hx;
double hy;
double hzed;
double xmin;
double ymin;
double zmin;
double *data;
} Vgrid;
%inline %{
void delete_vgrid(Vgrid *thee){
if (thee != VNULL) {
Vmem_free(thee->mem, (thee->nx*thee->ny*thee->nz), sizeof(double),
(void **)&(thee->data));
Vmem_free(VNULL, 1, sizeof(Vgrid), (void **)&thee);
thee = VNULL;
}
}
%}
extern int Vgrid_ctor2(Vgrid *thee, int nx, int ny, int nz, double hx,
double hy, double hzed, double xmin, double ymin,
double zmin, double *data);
extern void Vgrid_dtor(Vgrid **thee);
extern void Vgrid_dtor2(Vgrid *thee);
extern void Vgrid_writeUHBD(Vgrid *thee, const char *iodev, const char *iofmt, const char *thost, const char *fname, char *title, double *pvec);
extern void Vgrid_writeDX(Vgrid *thee, const char *iodev, const char *iofmt, const char *thost, const char *fname, char *title, double *pvec);
extern int Vgrid_readDX(Vgrid *thee, const char *iodev, const char *iofmt, const char *thost, const char *fname);
extern void startVio();
// Typemaps and functions for easy Python Access
%include typemaps.i
%typemap(in) double [3] {
/* Check if is a list */
if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$1 = (double *) malloc((size+1)*sizeof(double));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyFloat_Check(o))
$1[i] = PyFloat_AsDouble(PyList_GetItem($input,i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain floats");
free($1);
return NULL;
}
}
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
}
}
extern int Vgrid_value(Vgrid *thee, double x[3], double *INOUT);
%typemap(in) double * {
if (PyList_Check($input)) {
int size = PyList_Size($input);
int i = 0;
$1 = (double *) malloc((size+1)*sizeof(double));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyFloat_Check(o))
$1[i] = PyFloat_AsDouble(PyList_GetItem($input,i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain floats");
free($1);
return NULL;
}
}
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
}
}
extern int Vgrid_curvature(Vgrid *thee, double pt[3], int cflag, double *curv);
extern int Vgrid_gradient(Vgrid *thee, double pt[3], double grad[3]);
extern Vgrid* Vgrid_ctor(int nx, int ny, int nz, double hx, double hy,
double hzed, double xmin, double ymin, double zmin,
double *data);
|