source: sasview/park-1.2.1/park/lib/modeling.cc @ e9bd127

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 e9bd127 was 3570545, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Adding park Part 2

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/* This program is public domain. */
2
3#include <iostream>
4#include <iomanip>
5#include <Python.h>
6
7extern "C" void
8resolution(int Nin, const double Qin[], const double Rin[],
9           int N, const double Q[], const double dQ[], double R[]);
10
11#define INVECTOR(obj,buf,len)                                                                           \
12    do { \
13        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
14        if (err < 0) return NULL; \
15        len /= sizeof(*buf); \
16    } while (0)
17   
18#define OUTVECTOR(obj,buf,len) \
19    do { \
20        int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \
21        if (err < 0) return NULL; \
22        len /= sizeof(*buf); \
23    } while (0)
24
25PyObject* Pconvolve(PyObject *obj, PyObject *args)
26{
27  PyObject *Qi_obj,*Ri_obj,*Q_obj,*dQ_obj,*R_obj;
28  const double *Qi, *Ri, *Q, *dQ;
29  double *R;
30  Py_ssize_t nQi, nRi, nQ, ndQ, nR;
31 
32  if (!PyArg_ParseTuple(args, "OOOOO:resolution", 
33                        &Qi_obj,&Ri_obj,&Q_obj,&dQ_obj,&R_obj)) return NULL;
34  INVECTOR(Qi_obj,Qi,nQi);
35  INVECTOR(Ri_obj,Ri,nRi);
36  INVECTOR(Q_obj,Q,nQ);
37  INVECTOR(dQ_obj,dQ,ndQ);
38  OUTVECTOR(R_obj,R,nR);
39  if (nQi != nRi) {
40#ifndef BROKEN_EXCEPTIONS
41    PyErr_SetString(PyExc_ValueError, "_librefl.convolve: Qi and Ri have different lengths");
42#endif
43    return NULL;
44  }
45  if (nQ != ndQ || nQ != nR) {
46#ifndef BROKEN_EXCEPTIONS
47    PyErr_SetString(PyExc_ValueError, "_librefl.convolve: Q, dQ and R have different lengths");
48#endif
49    return NULL;
50  }
51  resolution(nQi,Qi,Ri,nQ,Q,dQ,R);
52  return Py_BuildValue("");
53}
54
55static PyMethodDef methods[] = {
56   {"convolve",
57    Pconvolve,
58    METH_VARARGS,
59    "convolve(Qi,Ri,Q,dQ,R): compute convolution of width dQ[k] at points Q[k], returned in R[k]"},
60    {0}
61} ;
62
63
64#if defined(WIN32) && !defined(__MINGW32__)
65__declspec(dllexport)
66#endif
67
68       
69extern "C" void init_modeling(void) {
70  Py_InitModule4("_modeling",
71                methods,
72                "Modeling C Library",
73                0,
74                PYTHON_API_VERSION
75                );
76}
Note: See TracBrowser for help on using the repository browser.