static PyObject * _lineshape_lorentz(PyObject *self, PyObject *args, PyObject *keywds) { int f; double w, xc = 0.0; static char *kwlist[] = {"x", "w", "xc", "y", NULL}; PyObject *ox, *oy=Py_None; PyArrayObject *x, *y; if(! PyArg_ParseTupleAndKeywords(args, keywds, "Od|dO", kwlist, &ox, &w, &xc, &oy)) return PyErr_Format(PyExc_RuntimeError, "lorentz: invalid parameters"); if((f = PyFloat_Check(ox)) || PyInt_Check(ox)) { /* scalar arguments -- always *return* Float result */ double xa[1], ya[1]; if(f) xa[0] = PyFloat_AS_DOUBLE(ox); else xa[0] = (double)PyInt_AS_LONG(ox); Py_BEGIN_ALLOW_THREADS; lorentz(1, xa, ya, w, xc); Py_END_ALLOW_THREADS; Py_DECREF(ox); return PyFloat_FromDouble(ya[0]); } else { /* array conversion */ if(! ((x = NA_InputArray(ox, tFloat64, C_ARRAY)) && (y = NA_OptionalOutputArray(oy, tFloat64, C_ARRAY, x)))) return 0; if(x->nd != 1) return PyErr_Format(_Error, "lorentz: x must be scalar or 1d array."); if (!PyArray_SAMESHAPE(x, y)) return PyErr_Format(_Error, "lorentz: x and y numarray must have same length."); /* calculate profile */ { double *xa = PyArray_DATA(x); double *ya = PyArray_DATA(y); Py_BEGIN_ALLOW_THREADS; lorentz(x->dimensions[0], xa, ya, w, xc); Py_END_ALLOW_THREADS; } /* cleanup and return */ Py_XDECREF(x); return NA_ReturnOutput(oy, y); } }
int main() { int times; double step; printf("Please input the data in follow order: \n\r (times step) \n\r"); scanf("%d %lf",×,&step); lorentz(times,step); return 0; }
void spectrum(int *npts, double pts[][CRD_SIZE], double xmin, double xmax, double xstp, int ntrans, double trans[][CRD_SIZE]) { int i, j; double x = 0.; double sum = 0.; *npts=abs( (xmax - xmin) / xstp ) + 1; for (i=0; i<*npts; i++) { x = xmin + (double)i * xstp; sum = 0.; for (j=0; j<ntrans; j++) { sum+=lorentz(x, trans[j][0], trans[j][1], trans[j][2]); } pts[i][0] = x; pts[i][1] = sum; } }