source: sasview/sansmodels/src/c_gen/sld2i_module.cpp @ 077207b

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 077207b was 318b5bbb, checked in by Jae Cho <jhjcho@…>, 12 years ago

Added polarization and magnetic stuffs

  • Property mode set to 100644
File size: 3.2 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        Py_ssize_t n_x;
45        //PyObject rlimit_obj;
46        //PyObject npoints_obj;
47        //PyObject nrbins_obj;
48        //PyObject nphibins_obj;
49        int n_pix;
50        double* x_val;
51        double* y_val;
52        double* z_val;
53        double* sldn_val;
54        double* mx_val;
55        double* my_val;
56        double* mz_val;
57        double inspin;
58        double outspin;
59        double stheta;
60
61        if (!PyArg_ParseTuple(args, "iOOOOOOOddd", &n_pix, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &inspin, &outspin, &stheta)) return NULL;
62        OUTVECTOR(x_val_obj, x_val, n_x);
63        OUTVECTOR(y_val_obj, y_val, n_x);
64        OUTVECTOR(z_val_obj, z_val, n_x);
65        OUTVECTOR(sldn_val_obj, sldn_val, n_x);
66        OUTVECTOR(mx_val_obj, mx_val, n_x);
67        OUTVECTOR(my_val_obj, my_val, n_x);
68        OUTVECTOR(mz_val_obj, mz_val, n_x);
69        GenI* sld2i = new GenI(n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,inspin,outspin,stheta);
70        return PyCObject_FromVoidPtr(sld2i, del_sld2i);
71}
72
73/**
74 * GenI the given input according to a given object
75 */
76PyObject * genicom_input(PyObject *, PyObject *args) {
77        int npoints;
78        PyObject *qx_obj;
79        double *qx;
80        PyObject *qy_obj;
81        double *qy;
82        PyObject *I_out_obj;
83        Py_ssize_t n_out;
84        double *I_out;
85        PyObject *gen_obj;
86
87        if (!PyArg_ParseTuple(args, "OiOOO",  &gen_obj, &npoints, &qx_obj, &qy_obj, &I_out_obj)) return NULL;
88        OUTVECTOR(qx_obj, qx, n_out);
89        OUTVECTOR(qy_obj, qy, n_out);
90        OUTVECTOR(I_out_obj, I_out, n_out);
91
92        // Sanity check
93        //if(n_in!=n_out) return Py_BuildValue("i",-1);
94
95        // Set the array pointers
96        void *temp = PyCObject_AsVoidPtr(gen_obj);
97        GenI* s = static_cast<GenI *>(temp);
98
99        s->genicom(npoints, qx, qy, I_out);
100        //return PyCObject_FromVoidPtr(s, del_genicom);
101        return Py_BuildValue("i",1);
102}
103
104
105/**
106 * Define module methods
107 */
108static PyMethodDef module_methods[] = {
109        {"new_GenI", (PyCFunction)new_GenI, METH_VARARGS,
110                  "Create a new GenI object"},
111        {"genicom",(PyCFunction)genicom_input, METH_VARARGS,
112                  "genicom the given input arrays"},
113    {NULL}
114};
115
116
117#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
118#define PyMODINIT_FUNC void
119#endif
120PyMODINIT_FUNC
121initsld2i(void)
122{
123    PyObject* m;
124
125    m = Py_InitModule3("sld2i", module_methods,
126                       "Sld2i module");
127}
Note: See TracBrowser for help on using the repository browser.