Changeset 9316609 in sasview for sansmodels/src/sans/models/c_extensions/CSphereModel.c
- Timestamp:
- Oct 28, 2008 3:22:22 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 92320e5
- Parents:
- 89fef2c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/c_extensions/CSphereModel.c
rae3ce4e r9316609 1 /** CSphereModel1 /** [PYTHONCLASS] 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * CSphereModelError = NULL;22 static PyObject * [PYTHONCLASS]Error = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 SphereParameters model_pars; 34 } CSphereModel;34 } [PYTHONCLASS]; 35 35 36 36 37 37 static void 38 CSphereModel_dealloc(CSphereModel* self)38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 CSphereModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 CSphereModel*self;49 50 self = ( CSphereModel*)type->tp_alloc(type, 0);48 [PYTHONCLASS] *self; 49 50 self = ([PYTHONCLASS] *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 CSphereModel_init(CSphereModel*self, PyObject *args, PyObject *kwds)56 [PYTHONCLASS]_init([PYTHONCLASS] *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 77 77 } 78 78 79 static PyMemberDef CSphereModel_members[] = {80 {"params", T_OBJECT, offsetof( CSphereModel, params), 0,79 static PyMemberDef [PYTHONCLASS]_members[] = { 80 {"params", T_OBJECT, offsetof([PYTHONCLASS], params), 0, 81 81 "Parameters"}, 82 {"log", T_OBJECT, offsetof( CSphereModel, log), 0,82 {"log", T_OBJECT, offsetof([PYTHONCLASS], log), 0, 83 83 "Log"}, 84 84 {NULL} /* Sentinel */ … … 89 89 @return double 90 90 */ 91 double CSphereModel_readDouble(PyObject *p) {91 double [PYTHONCLASS]_readDouble(PyObject *p) { 92 92 if (PyFloat_Check(p)==1) { 93 93 return (double)(((PyFloatObject *)(p))->ob_fval); … … 107 107 * @return: function value 108 108 */ 109 static PyObject * run( CSphereModel*self, PyObject *args) {109 static PyObject * run([PYTHONCLASS] *self, PyObject *args) { 110 110 double q_value, phi_value; 111 111 PyObject* pars; … … 123 123 // Get input and determine whether we have to supply a 1D or 2D return value. 124 124 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 125 PyErr_SetString( CSphereModelError,126 " CSphereModel.run expects a q value.");125 PyErr_SetString([PYTHONCLASS]Error, 126 "[PYTHONCLASS].run expects a q value."); 127 127 return NULL; 128 128 } … … 134 134 npars = PyList_GET_SIZE(pars); 135 135 if(npars!=2) { 136 PyErr_SetString( CSphereModelError,137 " CSphereModel.run expects a double or a list of dimension 2.");136 PyErr_SetString([PYTHONCLASS]Error, 137 "[PYTHONCLASS].run expects a double or a list of dimension 2."); 138 138 return NULL; 139 139 } 140 140 // We have a vector q, get the q and phi values at which 141 141 // to evaluate I(q,phi) 142 q_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0));143 phi_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1));142 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 143 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 144 144 // Skip zero 145 145 if (q_value==0) { … … 151 151 152 152 // We have a scalar q, we will evaluate I(q) 153 q_value = CSphereModel_readDouble(pars);153 q_value = [PYTHONCLASS]_readDouble(pars); 154 154 155 155 return Py_BuildValue("d",sphere_analytical_1D(&(self->model_pars),q_value)); … … 162 162 * @return: function value 163 163 */ 164 static PyObject * runXY( CSphereModel*self, PyObject *args) {164 static PyObject * runXY([PYTHONCLASS] *self, PyObject *args) { 165 165 double qx_value, qy_value; 166 166 PyObject* pars; … … 178 178 // Get input and determine whether we have to supply a 1D or 2D return value. 179 179 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 180 PyErr_SetString( CSphereModelError,181 " CSphereModel.run expects a q value.");180 PyErr_SetString([PYTHONCLASS]Error, 181 "[PYTHONCLASS].run expects a q value."); 182 182 return NULL; 183 183 } … … 189 189 npars = PyList_GET_SIZE(pars); 190 190 if(npars!=2) { 191 PyErr_SetString( CSphereModelError,192 " CSphereModel.run expects a double or a list of dimension 2.");191 PyErr_SetString([PYTHONCLASS]Error, 192 "[PYTHONCLASS].run expects a double or a list of dimension 2."); 193 193 return NULL; 194 194 } 195 195 // We have a vector q, get the qx and qy values at which 196 196 // to evaluate I(qx,qy) 197 qx_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,0));198 qy_value = CSphereModel_readDouble(PyList_GET_ITEM(pars,1));197 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 198 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 199 199 return Py_BuildValue("d",sphere_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 200 200 … … 202 202 203 203 // We have a scalar q, we will evaluate I(q) 204 qx_value = CSphereModel_readDouble(pars);204 qx_value = [PYTHONCLASS]_readDouble(pars); 205 205 206 206 return Py_BuildValue("d",sphere_analytical_1D(&(self->model_pars),qx_value)); … … 208 208 } 209 209 210 static PyObject * reset( CSphereModel*self, PyObject *args) {210 static PyObject * reset([PYTHONCLASS] *self, PyObject *args) { 211 211 212 212 … … 215 215 216 216 217 static PyMethodDef CSphereModel_methods[] = {217 static PyMethodDef [PYTHONCLASS]_methods[] = { 218 218 {"run", (PyCFunction)run , METH_VARARGS, 219 219 "Evaluate the model at a given Q or Q, phi"}, … … 227 227 }; 228 228 229 static PyTypeObject CSphereModelType = {229 static PyTypeObject [PYTHONCLASS]Type = { 230 230 PyObject_HEAD_INIT(NULL) 231 231 0, /*ob_size*/ 232 " CSphereModel", /*tp_name*/233 sizeof( CSphereModel), /*tp_basicsize*/232 "[PYTHONCLASS]", /*tp_name*/ 233 sizeof([PYTHONCLASS]), /*tp_basicsize*/ 234 234 0, /*tp_itemsize*/ 235 (destructor) CSphereModel_dealloc, /*tp_dealloc*/235 (destructor)[PYTHONCLASS]_dealloc, /*tp_dealloc*/ 236 236 0, /*tp_print*/ 237 237 0, /*tp_getattr*/ … … 249 249 0, /*tp_as_buffer*/ 250 250 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 251 " CSphereModelobjects", /* tp_doc */251 "[PYTHONCLASS] objects", /* tp_doc */ 252 252 0, /* tp_traverse */ 253 253 0, /* tp_clear */ … … 256 256 0, /* tp_iter */ 257 257 0, /* tp_iternext */ 258 CSphereModel_methods, /* tp_methods */259 CSphereModel_members, /* tp_members */258 [PYTHONCLASS]_methods, /* tp_methods */ 259 [PYTHONCLASS]_members, /* tp_members */ 260 260 0, /* tp_getset */ 261 261 0, /* tp_base */ … … 264 264 0, /* tp_descr_set */ 265 265 0, /* tp_dictoffset */ 266 (initproc) CSphereModel_init, /* tp_init */266 (initproc)[PYTHONCLASS]_init, /* tp_init */ 267 267 0, /* tp_alloc */ 268 CSphereModel_new, /* tp_new */268 [PYTHONCLASS]_new, /* tp_new */ 269 269 }; 270 270 … … 278 278 * @param module: module to add the class to 279 279 */ 280 void add CSphereModel(PyObject *module) {280 void add[PYTHONCLASS](PyObject *module) { 281 281 PyObject *d; 282 282 283 if (PyType_Ready(& CSphereModelType) < 0)283 if (PyType_Ready(&[PYTHONCLASS]Type) < 0) 284 284 return; 285 285 286 Py_INCREF(& CSphereModelType);287 PyModule_AddObject(module, " CSphereModel", (PyObject *)&CSphereModelType);286 Py_INCREF(&[PYTHONCLASS]Type); 287 PyModule_AddObject(module, "[PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type); 288 288 289 289 d = PyModule_GetDict(module); 290 CSphereModelError = PyErr_NewException("CSphereModel.error", NULL, NULL);291 PyDict_SetItemString(d, " CSphereModelError", CSphereModelError);292 } 293 290 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL); 291 PyDict_SetItemString(d, "[PYTHONCLASS]Error", [PYTHONCLASS]Error); 292 } 293
Note: See TracChangeset
for help on using the changeset viewer.