Index: sansmodels/src/c_gen/sld2i.cpp
===================================================================
--- sansmodels/src/c_gen/sld2i.cpp	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
+++ sansmodels/src/c_gen/sld2i.cpp	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
@@ -0,0 +1,133 @@
+/**
+Computes the (magnetic) scattering form sld (n and m) profile
+ */
+#include "sld2i.hh"
+#include <stdio.h>
+#include <math.h>
+using namespace std;
+extern "C" {
+	#include "libmultifunc/libfunc.h"
+	#include "libmultifunc/librefl.h"
+}
+/**
+ * Constructor for GenI
+ *
+ * binning
+ * //@param qx: array of Qx values
+ * //@param qy: array of Qy values
+ * //@param qz: array of Qz values
+ * @param x: array of x values
+ * @param y: array of y values
+ * @param z: array of z values
+ * @param sldn: array of sld n
+ * @param mx: array of sld mx
+ * @param my: array of sld my
+ * @param mz: array of sld mz
+ * @param in_spin: ratio of up spin in Iin
+ * @param out_spin: ratio of up spin in Iout
+ * @param s_theta: angle (from x-axis) of the up spin in degree
+ */
+GenI :: GenI(int npix, double* x, double* y, double* z, double* sldn,
+			double* mx, double* my, double* mz,
+			double in_spin, double out_spin,
+			double s_theta) {
+	//this->qx_val = qx;
+	//this->qy_val = qy;
+	//this->qz_val = qz;
+	this->n_pix = npix;
+	this->x_val = x;
+	this->y_val = y;
+	this->z_val = z;
+	this->sldn_val = sldn;
+	this->mx_val = mx;
+	this->my_val = my;
+	this->mz_val = mz;
+	this->inspin = in_spin;
+	this->outspin = out_spin;
+	this->stheta = s_theta;
+};
+
+/**
+ * Compute
+ */
+void GenI :: genicom(int npoints, double *qx, double *qy, double *I_out){
+	double q = 0.0;
+	//double Pi = 4.0*atan(1.0);
+	polar_sld b_sld;
+	double qr = 0.0;
+	complex iqr = cassign(0.0, 0.0);
+	complex ephase = cassign(0.0, 0.0);
+	complex comp_sld = cassign(0.0, 0.0);
+	complex sumj;
+	complex sumj_uu;
+	complex sumj_ud;
+	complex sumj_du;
+	complex sumj_dd;
+	complex temp_fi;
+
+	int count = 0;
+	//Assume that all pixels are in same size and int * 1A
+	//int x_size = 0; //in Ang
+	//int y_size = 0; //in Ang
+	//int z_size = 0; //in Ang
+	// Loop over q-values and multiply apply matrix
+
+	for(int i=0; i<npoints; i++){
+		//I_out[i] = 0.0;
+		sumj = cassign(0.0, 0.0);
+		sumj_uu = cassign(0.0, 0.0);
+		sumj_ud = cassign(0.0, 0.0);
+		sumj_du = cassign(0.0, 0.0);
+		sumj_dd = cassign(0.0, 0.0);		
+		//printf ("%d ", i);
+		q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]);
+
+		for(int j=0; j<n_pix; j++){
+			
+			if (sldn_val[j]!=0.0||mx_val[j]!=0.0||my_val[j]!=0.0||mz_val[j]!=0.0)
+			{	
+				temp_fi = cassign(0.0, 0.0);
+				b_sld = cal_msld(0, qx[i], qy[i], sldn_val[j],
+								 mx_val[j], my_val[j], mz_val[j],
+				 				 inspin, outspin, stheta);
+				qr = (qx[i]*x_val[j] + qy[i]*y_val[j]);
+				iqr = cassign(0.0, qr);
+				ephase = cplx_exp(iqr);
+				//up_up
+				if (inspin > 0.0 && outspin > 0.0){
+					comp_sld = cassign(b_sld.uu, 0.0);
+					temp_fi = cplx_mult(comp_sld, ephase);
+					sumj_uu = cplx_add(sumj_uu, temp_fi);
+					}
+				//down_down
+				if (inspin < 1.0 && outspin < 1.0){
+					comp_sld = cassign(b_sld.dd, 0.0);
+					temp_fi = cplx_mult(comp_sld, ephase);
+					sumj_dd = cplx_add(sumj_dd, temp_fi);
+					}
+				//up_down
+				if (inspin > 0.0 && outspin < 1.0){
+					comp_sld = cassign(b_sld.re_ud, b_sld.im_ud);
+					temp_fi = cplx_mult(comp_sld, ephase);
+					sumj_ud = cplx_add(sumj_ud, temp_fi);
+					}
+				//down_up
+				if (inspin < 1.0 && outspin > 0.0){
+					comp_sld = cassign(b_sld.re_du, b_sld.im_du);
+					temp_fi = cplx_mult(comp_sld, ephase);
+					sumj_du = cplx_add(sumj_du, temp_fi);
+					}
+				if (i == 0){
+					count += 1;
+				}
+			}
+		}
+		//printf("aa%d=%g %g %d\n", i, (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im), (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im), count);
+		I_out[i] = (sumj_uu.re*sumj_uu.re + sumj_uu.im*sumj_uu.im);
+		I_out[i] += (sumj_ud.re*sumj_ud.re + sumj_ud.im*sumj_ud.im);
+		I_out[i] += (sumj_du.re*sumj_du.re + sumj_du.im*sumj_du.im);
+		I_out[i] += (sumj_dd.re*sumj_dd.re + sumj_dd.im*sumj_dd.im);
+		I_out[i] *= (1.0E+8 / count); //in cm (unit) / number; //to be multiplied by vol_pix
+	}
+	//printf ("count = %d %g %g %g %g\n", count, sldn_val[0],mx_val[0], my_val[0], mz_val[0]);
+}
Index: sansmodels/src/c_gen/sld2i.hh
===================================================================
--- sansmodels/src/c_gen/sld2i.hh	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
+++ sansmodels/src/c_gen/sld2i.hh	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
@@ -0,0 +1,43 @@
+/**
+Computes the (magnetic) scattering form sld (n and m) profile
+ */
+#ifndef SLD2I_CLASS_H
+#define SLD2I_CLASS_H
+
+#include <vector>
+
+using namespace std;
+
+/**
+ * Base class
+ */
+class GenI {
+protected:
+	vector<double>* I_out;
+	// vectors
+	int n_pix;
+	double* qx;
+	double* qy;
+	double* x_val;
+	double* y_val;
+	double* z_val;
+	double* sldn_val;
+	double* mx_val;
+	double* my_val;
+	double* mz_val;
+    // spin ratios
+    double inspin;
+    double outspin;
+    double stheta;
+
+public:
+    // Constructor
+	GenI(int npix, double* x, double* y, double* z, double* sldn, 
+			double* mx, double* my, double* mz, 
+			double in_spin, double out_spin,
+			double s_theta);
+	// compute function
+	virtual void genicom(int npoints, double* qx, double* qy, double *I_out);
+};
+
+#endif
Index: sansmodels/src/c_gen/sld2i_module.cpp
===================================================================
--- sansmodels/src/c_gen/sld2i_module.cpp	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
+++ sansmodels/src/c_gen/sld2i_module.cpp	(revision 318b5bbbcb046db18a8e953dccae04fc7b8a71e0)
@@ -0,0 +1,127 @@
+/**
+  SLD2I module to perform point and I calculations
+ */
+#include <Python.h>
+#include <stdio.h>
+#include <sld2i.hh>
+
+// Utilities
+#define INVECTOR(obj,buf,len)										\
+    do { \
+        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
+        if (err < 0) return NULL; \
+        len /= sizeof(*buf); \
+    } while (0)
+
+#define OUTVECTOR(obj,buf,len) \
+    do { \
+        int err = PyObject_AsWriteBuffer(obj, (void **)(&buf), &len); \
+        if (err < 0) return NULL; \
+        len /= sizeof(*buf); \
+    } while (0)
+
+
+/**
+ * Delete a GenI object
+ */
+void del_sld2i(void *ptr){
+	GenI* sld2i = static_cast<GenI *>(ptr);
+	delete sld2i;
+	return;
+}
+
+/**
+ * Create a GenI as a python object by supplying arrays
+ */
+PyObject * new_GenI(PyObject *, PyObject *args) {
+	PyObject *x_val_obj;
+	PyObject *y_val_obj;
+	PyObject *z_val_obj;
+	PyObject *sldn_val_obj;
+	PyObject *mx_val_obj;
+	PyObject *my_val_obj;
+	PyObject *mz_val_obj;
+	Py_ssize_t n_x;
+	//PyObject rlimit_obj;
+	//PyObject npoints_obj;
+	//PyObject nrbins_obj;
+	//PyObject nphibins_obj;
+	int n_pix;
+	double* x_val;
+	double* y_val;
+	double* z_val;
+	double* sldn_val;
+	double* mx_val;
+	double* my_val;
+	double* mz_val;
+	double inspin;
+	double outspin;
+	double stheta;
+
+	if (!PyArg_ParseTuple(args, "iOOOOOOOddd", &n_pix, &x_val_obj, &y_val_obj, &z_val_obj, &sldn_val_obj, &mx_val_obj, &my_val_obj, &mz_val_obj, &inspin, &outspin, &stheta)) return NULL;
+	OUTVECTOR(x_val_obj, x_val, n_x);
+	OUTVECTOR(y_val_obj, y_val, n_x);
+	OUTVECTOR(z_val_obj, z_val, n_x);
+	OUTVECTOR(sldn_val_obj, sldn_val, n_x);
+	OUTVECTOR(mx_val_obj, mx_val, n_x);
+	OUTVECTOR(my_val_obj, my_val, n_x);
+	OUTVECTOR(mz_val_obj, mz_val, n_x);
+	GenI* sld2i = new GenI(n_pix,x_val,y_val,z_val,sldn_val,mx_val,my_val,mz_val,inspin,outspin,stheta);
+	return PyCObject_FromVoidPtr(sld2i, del_sld2i);
+}
+
+/**
+ * GenI the given input according to a given object
+ */
+PyObject * genicom_input(PyObject *, PyObject *args) {
+	int npoints;
+	PyObject *qx_obj;
+	double *qx;
+	PyObject *qy_obj;
+	double *qy;
+	PyObject *I_out_obj;
+	Py_ssize_t n_out;
+	double *I_out;
+	PyObject *gen_obj;
+
+	if (!PyArg_ParseTuple(args, "OiOOO",  &gen_obj, &npoints, &qx_obj, &qy_obj, &I_out_obj)) return NULL;
+	OUTVECTOR(qx_obj, qx, n_out);
+	OUTVECTOR(qy_obj, qy, n_out);
+	OUTVECTOR(I_out_obj, I_out, n_out);
+
+	// Sanity check
+	//if(n_in!=n_out) return Py_BuildValue("i",-1);
+
+	// Set the array pointers
+	void *temp = PyCObject_AsVoidPtr(gen_obj);
+	GenI* s = static_cast<GenI *>(temp);
+
+	s->genicom(npoints, qx, qy, I_out);
+	//return PyCObject_FromVoidPtr(s, del_genicom);
+	return Py_BuildValue("i",1);
+}
+
+
+/**
+ * Define module methods
+ */
+static PyMethodDef module_methods[] = {
+	{"new_GenI", (PyCFunction)new_GenI, METH_VARARGS,
+		  "Create a new GenI object"},
+	{"genicom",(PyCFunction)genicom_input, METH_VARARGS,
+		  "genicom the given input arrays"},
+    {NULL}
+};
+
+
+#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
+#endif
+PyMODINIT_FUNC
+initsld2i(void)
+{
+    PyObject* m;
+
+    m = Py_InitModule3("sld2i", module_methods,
+                       "Sld2i module");
+}
