Index: sansmodels/igor_wrapper/src/c_disperser.c
===================================================================
--- sansmodels/igor_wrapper/src/c_disperser.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/c_disperser.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,197 @@
+/**
+ * Straight C disperser
+ * 
+ * This code was written as part of the DANSE project
+ * http://danse.us/trac/sans/
+ *
+ * Copyright 2007: University of Tennessee, for the DANSE project
+ */
+#include "math.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+/**
+ * Weight distribution to give to each point in the dispersion
+ * The distribution is a Gaussian with
+ * 
+ * @param mean: mean value of the Gaussian
+ * @param sigma: sigma of the Gaussian
+ * @param x: point to evaluate at
+ * @return: weight value
+ * 
+ */
+double c_disperser_weight(double mean, double sigma, double x) {
+	double vary, expo_value;
+    vary = x-mean;
+    expo_value = -vary*vary/(2*sigma*sigma);
+    return exp(expo_value);
+}
+
+/**
+ * Function to apply dispersion to a list of parameters.
+ * 
+ * This function is re-entrant. It should be called with iPar=0.
+ * It will then call itself with increasing values for iPar until
+ * all parameters to be dispersed have been dealt with.
+ *
+ * 
+ * @param eval: pointer to the function used to evaluate the model at
+ * 				a particular point.
+ * @param dp: complete array of parameter values for the model.
+ * @param n_pars: number of parameters to apply dispersion to.
+ * @param idList: list of parameter indices for the parameters to apply
+ * 				dispersion to. For a given parameter, its index is the
+ * 				index of its position in the parameter vector of the model
+ * 				function.
+ * @param sigmaList: list of sigma values for the parameters to apply 
+ * 				dispersion to.
+ * @param centers: list of mean values for the parameters to apply 
+ * 				dispersion to.
+ * @param n_pts: number of points to use when applying dispersion.
+ * @param q: q-value to evaluate the model at.
+ * @param phi: angle of the q-vector with the q_x axis.
+ * @param iPar: index of the parameter to apply dispersion to (should
+ * 				be 0 when called by the user). 
+ * 
+ */
+double c_disperseParam( double (*eval)(double[], double, double), double dp[], int n_pars, 
+					int *idList, double *sigmaList, double *centers, 
+					int n_pts, double q, double phi, int iPar ) {
+	double min_value, max_value;
+	double step;
+	double prev_value;
+	double value_sum;
+	double gauss_sum;
+	double gauss_value;
+	double func_value;
+	double error_sys;
+	double value;
+	int n_sigma;
+	int i;
+	// Number of std variations to average over	
+	n_sigma = 2;	
+    if( iPar < n_pars ) {
+            
+		// Average over Gaussian distribution (2 sigmas)
+        value_sum = 0.0;
+        gauss_sum = 0.0;
+            
+        // Average over 4 sigmas wide
+        min_value = centers[iPar] - n_sigma*sigmaList[iPar];
+        max_value = centers[iPar] + n_sigma*sigmaList[iPar];
+            
+        // Calculate step size
+        step = (max_value - min_value)/(n_pts-1);
+            
+        // If we are not changing the parameter, just return the 
+        // value of the function
+        if (step == 0.0) {
+            return c_disperseParam(eval, dp, n_pars, idList, sigmaList, 
+            						centers, n_pts, q, phi, iPar+1);
+        }
+            
+        // Compute average
+        prev_value = 0.0;
+        error_sys  = 0.0;
+        for( i=0; i<n_pts; i++ ) {
+            // Set the parameter value           
+            value = min_value + (double)i*step;
+            dp[idList[iPar]] = value;
+                
+			gauss_value = c_disperser_weight(centers[iPar], sigmaList[iPar], value);
+            func_value = c_disperseParam(eval, dp, n_pars, idList, sigmaList, 
+            						centers, n_pts, q, phi, iPar+1);
+
+            value_sum += gauss_value * func_value;
+        	gauss_sum += gauss_value;	
+        }   
+        return value_sum/gauss_sum;
+        
+    } else {
+    	 return (*eval)(dp, q, phi);
+    }
+	
+}
+
+/**
+ * Function to add dispersion to a model.
+ * The dispersion is Gaussian around the value of given parameters.
+ * 
+ * @param eval: pointer to the function used to evaluate the model at
+ * 				a particular point.
+ * @param n_pars: number of parameters to apply dispersion to.
+ * @param idList: list of parameter indices for the parameters to apply
+ * 				dispersion to. For a given parameter, its index is the
+ * 				index of its position in the parameter vector of the model
+ * 				function.
+ * @param sigmaList: list of sigma values for the parameters to apply 
+ * 				dispersion to.
+ * @param n_pts: number of points to use when applying dispersion.
+ * @param q: q-value to evaluate the model at.
+ * @param phi: angle of the q-vector with the q_x axis.
+ * 
+ */
+double c_disperser( double (*eval)(double[], double, double), double dp[], int n_pars, 
+					int *idList, double *sigmaList, int n_pts, double q, double phi ) {
+	double *centers;
+	double value;
+	int i;
+	
+	// Allocate centers array
+	if( n_pars > 0 ) {
+	    centers = (double *)malloc(n_pars * sizeof(double));
+		if(centers==NULL) {
+		    printf("c_disperser could not allocate memory\n");
+			return 0.0;
+		}
+	}
+	
+	// Store current values in centers array
+	for(i=0; i<n_pars; i++) {
+		centers[i] = dp[idList[i]];	
+	}
+	
+	
+	if( n_pars > 0 ) {
+		value = c_disperseParam(eval, dp, n_pars, idList, sigmaList, centers, n_pts, q, phi, 0);
+    } else {
+    	value = (*eval)(dp, q, phi);
+	}
+	free(centers);
+	return value;
+}
+
+/**
+ * 
+ * Angles are in radian.
+ * 
+ * 
+ */
+double weight_dispersion( double (*eval)(double[], double, double), 
+						  double *par_values, double *weight_values, 
+						  int npts, int i_par,
+						  double dp[], double q, double phi ) {
+	int i;
+	double value;
+	double norma;
+				
+	value = 0.0;
+	norma = 0.0;	  	
+
+	// If we have an empty array of points, just 
+	// evaluate the function
+	if(npts == 0) {
+		return (*eval)(dp, q, phi);
+	} else {
+		for(i=0; i<npts; i++) {
+			dp[i_par] = par_values[i];
+			value += weight_values[i] * (*eval)(dp, q, phi);
+			//dp[i_par] = -par_values[i];
+			//value += weight_values[i] * (*eval)(dp, q, phi);
+			
+			norma += weight_values[i];
+		}
+	}
+	return value/norma/2.0;
+						  	
+}
Index: sansmodels/igor_wrapper/src/disp_core_shell_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/disp_core_shell_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/disp_core_shell_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,117 @@
+/**
+ * Scattering intensity for dispersed CCoreShellCylinderModel
+ * 
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY core_shell_cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ * This code was written as part of the DANSE project
+ * http://danse.us/trac/sans/
+ *
+ * Copyright 2007: University of Tennessee, for the DANSE project
+ */
+
+#include "core_shell_cylinder.h"
+#include <math.h>
+#include "libCylinder.h"
+#include "libSphere.h"
+#include "c_disperser.h"
+
+/**
+ * Function to evaluate 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ */
+double oriented_core_shell_cylinder_2D(double pars[], double q, double phi) {
+	CoreShellCylinderParameters danse_pars;
+	
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   thickness       = 10.0 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   core_sld        = 1e-06 A-2
+    //         pars[5]:   shell_sld       = 4e-06 A-2
+    //         pars[6]:   solvent_sld     = 1e-06 A-2
+    //         pars[7]:   background      = 0.0 cm-1
+    //         pars[8]:   axis_theta      = 1.57 rad
+    //         pars[9]:   axis_phi        = 0.0 rad
+    danse_pars.scale = pars[0];
+    danse_pars.radius = pars[1];
+    danse_pars.thickness = pars[2];
+    danse_pars.length = pars[3];
+    danse_pars.core_sld = pars[4];
+    danse_pars.shell_sld = pars[5];
+    danse_pars.solvent_sld = pars[6];
+    danse_pars.background = pars[7];
+    danse_pars.axis_theta = pars[8];
+    danse_pars.axis_phi = pars[9];
+
+	return core_shell_cylinder_analytical_2D(&danse_pars, q, phi);		
+}
+	
+/**
+ * Function to evaluate dispersed 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ * 
+     // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   thickness       = 10.0 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   core_sld        = 1e-06 A-2
+    //         pars[5]:   shell_sld       = 4e-06 A-2
+    //         pars[6]:   solvent_sld     = 1e-06 A-2
+    //         pars[7]:   background      = 0.0 cm-1
+    //         pars[8]:   axis_theta      = 1.57 rad
+    //         pars[9]:   axis_phi        = 0.0 rad
+
+    //         pars[10]:   dispersion of radius
+    //         pars[11]:   dispersion of thickness
+    //         pars[12]:   dispersion of axis_theta
+    //         pars[13]:   dispersion of axis_phi
+    //         pars[14]:   number of points in dispersion curve
+
+ */
+double disperse_core_shell_cylinder_analytical_2D(double dp[], double q, double phi) {
+	int paramList[4];
+	double sigmaList[4];
+	int npts;
+	int i;
+	double pars[15];
+	
+    // radius
+    paramList[0] = 1;
+    // thickness
+    paramList[1] = 2;
+    // axis_theta
+    paramList[2] = 8;
+    // axis_phi
+    paramList[3] = 9;
+
+    sigmaList[0] = dp[10];
+    sigmaList[1] = dp[11];
+    sigmaList[2] = dp[12];
+    sigmaList[3] = dp[13];
+
+    npts = (int)(floor(dp[14]));
+
+
+	// Internal copy of parameters
+	for(i=0; i<15; i++ ) {
+		pars[i] = dp[i];
+	}
+
+	return c_disperser( &oriented_core_shell_cylinder_2D, pars, 4, 
+					paramList, sigmaList, npts, q, phi ); 
+
+	
+}
+    
Index: sansmodels/igor_wrapper/src/disp_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/disp_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/disp_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,104 @@
+/**
+ * Scattering intensity for dispersed CCylinderModel
+ * 
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ * This code was written as part of the DANSE project
+ * http://danse.us/trac/sans/
+ *
+ * Copyright 2007: University of Tennessee, for the DANSE project
+ */
+
+#include "cylinder.h"
+#include <math.h>
+#include "libCylinder.h"
+#include "libSphere.h"
+#include "c_disperser.h"
+
+/**
+ * Function to evaluate 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ */
+double oriented_cylinder_2D(double pars[], double q, double phi) {
+	CylinderParameters danse_pars;
+	
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   length          = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   cyl_theta       = 1.0 rad
+    //         pars[6]:   cyl_phi         = 1.0 rad
+    danse_pars.scale = pars[0];
+    danse_pars.radius = pars[1];
+    danse_pars.length = pars[2];
+    danse_pars.contrast = pars[3];
+    danse_pars.background = pars[4];
+    danse_pars.cyl_theta = pars[5];
+    danse_pars.cyl_phi = pars[6];
+
+	return cylinder_analytical_2D(&danse_pars, q, phi);		
+}
+	
+/**
+ * Function to evaluate dispersed 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ * 
+     // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   length          = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   cyl_theta       = 1.0 rad
+    //         pars[6]:   cyl_phi         = 1.0 rad
+
+    //         pars[7]:   dispersion of radius
+    //         pars[8]:   dispersion of cyl_theta
+    //         pars[9]:   dispersion of cyl_phi
+    //         pars[10]:   number of points in dispersion curve
+
+ */
+double disperse_cylinder_analytical_2D(double dp[], double q, double phi) {
+	int paramList[3];
+	double sigmaList[3];
+	int npts;
+	int i;
+	double pars[11];
+	
+    // radius
+    paramList[0] = 1;
+    // cyl_theta
+    paramList[1] = 5;
+    // cyl_phi
+    paramList[2] = 6;
+
+    sigmaList[0] = dp[7];
+    sigmaList[1] = dp[8];
+    sigmaList[2] = dp[9];
+
+    npts = (int)(floor(dp[10]));
+
+
+	// Internal copy of parameters
+	for(i=0; i<11; i++ ) {
+		pars[i] = dp[i];
+	}
+
+	return c_disperser( &oriented_cylinder_2D, pars, 3, 
+					paramList, sigmaList, npts, q, phi ); 
+
+	
+}
+    
Index: sansmodels/igor_wrapper/src/disp_ellipsoid.c
===================================================================
--- sansmodels/igor_wrapper/src/disp_ellipsoid.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/disp_ellipsoid.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,108 @@
+/**
+ * Scattering intensity for dispersed CEllipsoidModel
+ * 
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY ellipsoid.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ * This code was written as part of the DANSE project
+ * http://danse.us/trac/sans/
+ *
+ * Copyright 2007: University of Tennessee, for the DANSE project
+ */
+
+#include "ellipsoid.h"
+#include <math.h>
+#include "libCylinder.h"
+#include "libSphere.h"
+#include "c_disperser.h"
+
+/**
+ * Function to evaluate 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ */
+double oriented_ellipsoid_2D(double pars[], double q, double phi) {
+	EllipsoidParameters danse_pars;
+	
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius_a        = 20.0 A
+    //         pars[2]:   radius_b        = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   axis_theta      = 1.57 rad
+    //         pars[6]:   axis_phi        = 0.0 rad
+    danse_pars.scale = pars[0];
+    danse_pars.radius_a = pars[1];
+    danse_pars.radius_b = pars[2];
+    danse_pars.contrast = pars[3];
+    danse_pars.background = pars[4];
+    danse_pars.axis_theta = pars[5];
+    danse_pars.axis_phi = pars[6];
+
+	return ellipsoid_analytical_2D(&danse_pars, q, phi);		
+}
+	
+/**
+ * Function to evaluate dispersed 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ * 
+     // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius_a        = 20.0 A
+    //         pars[2]:   radius_b        = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   axis_theta      = 1.57 rad
+    //         pars[6]:   axis_phi        = 0.0 rad
+
+    //         pars[7]:   dispersion of radius_a
+    //         pars[8]:   dispersion of radius_b
+    //         pars[9]:   dispersion of axis_theta
+    //         pars[10]:   dispersion of axis_phi
+    //         pars[11]:   number of points in dispersion curve
+
+ */
+double disperse_ellipsoid_analytical_2D(double dp[], double q, double phi) {
+	int paramList[4];
+	double sigmaList[4];
+	int npts;
+	int i;
+	double pars[12];
+	
+    // radius_a
+    paramList[0] = 1;
+    // radius_b
+    paramList[1] = 2;
+    // axis_theta
+    paramList[2] = 5;
+    // axis_phi
+    paramList[3] = 6;
+
+    sigmaList[0] = dp[7];
+    sigmaList[1] = dp[8];
+    sigmaList[2] = dp[9];
+    sigmaList[3] = dp[10];
+
+    npts = (int)(floor(dp[11]));
+
+
+	// Internal copy of parameters
+	for(i=0; i<12; i++ ) {
+		pars[i] = dp[i];
+	}
+
+	return c_disperser( &oriented_ellipsoid_2D, pars, 4, 
+					paramList, sigmaList, npts, q, phi ); 
+
+	
+}
+    
Index: sansmodels/igor_wrapper/src/disp_elliptical_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/disp_elliptical_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/disp_elliptical_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,114 @@
+/**
+ * Scattering intensity for dispersed CEllipticalCylinderModel
+ * 
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY elliptical_cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ * This code was written as part of the DANSE project
+ * http://danse.us/trac/sans/
+ *
+ * Copyright 2007: University of Tennessee, for the DANSE project
+ */
+
+#include "elliptical_cylinder.h"
+#include <math.h>
+#include "libCylinder.h"
+#include "libSphere.h"
+#include "c_disperser.h"
+
+/**
+ * Function to evaluate 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ */
+double oriented_elliptical_cylinder_2D(double pars[], double q, double phi) {
+	EllipticalCylinderParameters danse_pars;
+	
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   r_minor         = 20.0 A
+    //         pars[2]:   r_ratio         = 1.5 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   contrast        = 3e-06 A-2
+    //         pars[5]:   background      = 0.0 cm-1
+    //         pars[6]:   cyl_theta       = 1.57 rad
+    //         pars[7]:   cyl_phi         = 0.0 rad
+    //         pars[8]:   cyl_psi         = 0.0 rad
+    danse_pars.scale = pars[0];
+    danse_pars.r_minor = pars[1];
+    danse_pars.r_ratio = pars[2];
+    danse_pars.length = pars[3];
+    danse_pars.contrast = pars[4];
+    danse_pars.background = pars[5];
+    danse_pars.cyl_theta = pars[6];
+    danse_pars.cyl_phi = pars[7];
+    danse_pars.cyl_psi = pars[8];
+
+	return elliptical_cylinder_analytical_2D(&danse_pars, q, phi);		
+}
+	
+/**
+ * Function to evaluate dispersed 2D scattering function
+ * 
+ * @param dp: parameters of the function
+ * @param q: q-value
+ * @param phi: angle of the q-vector in the plane of the detector, relative to q_x
+ * @return: function value
+ * 
+     // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   r_minor         = 20.0 A
+    //         pars[2]:   r_ratio         = 1.5 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   contrast        = 3e-06 A-2
+    //         pars[5]:   background      = 0.0 cm-1
+    //         pars[6]:   cyl_theta       = 1.57 rad
+    //         pars[7]:   cyl_phi         = 0.0 rad
+    //         pars[8]:   cyl_psi         = 0.0 rad
+
+    //         pars[9]:   dispersion of r_minor
+    //         pars[10]:   dispersion of r_ratio
+    //         pars[11]:   dispersion of cyl_theta
+    //         pars[12]:   dispersion of cyl_phi
+    //         pars[13]:   number of points in dispersion curve
+
+ */
+double disperse_elliptical_cylinder_analytical_2D(double dp[], double q, double phi) {
+	int paramList[4];
+	double sigmaList[4];
+	int npts;
+	int i;
+	double pars[14];
+	
+    // r_minor
+    paramList[0] = 1;
+    // r_ratio
+    paramList[1] = 2;
+    // cyl_theta
+    paramList[2] = 6;
+    // cyl_phi
+    paramList[3] = 7;
+
+    sigmaList[0] = dp[9];
+    sigmaList[1] = dp[10];
+    sigmaList[2] = dp[11];
+    sigmaList[3] = dp[12];
+
+    npts = (int)(floor(dp[13]));
+
+
+	// Internal copy of parameters
+	for(i=0; i<14; i++ ) {
+		pars[i] = dp[i];
+	}
+
+	return c_disperser( &oriented_elliptical_cylinder_2D, pars, 4, 
+					paramList, sigmaList, npts, q, phi ); 
+
+	
+}
+    
Index: sansmodels/igor_wrapper/src/erf.c
===================================================================
--- sansmodels/igor_wrapper/src/erf.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/erf.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,96 @@
+/* erf.c
+reference - Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten
+            (New Algorithm handbook in C language) (Gijyutsu hyouron
+            sha, Tokyo, 1991) p.227 [in Japanese]                 */
+#include <stdio.h>
+#include <math.h>
+
+#ifdef _MSC_VER
+
+
+#ifdef _WIN32
+# include <float.h>
+# if !defined __MINGW32__ || defined __NO_ISOCEXT
+#  ifndef isnan
+#   define isnan(x) _isnan(x)
+#  endif
+#  ifndef isinf
+#   define isinf(x) (!_finite(x) && !_isnan(x))
+#  endif
+#  ifndef finite
+#   define finite(x) _finite(x)
+#  endif
+# endif
+#endif
+
+static double q_gamma(double, double, double);
+
+/* Incomplete gamma function
+   1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt  */
+static double p_gamma(a, x, loggamma_a)
+    double a, x, loggamma_a;
+{
+    int k;
+    double result, term, previous;
+
+    if (x >= 1 + a) return 1 - q_gamma(a, x, loggamma_a);
+    if (x == 0)     return 0;
+    result = term = exp(a * log(x) - x - loggamma_a) / a;
+    for (k = 1; k < 1000; k++) {
+        term *= x / (a + k);
+        previous = result;  result += term;
+        if (result == previous) return result;
+    }
+    fprintf(stderr, "erf.c:%d:p_gamma() could not converge.", __LINE__);
+    return result;
+}
+
+/* Incomplete gamma function
+   1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt  */
+static double q_gamma(a, x, loggamma_a)
+    double a, x, loggamma_a;
+{
+    int k;
+    double result, w, temp, previous;
+    double la = 1, lb = 1 + x - a;  /* Laguerre polynomial */
+
+    if (x < 1 + a) return 1 - p_gamma(a, x, loggamma_a);
+    w = exp(a * log(x) - x - loggamma_a);
+    result = w / lb;
+    for (k = 2; k < 1000; k++) {
+        temp = ((k - 1 - a) * (lb - la) + (k + x) * lb) / k;
+        la = lb;  lb = temp;
+        w *= (k - 1 - a) / k;
+        temp = w / (la * lb);
+        previous = result;  result += temp;
+        if (result == previous) return result;
+    }
+    fprintf(stderr, "erf.c:%d:q_gamma() could not converge.", __LINE__);
+    return result;
+}
+
+#define LOG_PI_OVER_2 0.572364942924700087071713675675 /* log_e(PI)/2 */
+
+double erf(x)
+    double x;
+{
+    if (!finite(x)) {
+        if (isnan(x)) return x;      /* erf(NaN)   = NaN   */
+        return (x>0 ? 1.0 : -1.0);   /* erf(+-inf) = +-1.0 */
+    }
+    if (x >= 0) return   p_gamma(0.5, x * x, LOG_PI_OVER_2);
+    else        return - p_gamma(0.5, x * x, LOG_PI_OVER_2);
+}
+
+double erfc(x)
+    double x;
+{
+    if (!finite(x)) {
+        if (isnan(x)) return x;      /* erfc(NaN)   = NaN      */
+        return (x>0 ? 0.0 : 2.0);    /* erfc(+-inf) = 0.0, 2.0 */
+    }
+    if (x >= 0) return  q_gamma(0.5, x * x, LOG_PI_OVER_2);
+    else        return  1 + p_gamma(0.5, x * x, LOG_PI_OVER_2);
+}
+
+#endif
Index: sansmodels/igor_wrapper/src/weighted_core_shell_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/weighted_core_shell_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/weighted_core_shell_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,104 @@
+/**
+ * Evaluate CoreShellCylinderModel with angular distribution given
+ * by user. 
+ * 
+ * This code was written as part of the DANSE project
+ *  http://danse.us/trac/sans/
+ *
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY core_shell_cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *   
+ *  @copyright 2007: University of Tennessee, for the DANSE project
+ *
+ */
+
+#include "c_disperser.h"
+#include "danse.h"
+#include <math.h>
+
+/**
+ * Evaluate model for given angular distributions in theta and phi.
+ * 
+ * Angles are in radian.
+ * 
+ * See disp_core_shell_cylinder.c for more information about the model parameters.
+ * 
+ * @param dp: model parameters
+ * @param phi_values: vector of phi_values
+ * @param phi_weights: vector of weights for each entry in phi_values
+ * @param n_phi: length of phi_values and phi_weights vectors
+ * @param theta_values: vector of theta values
+ * @param theta_weights: vector of weights for each entry in theta_values
+ * @param n_theta: length of theta_Values and theta_weights vectors
+ * @param q: q-value to evaluate the model at
+ * @param phi_q: angle between the q-vector and the q_x axis
+ * @return: scattering intensity
+ * 
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   thickness       = 10.0 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   core_sld        = 1e-06 A-2
+    //         pars[5]:   shell_sld       = 4e-06 A-2
+    //         pars[6]:   solvent_sld     = 1e-06 A-2
+    //         pars[7]:   background      = 0.0 cm-1
+    //         pars[8]:   axis_theta      = 1.57 rad
+    //         pars[9]:   axis_phi        = 0.0 rad
+
+    //         pars[10]:   dispersion of radius
+    //         pars[11]:   dispersion of thickness
+    //         pars[12]:   dispersion of axis_theta
+    //         pars[13]:   dispersion of axis_phi
+    //         pars[14]:   number of points in dispersion curve
+ * 
+ * NOTE: DO NOT USE THETA AND PHI PARAMETERS WHEN
+ *       USING THIS FUNCTION TO APPLY ANGULAR DISTRIBUTIONS.
+ * 
+ */
+double core_shell_cylinder_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi, 
+								double *theta_values, double *theta_weights, int n_theta, 
+								double q, double phi_q) {
+	// Copy of parameters
+	double pars[15];
+	// Parameter index for theta
+	int theta_index = 8;
+	// Parameter index for phi
+	int phi_index   = 9;
+	int i, i_theta;
+	double sum, norm;
+	
+	// Copy parameters because they will be modified
+	for(i=0; i<15; i++) {
+		pars[i] = dp[i];
+	}
+
+	if (n_theta == 0) {
+		return weight_dispersion( &disperse_core_shell_cylinder_analytical_2D,
+				phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+	} else {
+		sum = 0.0;
+		norm = 0.0;
+		
+		for(i_theta=0; i_theta<n_theta; i_theta++) {
+			// Assign new theta value
+			pars[theta_index] = theta_values[i_theta];
+			// Evaluate the function, weight by sin(theta) 
+			sum += sin(theta_values[i_theta]) * theta_weights[i_theta] * 
+					weight_dispersion( &disperse_core_shell_cylinder_analytical_2D,
+					phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+			// Keep track of normalization
+			norm += theta_weights[i_theta];
+		}
+		
+		// Protect against null weight vector
+		if(norm > 0) {
+			return sum/norm;
+		}
+	}
+	return 0.0;
+}
+
+
+
Index: sansmodels/igor_wrapper/src/weighted_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/weighted_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/weighted_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,100 @@
+/**
+ * Evaluate CylinderModel with angular distribution given
+ * by user. 
+ * 
+ * This code was written as part of the DANSE project
+ *  http://danse.us/trac/sans/
+ *
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *   
+ *  @copyright 2007: University of Tennessee, for the DANSE project
+ *
+ */
+
+#include "c_disperser.h"
+#include "danse.h"
+#include <math.h>
+
+/**
+ * Evaluate model for given angular distributions in theta and phi.
+ * 
+ * Angles are in radian.
+ * 
+ * See disp_cylinder.c for more information about the model parameters.
+ * 
+ * @param dp: model parameters
+ * @param phi_values: vector of phi_values
+ * @param phi_weights: vector of weights for each entry in phi_values
+ * @param n_phi: length of phi_values and phi_weights vectors
+ * @param theta_values: vector of theta values
+ * @param theta_weights: vector of weights for each entry in theta_values
+ * @param n_theta: length of theta_Values and theta_weights vectors
+ * @param q: q-value to evaluate the model at
+ * @param phi_q: angle between the q-vector and the q_x axis
+ * @return: scattering intensity
+ * 
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius          = 20.0 A
+    //         pars[2]:   length          = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   cyl_theta       = 1.0 rad
+    //         pars[6]:   cyl_phi         = 1.0 rad
+
+    //         pars[7]:   dispersion of radius
+    //         pars[8]:   dispersion of cyl_theta
+    //         pars[9]:   dispersion of cyl_phi
+    //         pars[10]:   number of points in dispersion curve
+ * 
+ * NOTE: DO NOT USE THETA AND PHI PARAMETERS WHEN
+ *       USING THIS FUNCTION TO APPLY ANGULAR DISTRIBUTIONS.
+ * 
+ */
+double cylinder_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi, 
+								double *theta_values, double *theta_weights, int n_theta, 
+								double q, double phi_q) {
+	// Copy of parameters
+	double pars[11];
+	// Parameter index for theta
+	int theta_index = 5;
+	// Parameter index for phi
+	int phi_index   = 6;
+	int i, i_theta;
+	double sum, norm;
+	
+	// Copy parameters because they will be modified
+	for(i=0; i<11; i++) {
+		pars[i] = dp[i];
+	}
+
+	if (n_theta == 0) {
+		return weight_dispersion( &disperse_cylinder_analytical_2D,
+				phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+	} else {
+		sum = 0.0;
+		norm = 0.0;
+		
+		for(i_theta=0; i_theta<n_theta; i_theta++) {
+			// Assign new theta value
+			pars[theta_index] = theta_values[i_theta];
+			// Evaluate the function, weight by sin(theta) 
+			sum += sin(theta_values[i_theta]) * theta_weights[i_theta] * 
+					weight_dispersion( &disperse_cylinder_analytical_2D,
+					phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+			// Keep track of normalization
+			norm += theta_weights[i_theta];
+		}
+		
+		// Protect against null weight vector
+		if(norm > 0) {
+			return sum/norm;
+		}
+	}
+	return 0.0;
+}
+
+
+
Index: sansmodels/igor_wrapper/src/weighted_ellipsoid.c
===================================================================
--- sansmodels/igor_wrapper/src/weighted_ellipsoid.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/weighted_ellipsoid.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,101 @@
+/**
+ * Evaluate EllipsoidModel with angular distribution given
+ * by user. 
+ * 
+ * This code was written as part of the DANSE project
+ *  http://danse.us/trac/sans/
+ *
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY ellipsoid.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *   
+ *  @copyright 2007: University of Tennessee, for the DANSE project
+ *
+ */
+
+#include "c_disperser.h"
+#include "danse.h"
+#include <math.h>
+
+/**
+ * Evaluate model for given angular distributions in theta and phi.
+ * 
+ * Angles are in radian.
+ * 
+ * See disp_ellipsoid.c for more information about the model parameters.
+ * 
+ * @param dp: model parameters
+ * @param phi_values: vector of phi_values
+ * @param phi_weights: vector of weights for each entry in phi_values
+ * @param n_phi: length of phi_values and phi_weights vectors
+ * @param theta_values: vector of theta values
+ * @param theta_weights: vector of weights for each entry in theta_values
+ * @param n_theta: length of theta_Values and theta_weights vectors
+ * @param q: q-value to evaluate the model at
+ * @param phi_q: angle between the q-vector and the q_x axis
+ * @return: scattering intensity
+ * 
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   radius_a        = 20.0 A
+    //         pars[2]:   radius_b        = 400.0 A
+    //         pars[3]:   contrast        = 3e-06 A-2
+    //         pars[4]:   background      = 0.0 cm-1
+    //         pars[5]:   axis_theta      = 1.57 rad
+    //         pars[6]:   axis_phi        = 0.0 rad
+
+    //         pars[7]:   dispersion of radius_a
+    //         pars[8]:   dispersion of radius_b
+    //         pars[9]:   dispersion of axis_theta
+    //         pars[10]:   dispersion of axis_phi
+    //         pars[11]:   number of points in dispersion curve
+ * 
+ * NOTE: DO NOT USE THETA AND PHI PARAMETERS WHEN
+ *       USING THIS FUNCTION TO APPLY ANGULAR DISTRIBUTIONS.
+ * 
+ */
+double ellipsoid_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi, 
+								double *theta_values, double *theta_weights, int n_theta, 
+								double q, double phi_q) {
+	// Copy of parameters
+	double pars[12];
+	// Parameter index for theta
+	int theta_index = 5;
+	// Parameter index for phi
+	int phi_index   = 6;
+	int i, i_theta;
+	double sum, norm;
+	
+	// Copy parameters because they will be modified
+	for(i=0; i<12; i++) {
+		pars[i] = dp[i];
+	}
+
+	if (n_theta == 0) {
+		return weight_dispersion( &disperse_ellipsoid_analytical_2D,
+				phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+	} else {
+		sum = 0.0;
+		norm = 0.0;
+		
+		for(i_theta=0; i_theta<n_theta; i_theta++) {
+			// Assign new theta value
+			pars[theta_index] = theta_values[i_theta];
+			// Evaluate the function, weight by sin(theta) 
+			sum += sin(theta_values[i_theta]) * theta_weights[i_theta] * 
+					weight_dispersion( &disperse_ellipsoid_analytical_2D,
+					phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+			// Keep track of normalization
+			norm += theta_weights[i_theta];
+		}
+		
+		// Protect against null weight vector
+		if(norm > 0) {
+			return sum/norm;
+		}
+	}
+	return 0.0;
+}
+
+
+
Index: sansmodels/igor_wrapper/src/weighted_elliptical_cylinder.c
===================================================================
--- sansmodels/igor_wrapper/src/weighted_elliptical_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
+++ sansmodels/igor_wrapper/src/weighted_elliptical_cylinder.c	(revision 25a60dc18cfd6e9a29a6a6c01bf49e2862c62e61)
@@ -0,0 +1,103 @@
+/**
+ * Evaluate EllipticalCylinderModel with angular distribution given
+ * by user. 
+ * 
+ * This code was written as part of the DANSE project
+ *  http://danse.us/trac/sans/
+ *
+ * WARNING: THIS FILE WAS GENERATED BY IGORGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY elliptical_cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *   
+ *  @copyright 2007: University of Tennessee, for the DANSE project
+ *
+ */
+
+#include "c_disperser.h"
+#include "danse.h"
+#include <math.h>
+
+/**
+ * Evaluate model for given angular distributions in theta and phi.
+ * 
+ * Angles are in radian.
+ * 
+ * See disp_elliptical_cylinder.c for more information about the model parameters.
+ * 
+ * @param dp: model parameters
+ * @param phi_values: vector of phi_values
+ * @param phi_weights: vector of weights for each entry in phi_values
+ * @param n_phi: length of phi_values and phi_weights vectors
+ * @param theta_values: vector of theta values
+ * @param theta_weights: vector of weights for each entry in theta_values
+ * @param n_theta: length of theta_Values and theta_weights vectors
+ * @param q: q-value to evaluate the model at
+ * @param phi_q: angle between the q-vector and the q_x axis
+ * @return: scattering intensity
+ * 
+    // List of default parameters:
+    //         pars[0]:   scale           = 1.0 
+    //         pars[1]:   r_minor         = 20.0 A
+    //         pars[2]:   r_ratio         = 1.5 A
+    //         pars[3]:   length          = 400.0 A
+    //         pars[4]:   contrast        = 3e-06 A-2
+    //         pars[5]:   background      = 0.0 cm-1
+    //         pars[6]:   cyl_theta       = 1.57 rad
+    //         pars[7]:   cyl_phi         = 0.0 rad
+    //         pars[8]:   cyl_psi         = 0.0 rad
+
+    //         pars[9]:   dispersion of r_minor
+    //         pars[10]:   dispersion of r_ratio
+    //         pars[11]:   dispersion of cyl_theta
+    //         pars[12]:   dispersion of cyl_phi
+    //         pars[13]:   number of points in dispersion curve
+ * 
+ * NOTE: DO NOT USE THETA AND PHI PARAMETERS WHEN
+ *       USING THIS FUNCTION TO APPLY ANGULAR DISTRIBUTIONS.
+ * 
+ */
+double elliptical_cylinder_Weights(double dp[], double *phi_values, double *phi_weights, int n_phi, 
+								double *theta_values, double *theta_weights, int n_theta, 
+								double q, double phi_q) {
+	// Copy of parameters
+	double pars[14];
+	// Parameter index for theta
+	int theta_index = 6;
+	// Parameter index for phi
+	int phi_index   = 7;
+	int i, i_theta;
+	double sum, norm;
+	
+	// Copy parameters because they will be modified
+	for(i=0; i<14; i++) {
+		pars[i] = dp[i];
+	}
+
+	if (n_theta == 0) {
+		return weight_dispersion( &disperse_elliptical_cylinder_analytical_2D,
+				phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+	} else {
+		sum = 0.0;
+		norm = 0.0;
+		
+		for(i_theta=0; i_theta<n_theta; i_theta++) {
+			// Assign new theta value
+			pars[theta_index] = theta_values[i_theta];
+			// Evaluate the function, weight by sin(theta) 
+			sum += sin(theta_values[i_theta]) * theta_weights[i_theta] * 
+					weight_dispersion( &disperse_elliptical_cylinder_analytical_2D,
+					phi_values, phi_weights, n_phi, phi_index, pars, q, phi_q );
+			// Keep track of normalization
+			norm += theta_weights[i_theta];
+		}
+		
+		// Protect against null weight vector
+		if(norm > 0) {
+			return sum/norm;
+		}
+	}
+	return 0.0;
+}
+
+
+
