source: sasview/sansmodels/src/c_gen/sld2i_module.cpp @ b1174ec

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b1174ec was b1174ec, checked in by Jae Cho <jhjcho@…>, 11 years ago

more fixes in gen sans

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/**
2  SLD2I module to perform point and I calculations
3 */
4#include <Python.h>
5#include <stdio.h>
6#include <sld2i.hh>
7
8// Utilities
9#define INVECTOR(obj,buf,len)                                                                           \
10    do { \
11        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
12        if (err < 0) return NULL; \
13        len /= sizeof(*buf); \
14    } while (0)
15
16#define OUTVECTOR(obj,buf,len) \
17    do { \
18        int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \
19        if (err < 0) return NULL; \
20        len /= sizeof(*buf); \
21    } while (0)
22
23
24/**
25 * Delete a GenI object
26 */
27void del_sld2i(void *ptr){
28        GenI* sld2i = static_cast<GenI *>(ptr);
29        delete sld2i;
30        return;
31}
32
33/**
34 * Create a GenI as a python object by supplying arrays
35 */
36PyObject * new_GenI(PyObject *, PyObject *args) {
37        PyObject *x_val_obj;
38        PyObject *y_val_obj;
39        PyObject *z_val_obj;
40        PyObject *sldn_val_obj;
41        PyObject *mx_val_obj;
42        PyObject *my_val_obj;
43        PyObject *mz_val_obj;
44        PyObject *vol_pix_obj;
45        Py_ssize_t n_x;
46        //PyObject rlimit_obj;
47        //PyObject npoints_obj;
48        //PyObject nrbins_obj;
49        //PyObject nphibins_obj;
50        int n_pix;
51        double* x_val;
52        double* y_val;
53        double* z_val;
54        double* sldn_val;
55        double* mx_val;
56        double* my_val;
57        double* mz_val;
58        double* vol_pix;
59        double inspin;
60        double outspin;
61        double stheta;
62
63        if (!PyArg_ParseTuple(args, "iOOOOOOOOddd", &n_pix, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &vol_pix_obj, &inspin, &outspin, &stheta)) return NULL;
64        OUTVECTOR(x_val_obj, x_val, n_x);
65        OUTVECTOR(y_val_obj, y_val, n_x);
66        OUTVECTOR(z_val_obj, z_val, n_x);
67        OUTVECTOR(sldn_val_obj, sldn_val, n_x);
68        OUTVECTOR(mx_val_obj, mx_val, n_x);
69        OUTVECTOR(my_val_obj, my_val, n_x);
70        OUTVECTOR(mz_val_obj, mz_val, n_x);
71        OUTVECTOR(vol_pix_obj, vol_pix, n_x);
72        GenI* sld2i = new GenI(n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,vol_pix,inspin,outspin,stheta);
73        return PyCObject_FromVoidPtr(sld2i, del_sld2i);
74}
75
76/**
77 * GenI the given input according to a given object
78 */
79PyObject * genicom_input(PyObject *, PyObject *args) {
80        int npoints;
81        PyObject *qx_obj;
82        double *qx;
83        PyObject *qy_obj;
84        double *qy;
85        PyObject *I_out_obj;
86        Py_ssize_t n_out;
87        double *I_out;
88        PyObject *gen_obj;
89
90        if (!PyArg_ParseTuple(args, "OiOOO",  &gen_obj, &npoints, &qx_obj, &qy_obj, &I_out_obj)) return NULL;
91        OUTVECTOR(qx_obj, qx, n_out);
92        OUTVECTOR(qy_obj, qy, n_out);
93        OUTVECTOR(I_out_obj, I_out, n_out);
94
95        // Sanity check
96        //if(n_in!=n_out) return Py_BuildValue("i",-1);
97
98        // Set the array pointers
99        void *temp = PyCObject_AsVoidPtr(gen_obj);
100        GenI* s = static_cast<GenI *>(temp);
101
102        s->genicom(npoints, qx, qy, I_out);
103        //return PyCObject_FromVoidPtr(s, del_genicom);
104        return Py_BuildValue("i",1);
105}
106
107
108/**
109 * Define module methods
110 */
111static PyMethodDef module_methods[] = {
112        {"new_GenI", (PyCFunction)new_GenI, METH_VARARGS,
113                  "Create a new GenI object"},
114        {"genicom",(PyCFunction)genicom_input, METH_VARARGS,
115                  "genicom the given input arrays"},
116    {NULL}
117};
118
119
120#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
121#define PyMODINIT_FUNC void
122#endif
123PyMODINIT_FUNC
124initsld2i(void)
125{
126    PyObject* m;
127
128    m = Py_InitModule3("sld2i", module_methods,
129                       "Sld2i module");
130}
Note: See TracBrowser for help on using the repository browser.