Index: sansmodels/src/sans/models/c_models/classTemplate.txt
===================================================================
--- sansmodels/src/sans/models/c_models/classTemplate.txt	(revision 41764355342545e515f88e826088d1c5dbedf6ac)
+++ sansmodels/src/sans/models/c_models/classTemplate.txt	(revision 8344c5029e4ed7f30ffef7c8d0d06ee7cfa35ff2)
@@ -22,7 +22,10 @@
  *
  */
+#define NO_IMPORT_ARRAY
+#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
  
 extern "C" {
 #include <Python.h>
+#include <arrayobject.h>
 #include "structmember.h"
 #include <stdio.h>
@@ -116,5 +119,180 @@
     }
 }
-
+/**
+ * Function to call to evaluate model
+ * @param args: input numpy array q[] 
+ * @return: numpy array object 
+ */
+ 
+static PyObject *evaluateOneDim([CMODEL]* model, PyArrayObject *q){
+    PyArrayObject *result;
+   
+    // Check validity of array q , q must be of dimension 1, an array of double
+    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
+    {
+        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
+        //PyErr_SetString(PyExc_ValueError , message);
+        return NULL;
+    }
+    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 
+										  PyArray_DOUBLE);
+	if (result == NULL) {
+        const char * message= "Could not create result ";
+        PyErr_SetString(PyExc_RuntimeError , message);
+		return NULL;
+	}
+	 for (int i = 0; i < q->dimensions[0]; i++){
+      double q_value  = *(double *)(q->data + i*q->strides[0]);
+      double *result_value = (double *)(result->data + i*result->strides[0]);
+      *result_value =(*model)(q_value);
+	}
+    return PyArray_Return(result); 
+ }
+/**
+ * Function to call to evaluate model
+ * @param args: input numpy array  [q[],phi[]]
+ * @return: numpy array object 
+ */
+static PyObject * evaluateTwoDim( [CMODEL]* model, 
+                              PyArrayObject *q, PyArrayObject *phi)
+ {
+    PyArrayObject *result;
+    //check validity of input vectors
+    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE
+        || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE
+        || phi->dimensions[0] != q->dimensions[0]){
+     
+        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
+        PyErr_SetString(PyExc_ValueError ,"wrong input"); 
+        return NULL;
+    }
+	result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE);
+
+	if (result == NULL){
+	    const char * message= "Could not create result ";
+        PyErr_SetString(PyExc_RuntimeError , message);
+	    return NULL;
+	}
+	
+    for (int i = 0; i < q->dimensions[0]; i++) {
+      double q_value = *(double *)(q->data + i*q->strides[0]);
+      double phi_value = *(double *)(phi->data + i*phi->strides[0]);
+      double *result_value = (double *)(result->data + i*result->strides[0]);
+      if (q_value == 0)
+          *result_value = 0.0;
+      else
+          *result_value = model->evaluate_rphi(q_value, phi_value);
+    }
+    return PyArray_Return(result); 
+ }
+ /**
+ * Function to call to evaluate model
+ * @param args: input numpy array  [x[],y[]]
+ * @return: numpy array object 
+ */
+ static PyObject * evaluateTwoDimXY( [CMODEL]* model, 
+                              PyArrayObject *x, PyArrayObject *y)
+ {
+    PyArrayObject *result;
+    int i,j, x_len, y_len, dims[2];
+    //check validity of input vectors
+    if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE
+        || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE
+        || y->dimensions[1] != x->dimensions[0]){
+        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
+        PyErr_SetString(PyExc_ValueError , message); 
+        return NULL;
+    }
+   
+	if (PyArray_Check(x) && PyArray_Check(y)) {
+	    x_len = dims[0]= x->dimensions[0];
+        y_len = dims[1]= y->dimensions[1];
+	    
+	    // Make a new double matrix of same dims
+        result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE);
+        if (result == NULL){
+	    const char * message= "Could not create result ";
+        PyErr_SetString(PyExc_RuntimeError , message);
+	    return NULL;
+	    }
+       
+        /* Do the calculation. */
+        for ( i=0; i< x_len; i++) {
+            for ( j=0; j< y_len; j++) {
+                double x_value = *(double *)(x->data + i*x->strides[0]);
+      		    double y_value = *(double *)(y->data + j*y->strides[1]);
+      			double *result_value = (double *)(result->data +
+      			      i*result->strides[0] + j*result->strides[1]);
+      			*result_value = (*model)(x_value, y_value);
+            }           
+        }
+        return PyArray_Return(result); 
+        
+        }else{
+		    PyErr_SetString([PYTHONCLASS]Error, 
+                   "[PYTHONCLASS].evaluateTwoDimXY couldn't run.");
+	        return NULL;
+		}      	
+}
+/**
+ *  evalDistribution function evaluate a model function with input vector
+ *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
+ *
+ */ 
+static PyObject * evalDistribution([PYTHONCLASS] *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	[READDICTIONARY]
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString([PYTHONCLASS]Error, 
+	    	"[PYTHONCLASS].evalDistribution expects a q value.");
+		return NULL;
+	}
+    // Check params
+	
+    if(PyArray_Check(pars)==1) {
+		
+	    // Length of list should 1 or 2
+	    npars = pars->nd; 
+	    if(npars==1) {
+	        // input is a numpy array
+	        if (PyArray_Check(pars)) {
+		        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
+		    }
+		}else{
+		    PyErr_SetString([PYTHONCLASS]Error, 
+                   "[PYTHONCLASS].evalDistribution expect numpy array of one dimension.");
+	        return NULL;
+		}
+    }else if( PyList_Check(pars)==1) {
+    	// Length of list should be 2 for I(qx,qy)
+	    mpars = PyList_GET_SIZE(pars); 
+	    if(mpars!=2) {
+	    	PyErr_SetString([PYTHONCLASS]Error, 
+	    		"[PYTHONCLASS].evalDistribution expects a list of dimension 2.");
+	    	return NULL;
+	    }
+	     qx = PyList_GET_ITEM(pars,0);
+	     qy = PyList_GET_ITEM(pars,1);
+	     if (PyArray_Check(qx) && PyArray_Check(qy)) {
+	         return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
+		           (PyArrayObject*)qy);
+		 }else{
+		    PyErr_SetString([PYTHONCLASS]Error, 
+                   "[PYTHONCLASS].evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}else{
+	    PyErr_SetString([PYTHONCLASS]Error, 
+                   "[PYTHONCLASS].evalDistribution couln't be run.");
+	    return NULL;
+	}
+}
 
 /**
@@ -252,4 +430,7 @@
     {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
       "Evaluate the model at a given Q or Qx, Qy"},
+      
+    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy vector "},
     {"reset",    (PyCFunction)reset   , METH_VARARGS,
       "Reset pair correlation"},
@@ -302,7 +483,7 @@
 
 
-static PyMethodDef module_methods[] = {
-    {NULL} 
-};
+//static PyMethodDef module_methods[] = {
+//    {NULL} 
+//};
 
 /**
