source: sasview/sansmodels/src/sans/models/c_models/COblateModel.cpp @ ecc58e72

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 ecc58e72 was 9bd69098, checked in by Jae Cho <jhjcho@…>, 15 years ago

recompiled all due to Alina's new eval(run) function

  • Property mode set to 100644
File size: 23.7 KB
Line 
1/**
2        This software was developed by the University of Tennessee as part of the
3        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4        project funded by the US National Science Foundation.
5
6        If you use DANSE applications to do scientific research that leads to
7        publication, we ask that you acknowledge the use of the software with the
8        following sentence:
9
10        "This work benefited from DANSE software developed under NSF award DMR-0520547."
11
12        copyright 2008, University of Tennessee
13 */
14
15/** COblateModel
16 *
17 * C extension
18 *
19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
20 *          DO NOT MODIFY THIS FILE, MODIFY oblate.h
21 *          AND RE-RUN THE GENERATOR SCRIPT
22 *
23 */
24#define NO_IMPORT_ARRAY
25#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
26 
27extern "C" {
28#include <Python.h>
29#include <arrayobject.h>
30#include "structmember.h"
31#include <stdio.h>
32#include <stdlib.h>
33#include <math.h>
34#include <time.h>
35#include "oblate.h"
36}
37
38#include "models.hh"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * COblateModelError = NULL;
43
44
45// Class definition
46typedef struct {
47    PyObject_HEAD
48    /// Parameters
49    PyObject * params;
50    /// Dispersion parameters
51    PyObject * dispersion;
52    /// Underlying model object
53    OblateModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} COblateModel;
57
58
59static void
60COblateModel_dealloc(COblateModel* self)
61{
62    self->ob_type->tp_free((PyObject*)self);
63   
64
65}
66
67static PyObject *
68COblateModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
69{
70    COblateModel *self;
71   
72    self = (COblateModel *)type->tp_alloc(type, 0);
73   
74    return (PyObject *)self;
75}
76
77static int
78COblateModel_init(COblateModel *self, PyObject *args, PyObject *kwds)
79{
80    if (self != NULL) {
81       
82        // Create parameters
83        self->params = PyDict_New();
84        self->dispersion = PyDict_New();
85        self->model = new OblateModel();
86       
87        // Initialize parameter dictionary
88        PyDict_SetItemString(self->params,"major_core",Py_BuildValue("d",200.000000));
89        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000));
90        PyDict_SetItemString(self->params,"minor_core",Py_BuildValue("d",20.000000));
91        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
92        PyDict_SetItemString(self->params,"sld_solvent",Py_BuildValue("d",0.000006));
93        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
94        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.001000));
95        PyDict_SetItemString(self->params,"major_shell",Py_BuildValue("d",250.000000));
96        PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000001));
97        PyDict_SetItemString(self->params,"minor_shell",Py_BuildValue("d",30.000000));
98        // Initialize dispersion / averaging parameter dict
99        DispersionVisitor* visitor = new DispersionVisitor();
100        PyObject * disp_dict;
101        disp_dict = PyDict_New();
102        self->model->major_core.dispersion->accept_as_source(visitor, self->model->major_core.dispersion, disp_dict);
103        PyDict_SetItemString(self->dispersion, "major_core", disp_dict);
104        disp_dict = PyDict_New();
105        self->model->minor_core.dispersion->accept_as_source(visitor, self->model->minor_core.dispersion, disp_dict);
106        PyDict_SetItemString(self->dispersion, "minor_core", disp_dict);
107        disp_dict = PyDict_New();
108        self->model->major_shell.dispersion->accept_as_source(visitor, self->model->major_shell.dispersion, disp_dict);
109        PyDict_SetItemString(self->dispersion, "major_shell", disp_dict);
110        disp_dict = PyDict_New();
111        self->model->minor_shell.dispersion->accept_as_source(visitor, self->model->minor_shell.dispersion, disp_dict);
112        PyDict_SetItemString(self->dispersion, "minor_shell", disp_dict);
113
114
115         
116        // Create empty log
117        self->log = PyDict_New();
118       
119       
120
121    }
122    return 0;
123}
124
125static PyMemberDef COblateModel_members[] = {
126    {"params", T_OBJECT, offsetof(COblateModel, params), 0,
127     "Parameters"},
128        {"dispersion", T_OBJECT, offsetof(COblateModel, dispersion), 0,
129          "Dispersion parameters"},     
130    {"log", T_OBJECT, offsetof(COblateModel, log), 0,
131     "Log"},
132    {NULL}  /* Sentinel */
133};
134
135/** Read double from PyObject
136    @param p PyObject
137    @return double
138*/
139double COblateModel_readDouble(PyObject *p) {
140    if (PyFloat_Check(p)==1) {
141        return (double)(((PyFloatObject *)(p))->ob_fval);
142    } else if (PyInt_Check(p)==1) {
143        return (double)(((PyIntObject *)(p))->ob_ival);
144    } else if (PyLong_Check(p)==1) {
145        return (double)PyLong_AsLong(p);
146    } else {
147        return 0.0;
148    }
149}
150/**
151 * Function to call to evaluate model
152 * @param args: input numpy array q[]
153 * @return: numpy array object
154 */
155 
156static PyObject *evaluateOneDim(OblateModel* model, PyArrayObject *q){
157    PyArrayObject *result;
158   
159    // Check validity of array q , q must be of dimension 1, an array of double
160    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
161    {
162        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
163        //PyErr_SetString(PyExc_ValueError , message);
164        return NULL;
165    }
166    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 
167                                                                                  PyArray_DOUBLE);
168        if (result == NULL) {
169        const char * message= "Could not create result ";
170        PyErr_SetString(PyExc_RuntimeError , message);
171                return NULL;
172        }
173         for (int i = 0; i < q->dimensions[0]; i++){
174      double q_value  = *(double *)(q->data + i*q->strides[0]);
175      double *result_value = (double *)(result->data + i*result->strides[0]);
176      *result_value =(*model)(q_value);
177        }
178    return PyArray_Return(result); 
179 }
180/**
181 * Function to call to evaluate model
182 * @param args: input numpy array  [q[],phi[]]
183 * @return: numpy array object
184 */
185static PyObject * evaluateTwoDim( OblateModel* model, 
186                              PyArrayObject *q, PyArrayObject *phi)
187 {
188    PyArrayObject *result;
189    //check validity of input vectors
190    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE
191        || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE
192        || phi->dimensions[0] != q->dimensions[0]){
193     
194        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
195        PyErr_SetString(PyExc_ValueError ,"wrong input"); 
196        return NULL;
197    }
198        result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE);
199
200        if (result == NULL){
201            const char * message= "Could not create result ";
202        PyErr_SetString(PyExc_RuntimeError , message);
203            return NULL;
204        }
205       
206    for (int i = 0; i < q->dimensions[0]; i++) {
207      double q_value = *(double *)(q->data + i*q->strides[0]);
208      double phi_value = *(double *)(phi->data + i*phi->strides[0]);
209      double *result_value = (double *)(result->data + i*result->strides[0]);
210      if (q_value == 0)
211          *result_value = 0.0;
212      else
213          *result_value = model->evaluate_rphi(q_value, phi_value);
214    }
215    return PyArray_Return(result); 
216 }
217 /**
218 * Function to call to evaluate model
219 * @param args: input numpy array  [x[],y[]]
220 * @return: numpy array object
221 */
222 static PyObject * evaluateTwoDimXY( OblateModel* model, 
223                              PyArrayObject *x, PyArrayObject *y)
224 {
225    PyArrayObject *result;
226    int i,j, x_len, y_len, dims[2];
227    //check validity of input vectors
228    if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE
229        || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE
230        || y->dimensions[1] != x->dimensions[0]){
231        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
232        PyErr_SetString(PyExc_ValueError , message); 
233        return NULL;
234    }
235   
236        if (PyArray_Check(x) && PyArray_Check(y)) {
237            x_len = dims[0]= x->dimensions[0];
238        y_len = dims[1]= y->dimensions[1];
239           
240            // Make a new double matrix of same dims
241        result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE);
242        if (result == NULL){
243            const char * message= "Could not create result ";
244        PyErr_SetString(PyExc_RuntimeError , message);
245            return NULL;
246            }
247       
248        /* Do the calculation. */
249        for ( i=0; i< x_len; i++) {
250            for ( j=0; j< y_len; j++) {
251                double x_value = *(double *)(x->data + i*x->strides[0]);
252                    double y_value = *(double *)(y->data + j*y->strides[1]);
253                        double *result_value = (double *)(result->data +
254                              i*result->strides[0] + j*result->strides[1]);
255                        *result_value = (*model)(x_value, y_value);
256            }           
257        }
258        return PyArray_Return(result); 
259       
260        }else{
261                    PyErr_SetString(COblateModelError, 
262                   "COblateModel.evaluateTwoDimXY couldn't run.");
263                return NULL;
264                }       
265}
266/**
267 *  evalDistribution function evaluate a model function with input vector
268 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
269 *
270 */ 
271static PyObject * evalDistribution(COblateModel *self, PyObject *args){
272        PyObject *qx, *qy;
273        PyArrayObject * pars;
274        int npars ,mpars;
275       
276        // Get parameters
277       
278            // Reader parameter dictionary
279    self->model->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
280    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
281    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
282    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
283    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
284    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
285    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
286    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
287    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
288    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
289    // Read in dispersion parameters
290    PyObject* disp_dict;
291    DispersionVisitor* visitor = new DispersionVisitor();
292    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
293    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
294    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
295    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
296    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
297    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
298    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
299    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
300
301       
302        // Get input and determine whether we have to supply a 1D or 2D return value.
303        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
304            PyErr_SetString(COblateModelError, 
305                "COblateModel.evalDistribution expects a q value.");
306                return NULL;
307        }
308    // Check params
309       
310    if(PyArray_Check(pars)==1) {
311               
312            // Length of list should 1 or 2
313            npars = pars->nd; 
314            if(npars==1) {
315                // input is a numpy array
316                if (PyArray_Check(pars)) {
317                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
318                    }
319                }else{
320                    PyErr_SetString(COblateModelError, 
321                   "COblateModel.evalDistribution expect numpy array of one dimension.");
322                return NULL;
323                }
324    }else if( PyList_Check(pars)==1) {
325        // Length of list should be 2 for I(qx,qy)
326            mpars = PyList_GET_SIZE(pars); 
327            if(mpars!=2) {
328                PyErr_SetString(COblateModelError, 
329                        "COblateModel.evalDistribution expects a list of dimension 2.");
330                return NULL;
331            }
332             qx = PyList_GET_ITEM(pars,0);
333             qy = PyList_GET_ITEM(pars,1);
334             if (PyArray_Check(qx) && PyArray_Check(qy)) {
335                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
336                           (PyArrayObject*)qy);
337                 }else{
338                    PyErr_SetString(COblateModelError, 
339                   "COblateModel.evalDistribution expect 2 numpy arrays in list.");
340                return NULL;
341             }
342        }else{
343            PyErr_SetString(COblateModelError, 
344                   "COblateModel.evalDistribution couln't be run.");
345            return NULL;
346        }
347}
348
349/**
350 * Function to call to evaluate model
351 * @param args: input q or [q,phi]
352 * @return: function value
353 */
354static PyObject * run(COblateModel *self, PyObject *args) {
355        double q_value, phi_value;
356        PyObject* pars;
357        int npars;
358       
359        // Get parameters
360       
361            // Reader parameter dictionary
362    self->model->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
363    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
364    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
365    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
366    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
367    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
368    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
369    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
370    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
371    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
372    // Read in dispersion parameters
373    PyObject* disp_dict;
374    DispersionVisitor* visitor = new DispersionVisitor();
375    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
376    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
377    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
378    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
379    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
380    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
381    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
382    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
383
384       
385        // Get input and determine whether we have to supply a 1D or 2D return value.
386        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
387            PyErr_SetString(COblateModelError, 
388                "COblateModel.run expects a q value.");
389                return NULL;
390        }
391         
392        // Check params
393        if( PyList_Check(pars)==1) {
394               
395                // Length of list should be 2 for I(q,phi)
396            npars = PyList_GET_SIZE(pars); 
397            if(npars!=2) {
398                PyErr_SetString(COblateModelError, 
399                        "COblateModel.run expects a double or a list of dimension 2.");
400                return NULL;
401            }
402            // We have a vector q, get the q and phi values at which
403            // to evaluate I(q,phi)
404            q_value = COblateModel_readDouble(PyList_GET_ITEM(pars,0));
405            phi_value = COblateModel_readDouble(PyList_GET_ITEM(pars,1));
406            // Skip zero
407            if (q_value==0) {
408                return Py_BuildValue("d",0.0);
409            }
410                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
411
412        } else {
413
414                // We have a scalar q, we will evaluate I(q)
415                q_value = COblateModel_readDouble(pars);               
416               
417                return Py_BuildValue("d",(*(self->model))(q_value));
418        }       
419}
420
421/**
422 * Function to call to evaluate model in cartesian coordinates
423 * @param args: input q or [qx, qy]]
424 * @return: function value
425 */
426static PyObject * runXY(COblateModel *self, PyObject *args) {
427        double qx_value, qy_value;
428        PyObject* pars;
429        int npars;
430       
431        // Get parameters
432       
433            // Reader parameter dictionary
434    self->model->major_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_core") );
435    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
436    self->model->minor_core = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_core") );
437    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
438    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
439    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
440    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
441    self->model->major_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "major_shell") );
442    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
443    self->model->minor_shell = PyFloat_AsDouble( PyDict_GetItemString(self->params, "minor_shell") );
444    // Read in dispersion parameters
445    PyObject* disp_dict;
446    DispersionVisitor* visitor = new DispersionVisitor();
447    disp_dict = PyDict_GetItemString(self->dispersion, "major_core");
448    self->model->major_core.dispersion->accept_as_destination(visitor, self->model->major_core.dispersion, disp_dict);
449    disp_dict = PyDict_GetItemString(self->dispersion, "minor_core");
450    self->model->minor_core.dispersion->accept_as_destination(visitor, self->model->minor_core.dispersion, disp_dict);
451    disp_dict = PyDict_GetItemString(self->dispersion, "major_shell");
452    self->model->major_shell.dispersion->accept_as_destination(visitor, self->model->major_shell.dispersion, disp_dict);
453    disp_dict = PyDict_GetItemString(self->dispersion, "minor_shell");
454    self->model->minor_shell.dispersion->accept_as_destination(visitor, self->model->minor_shell.dispersion, disp_dict);
455
456       
457        // Get input and determine whether we have to supply a 1D or 2D return value.
458        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
459            PyErr_SetString(COblateModelError, 
460                "COblateModel.run expects a q value.");
461                return NULL;
462        }
463         
464        // Check params
465        if( PyList_Check(pars)==1) {
466               
467                // Length of list should be 2 for I(qx, qy))
468            npars = PyList_GET_SIZE(pars); 
469            if(npars!=2) {
470                PyErr_SetString(COblateModelError, 
471                        "COblateModel.run expects a double or a list of dimension 2.");
472                return NULL;
473            }
474            // We have a vector q, get the qx and qy values at which
475            // to evaluate I(qx,qy)
476            qx_value = COblateModel_readDouble(PyList_GET_ITEM(pars,0));
477            qy_value = COblateModel_readDouble(PyList_GET_ITEM(pars,1));
478            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
479
480        } else {
481
482                // We have a scalar q, we will evaluate I(q)
483                qx_value = COblateModel_readDouble(pars);               
484               
485                return Py_BuildValue("d",(*(self->model))(qx_value));
486        }       
487}
488
489static PyObject * reset(COblateModel *self, PyObject *args) {
490   
491
492    return Py_BuildValue("d",0.0);
493}
494
495static PyObject * set_dispersion(COblateModel *self, PyObject *args) {
496        PyObject * disp;
497        const char * par_name;
498
499        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
500            PyErr_SetString(COblateModelError,
501                "COblateModel.set_dispersion expects a DispersionModel object.");
502                return NULL;
503        }
504        void *temp = PyCObject_AsVoidPtr(disp);
505        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
506
507
508        // Ugliness necessary to go from python to C
509            // TODO: refactor this
510    if (!strcmp(par_name, "major_core")) {
511        self->model->major_core.dispersion = dispersion;
512    } else    if (!strcmp(par_name, "minor_core")) {
513        self->model->minor_core.dispersion = dispersion;
514    } else    if (!strcmp(par_name, "major_shell")) {
515        self->model->major_shell.dispersion = dispersion;
516    } else    if (!strcmp(par_name, "minor_shell")) {
517        self->model->minor_shell.dispersion = dispersion;
518    } else {
519            PyErr_SetString(COblateModelError,
520                "COblateModel.set_dispersion expects a valid parameter name.");
521                return NULL;
522        }
523
524        DispersionVisitor* visitor = new DispersionVisitor();
525        PyObject * disp_dict = PyDict_New();
526        dispersion->accept_as_source(visitor, dispersion, disp_dict);
527        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
528    return Py_BuildValue("i",1);
529}
530
531
532static PyMethodDef COblateModel_methods[] = {
533    {"run",      (PyCFunction)run     , METH_VARARGS,
534      "Evaluate the model at a given Q or Q, phi"},
535    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
536      "Evaluate the model at a given Q or Qx, Qy"},
537     
538    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
539      "Evaluate the model at a given Q or Qx, Qy vector "},
540    {"reset",    (PyCFunction)reset   , METH_VARARGS,
541      "Reset pair correlation"},
542    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
543      "Set the dispersion model for a given parameter"},
544   {NULL}
545};
546
547static PyTypeObject COblateModelType = {
548    PyObject_HEAD_INIT(NULL)
549    0,                         /*ob_size*/
550    "COblateModel",             /*tp_name*/
551    sizeof(COblateModel),             /*tp_basicsize*/
552    0,                         /*tp_itemsize*/
553    (destructor)COblateModel_dealloc, /*tp_dealloc*/
554    0,                         /*tp_print*/
555    0,                         /*tp_getattr*/
556    0,                         /*tp_setattr*/
557    0,                         /*tp_compare*/
558    0,                         /*tp_repr*/
559    0,                         /*tp_as_number*/
560    0,                         /*tp_as_sequence*/
561    0,                         /*tp_as_mapping*/
562    0,                         /*tp_hash */
563    0,                         /*tp_call*/
564    0,                         /*tp_str*/
565    0,                         /*tp_getattro*/
566    0,                         /*tp_setattro*/
567    0,                         /*tp_as_buffer*/
568    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
569    "COblateModel objects",           /* tp_doc */
570    0,                         /* tp_traverse */
571    0,                         /* tp_clear */
572    0,                         /* tp_richcompare */
573    0,                         /* tp_weaklistoffset */
574    0,                         /* tp_iter */
575    0,                         /* tp_iternext */
576    COblateModel_methods,             /* tp_methods */
577    COblateModel_members,             /* tp_members */
578    0,                         /* tp_getset */
579    0,                         /* tp_base */
580    0,                         /* tp_dict */
581    0,                         /* tp_descr_get */
582    0,                         /* tp_descr_set */
583    0,                         /* tp_dictoffset */
584    (initproc)COblateModel_init,      /* tp_init */
585    0,                         /* tp_alloc */
586    COblateModel_new,                 /* tp_new */
587};
588
589
590//static PyMethodDef module_methods[] = {
591//    {NULL}
592//};
593
594/**
595 * Function used to add the model class to a module
596 * @param module: module to add the class to
597 */ 
598void addCOblateModel(PyObject *module) {
599        PyObject *d;
600       
601    if (PyType_Ready(&COblateModelType) < 0)
602        return;
603
604    Py_INCREF(&COblateModelType);
605    PyModule_AddObject(module, "COblateModel", (PyObject *)&COblateModelType);
606   
607    d = PyModule_GetDict(module);
608    COblateModelError = PyErr_NewException("COblateModel.error", NULL, NULL);
609    PyDict_SetItemString(d, "COblateModelError", COblateModelError);
610}
611
Note: See TracBrowser for help on using the repository browser.