Changeset 9316609 in sasview for sansmodels/src/sans/models/c_extensions/CEllipticalCylinderModel.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/CEllipticalCylinderModel.c
rae3ce4e r9316609 1 /** CEllipticalCylinderModel1 /** [PYTHONCLASS] 2 2 * 3 3 * C extension … … 20 20 21 21 /// Error object for raised exceptions 22 static PyObject * CEllipticalCylinderModelError = NULL;22 static PyObject * [PYTHONCLASS]Error = NULL; 23 23 24 24 … … 32 32 /// Model parameters 33 33 EllipticalCylinderParameters model_pars; 34 } CEllipticalCylinderModel;34 } [PYTHONCLASS]; 35 35 36 36 37 37 static void 38 CEllipticalCylinderModel_dealloc(CEllipticalCylinderModel* self)38 [PYTHONCLASS]_dealloc([PYTHONCLASS]* self) 39 39 { 40 40 self->ob_type->tp_free((PyObject*)self); … … 44 44 45 45 static PyObject * 46 CEllipticalCylinderModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)46 [PYTHONCLASS]_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 47 47 { 48 CEllipticalCylinderModel*self;48 [PYTHONCLASS] *self; 49 49 50 self = ( CEllipticalCylinderModel*)type->tp_alloc(type, 0);50 self = ([PYTHONCLASS] *)type->tp_alloc(type, 0); 51 51 52 52 return (PyObject *)self; … … 54 54 55 55 static int 56 CEllipticalCylinderModel_init(CEllipticalCylinderModel*self, PyObject *args, PyObject *kwds)56 [PYTHONCLASS]_init([PYTHONCLASS] *self, PyObject *args, PyObject *kwds) 57 57 { 58 58 if (self != NULL) { … … 82 82 } 83 83 84 static PyMemberDef CEllipticalCylinderModel_members[] = {85 {"params", T_OBJECT, offsetof( CEllipticalCylinderModel, params), 0,84 static PyMemberDef [PYTHONCLASS]_members[] = { 85 {"params", T_OBJECT, offsetof([PYTHONCLASS], params), 0, 86 86 "Parameters"}, 87 {"log", T_OBJECT, offsetof( CEllipticalCylinderModel, log), 0,87 {"log", T_OBJECT, offsetof([PYTHONCLASS], log), 0, 88 88 "Log"}, 89 89 {NULL} /* Sentinel */ … … 94 94 @return double 95 95 */ 96 double CEllipticalCylinderModel_readDouble(PyObject *p) {96 double [PYTHONCLASS]_readDouble(PyObject *p) { 97 97 if (PyFloat_Check(p)==1) { 98 98 return (double)(((PyFloatObject *)(p))->ob_fval); … … 112 112 * @return: function value 113 113 */ 114 static PyObject * run( CEllipticalCylinderModel*self, PyObject *args) {114 static PyObject * run([PYTHONCLASS] *self, PyObject *args) { 115 115 double q_value, phi_value; 116 116 PyObject* pars; … … 133 133 // Get input and determine whether we have to supply a 1D or 2D return value. 134 134 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 135 PyErr_SetString( CEllipticalCylinderModelError,136 " CEllipticalCylinderModel.run expects a q value.");135 PyErr_SetString([PYTHONCLASS]Error, 136 "[PYTHONCLASS].run expects a q value."); 137 137 return NULL; 138 138 } … … 144 144 npars = PyList_GET_SIZE(pars); 145 145 if(npars!=2) { 146 PyErr_SetString( CEllipticalCylinderModelError,147 " CEllipticalCylinderModel.run expects a double or a list of dimension 2.");146 PyErr_SetString([PYTHONCLASS]Error, 147 "[PYTHONCLASS].run expects a double or a list of dimension 2."); 148 148 return NULL; 149 149 } 150 150 // We have a vector q, get the q and phi values at which 151 151 // to evaluate I(q,phi) 152 q_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,0));153 phi_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,1));152 q_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 153 phi_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 154 154 // Skip zero 155 155 if (q_value==0) { … … 161 161 162 162 // We have a scalar q, we will evaluate I(q) 163 q_value = CEllipticalCylinderModel_readDouble(pars);163 q_value = [PYTHONCLASS]_readDouble(pars); 164 164 165 165 return Py_BuildValue("d",elliptical_cylinder_analytical_1D(&(self->model_pars),q_value)); … … 172 172 * @return: function value 173 173 */ 174 static PyObject * runXY( CEllipticalCylinderModel*self, PyObject *args) {174 static PyObject * runXY([PYTHONCLASS] *self, PyObject *args) { 175 175 double qx_value, qy_value; 176 176 PyObject* pars; … … 193 193 // Get input and determine whether we have to supply a 1D or 2D return value. 194 194 if ( !PyArg_ParseTuple(args,"O",&pars) ) { 195 PyErr_SetString( CEllipticalCylinderModelError,196 " CEllipticalCylinderModel.run expects a q value.");195 PyErr_SetString([PYTHONCLASS]Error, 196 "[PYTHONCLASS].run expects a q value."); 197 197 return NULL; 198 198 } … … 204 204 npars = PyList_GET_SIZE(pars); 205 205 if(npars!=2) { 206 PyErr_SetString( CEllipticalCylinderModelError,207 " CEllipticalCylinderModel.run expects a double or a list of dimension 2.");206 PyErr_SetString([PYTHONCLASS]Error, 207 "[PYTHONCLASS].run expects a double or a list of dimension 2."); 208 208 return NULL; 209 209 } 210 210 // We have a vector q, get the qx and qy values at which 211 211 // to evaluate I(qx,qy) 212 qx_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,0));213 qy_value = CEllipticalCylinderModel_readDouble(PyList_GET_ITEM(pars,1));212 qx_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,0)); 213 qy_value = [PYTHONCLASS]_readDouble(PyList_GET_ITEM(pars,1)); 214 214 return Py_BuildValue("d",elliptical_cylinder_analytical_2DXY(&(self->model_pars),qx_value,qy_value)); 215 215 … … 217 217 218 218 // We have a scalar q, we will evaluate I(q) 219 qx_value = CEllipticalCylinderModel_readDouble(pars);219 qx_value = [PYTHONCLASS]_readDouble(pars); 220 220 221 221 return Py_BuildValue("d",elliptical_cylinder_analytical_1D(&(self->model_pars),qx_value)); … … 223 223 } 224 224 225 static PyObject * reset( CEllipticalCylinderModel*self, PyObject *args) {225 static PyObject * reset([PYTHONCLASS] *self, PyObject *args) { 226 226 227 227 … … 230 230 231 231 232 static PyMethodDef CEllipticalCylinderModel_methods[] = {232 static PyMethodDef [PYTHONCLASS]_methods[] = { 233 233 {"run", (PyCFunction)run , METH_VARARGS, 234 234 "Evaluate the model at a given Q or Q, phi"}, … … 242 242 }; 243 243 244 static PyTypeObject CEllipticalCylinderModelType = {244 static PyTypeObject [PYTHONCLASS]Type = { 245 245 PyObject_HEAD_INIT(NULL) 246 246 0, /*ob_size*/ 247 " CEllipticalCylinderModel", /*tp_name*/248 sizeof( CEllipticalCylinderModel), /*tp_basicsize*/247 "[PYTHONCLASS]", /*tp_name*/ 248 sizeof([PYTHONCLASS]), /*tp_basicsize*/ 249 249 0, /*tp_itemsize*/ 250 (destructor) CEllipticalCylinderModel_dealloc, /*tp_dealloc*/250 (destructor)[PYTHONCLASS]_dealloc, /*tp_dealloc*/ 251 251 0, /*tp_print*/ 252 252 0, /*tp_getattr*/ … … 264 264 0, /*tp_as_buffer*/ 265 265 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 266 " CEllipticalCylinderModelobjects", /* tp_doc */266 "[PYTHONCLASS] objects", /* tp_doc */ 267 267 0, /* tp_traverse */ 268 268 0, /* tp_clear */ … … 271 271 0, /* tp_iter */ 272 272 0, /* tp_iternext */ 273 CEllipticalCylinderModel_methods, /* tp_methods */274 CEllipticalCylinderModel_members, /* tp_members */273 [PYTHONCLASS]_methods, /* tp_methods */ 274 [PYTHONCLASS]_members, /* tp_members */ 275 275 0, /* tp_getset */ 276 276 0, /* tp_base */ … … 279 279 0, /* tp_descr_set */ 280 280 0, /* tp_dictoffset */ 281 (initproc) CEllipticalCylinderModel_init, /* tp_init */281 (initproc)[PYTHONCLASS]_init, /* tp_init */ 282 282 0, /* tp_alloc */ 283 CEllipticalCylinderModel_new, /* tp_new */283 [PYTHONCLASS]_new, /* tp_new */ 284 284 }; 285 285 … … 293 293 * @param module: module to add the class to 294 294 */ 295 void add CEllipticalCylinderModel(PyObject *module) {295 void add[PYTHONCLASS](PyObject *module) { 296 296 PyObject *d; 297 297 298 if (PyType_Ready(& CEllipticalCylinderModelType) < 0)298 if (PyType_Ready(&[PYTHONCLASS]Type) < 0) 299 299 return; 300 300 301 Py_INCREF(& CEllipticalCylinderModelType);302 PyModule_AddObject(module, " CEllipticalCylinderModel", (PyObject *)&CEllipticalCylinderModelType);301 Py_INCREF(&[PYTHONCLASS]Type); 302 PyModule_AddObject(module, "[PYTHONCLASS]", (PyObject *)&[PYTHONCLASS]Type); 303 303 304 304 d = PyModule_GetDict(module); 305 CEllipticalCylinderModelError = PyErr_NewException("CEllipticalCylinderModel.error", NULL, NULL);306 PyDict_SetItemString(d, " CEllipticalCylinderModelError", CEllipticalCylinderModelError);307 } 308 305 [PYTHONCLASS]Error = PyErr_NewException("[PYTHONCLASS].error", NULL, NULL); 306 PyDict_SetItemString(d, "[PYTHONCLASS]Error", [PYTHONCLASS]Error); 307 } 308
Note: See TracChangeset
for help on using the changeset viewer.