source: sasview/sansmodels/src/sans/models/c_smearer/smearer2d_helper_module.cpp @ f82fe3c

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 f82fe3c was 8dbc4e5, checked in by Jae Cho <jhjcho@…>, 14 years ago

a fix on Mc c-compile

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/**
2 *  Smearer module to perform point and slit smearing calculations
3
4        This software was developed by the University of Tennessee as part of the
5        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
6        project funded by the US National Science Foundation.
7
8        See the license text in license.txt
9
10        copyright 2009, University of Tennessee
11 */
12#include <Python.h>
13#include <stdio.h>
14#include <smearer2d_helper.hh>
15
16// Utilities
17#define INVECTOR(obj,buf,len)                                                                           \
18    do { \
19        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
20        if (err < 0) return NULL; \
21        len /= sizeof(*buf); \
22    } while (0)
23
24#define OUTVECTOR(obj,buf,len) \
25    do { \
26        int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \
27        if (err < 0) return NULL; \
28        len /= sizeof(*buf); \
29    } while (0)
30
31
32/**
33 * Delete a Smearer2d object
34 */
35void del_smearer2d_helper(void *ptr){
36        Smearer_helper* smearer2d_helper = static_cast<Smearer_helper *>(ptr);
37        delete smearer2d_helper;
38        return;
39}
40
41/**
42/**
43 * Create a QSmearer as a python object by supplying a q array
44 */
45PyObject * new_Smearer_helper(PyObject *, PyObject *args) {
46        PyObject *qx_values_obj;
47        PyObject *qy_values_obj;
48        PyObject *dqx_values_obj;
49        PyObject *dqy_values_obj;
50        Py_ssize_t n_q;
51        //PyObject rlimit_obj;
52        //PyObject npoints_obj;
53        //PyObject nrbins_obj;
54        //PyObject nphibins_obj;
55        double* qx_values;
56        double* qy_values;
57        double* dqx_values;
58        double* dqy_values;
59        double rlimit;
60        int npoints;
61        int nrbins;
62        int nphibins;
63
64
65        if (!PyArg_ParseTuple(args, "OOOOdiii", &qx_values_obj, &qy_values_obj, &dqx_values_obj, &dqy_values_obj, &rlimit, &nrbins, &nphibins, &npoints)) return NULL;
66        OUTVECTOR(qx_values_obj, qx_values, n_q);
67        OUTVECTOR(qy_values_obj, qy_values, n_q);
68        OUTVECTOR(dqx_values_obj, dqx_values, n_q);
69        OUTVECTOR(dqy_values_obj, dqy_values, n_q);
70        Smearer_helper* smearer2d_helper = new Smearer_helper(npoints,qx_values,qy_values,dqx_values,dqy_values, rlimit, nrbins, nphibins);
71        return PyCObject_FromVoidPtr(smearer2d_helper, del_smearer2d_helper);
72}
73
74/**
75 * Smear the given input according to a given smearer object
76 */
77PyObject * smear2d_input(PyObject *, PyObject *args) {
78        PyObject *weights_obj;
79        Py_ssize_t w_out;
80        double *weights;
81        PyObject *qx_out_obj;
82        Py_ssize_t n_out;
83        double *qx_out;
84        PyObject *qy_out_obj;
85        //Py_ssize_t n_out;
86        double *qy_out;
87        PyObject *smear_obj;
88
89        if (!PyArg_ParseTuple(args, "OOOO",  &smear_obj, &weights_obj, &qx_out_obj, &qy_out_obj)) return NULL;
90        OUTVECTOR(weights_obj, weights, w_out);
91        OUTVECTOR(qx_out_obj, qx_out, n_out);
92        OUTVECTOR(qy_out_obj, qy_out, n_out);
93
94        // Sanity check
95        //if(n_in!=n_out) return Py_BuildValue("i",-1);
96
97        // Set the array pointers
98        void *temp = PyCObject_AsVoidPtr(smear_obj);
99        Smearer_helper* s = static_cast<Smearer_helper *>(temp);
100
101        s->smear2d(weights, qx_out, qy_out);
102        //return PyCObject_FromVoidPtr(s, del_smearer2d_helper);
103        return Py_BuildValue("i",1);
104}
105
106
107/**
108 * Define module methods
109 */
110static PyMethodDef module_methods[] = {
111        {"new_Smearer_helper", (PyCFunction)new_Smearer_helper, METH_VARARGS,
112                  "Create a new Q Smearer object"},
113        {"smearer2d_helper",(PyCFunction)smear2d_input, METH_VARARGS,
114                  "Smear the given input array"},
115    {NULL}
116};
117
118
119#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
120#define PyMODINIT_FUNC void
121#endif
122PyMODINIT_FUNC
123initsmearer2d_helper(void)
124{
125    PyObject* m;
126
127    m = Py_InitModule3("smearer2d_helper", module_methods,
128                       "Smearer2d_helper module");
129}
Note: See TracBrowser for help on using the repository browser.