Index: src/sas/models/c_extension/libigor/2Y_OneYukawa.c
===================================================================
--- src/sas/models/c_extension/libigor/2Y_OneYukawa.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,370 +1,0 @@
-/*
- *  Yukawa.c
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/12/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "2Y_OneYukawa.h"
-#include "2Y_cpoly.h"
-#include "2Y_utility.h"
-#include "2Y_PairCorrelation.h"
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-
-/*
-================================================================================================== 
- 
- Structure factor for the potential 
- 
- V(r) = -kB * T * K * exp[ -Z * (r - 1)] / r for r > 1
- V(r) = inf for r <= 1
- 
- The structure factor is parametrized by (a, b, c, d) 
- which depend on (Z, K, phi).  
- 
-================================================================================================== 
-*/
-
-double Y_sigma( double s, double Z, double a, double b, double c, double d )
-{
-	return -(a / 2. + b + c * exp( -Z )) / s + a * pow( s, -3 ) + b * pow( s, -2 ) + ( c + d ) * pow( s + Z, -1 );
-}
-
-double Y_tau( double s, double Z, double a, double b, double c )
-{
-	return b * pow( s, -2 ) + a * ( pow( s, -3 ) + pow( s, -2 ) ) - pow( s, -1 ) * c * Z * exp( -Z ) * pow( s + Z, -1 );
-} 
-
-double Y_q( double s, double Z, double a, double b, double c, double d )
-{
-	return Y_sigma(s, Z, a, b, c, d ) - exp( -s ) * Y_tau( s, Z, a, b, c );
-}
-
-double Y_g( double s, double phi, double Z, double a, double b, double c, double d )
-{
-	return s * Y_tau( s, Z, a, b, c ) * exp( -s ) / ( 1 - 12 * phi * Y_q( s, Z, a, b, c, d ) );
-}
-
-double Y_hq( double q, double Z, double K, double v )
-{
-	double t1, t2, t3, t4;
-
-	if ( q == 0) 
-	{
-		return (exp(-2*Z)*(v + (v*(-1 + Z) - 2*K*Z)*exp(Z))*(-(v*(1 + Z)) + (v + 2*K*Z*(1 + Z))*exp(Z))*pow(K,-1)*pow(Z,-4))/4.;
-	}
-	else 
-	{
-		
-		t1 = ( 1 - v / ( 2 * K * Z * exp( Z ) ) ) * ( ( 1 - cos( q ) ) / ( q*q ) - 1 / ( Z*Z + q*q ) );
-		t2 = ( v*v * ( q * cos( q ) - Z * sin( q ) ) ) / ( 4 * K * Z*Z * q * ( Z*Z + q*q ) );
-		t3 = ( q * cos( q ) + Z * sin( q ) ) / ( q * ( Z*Z + q*q ) );
-		t4 = v / ( Z * exp( Z ) ) - v*v / ( 4 * K * Z*Z * exp( 2 * Z ) ) - K;
-		
-		return v / Z * t1 - t2 + t3 * t4;
-	}
-}
-
-double Y_pc( double q, 
-			double Z, double K, double phi,
-			double a, double b, double c, double d )
-{	
-	double v = 24 * phi * K * exp( Z ) * Y_g( Z, phi, Z, a, b, c, d );
-	
-	double a0 = a * a;
-	double b0 = -12 * phi *( pow( a + b,2 ) / 2 + a * c * exp( -Z ) );
-	
-	double t1, t2, t3, t4;
-	
-	if ( q == 0 ) 
-	{
-		t1 = a0 / 3;
-		t2 = b0 / 4;
-		t3 = a0 * phi / 12;
-	}
-	else 
-	{
-		t1 = a0 * ( sin( q ) - q * cos( q ) ) / pow( q, 3 );
-		t2 = b0 * ( 2 * q * sin( q ) - ( q * q - 2 ) * cos( q ) - 2 ) / pow( q, 4 );
-		t3 = a0 * phi * ( ( q*q - 6 ) * 4 * q * sin( q ) - ( pow( q, 4 ) - 12 * q*q + 24) * cos( q ) + 24 ) / ( 2 * pow( q, 6 ) );
-	}
-	t4 = Y_hq( q, Z, K, v );
-	return -24 * phi * ( t1 + t2 + t3 + t4 );
-}
-
-double SqOneYukawa( double q, 
-				 double Z, double K, double phi,
-				 double a, double b, double c, double d )
-{
-	//structure factor one-yukawa potential
-	return 1. / ( 1. - Y_pc( q, Z, K, phi, a, b, c, d ) );
-}
-
-
-/*
-================================================================================================== 
-
- The structure factor S(q) for the one-Yukawa potential is parameterized by a,b,c,d which are
- the solution of a system of non-linear equations given Z,K, phi. There are at most 4 solutions 
- from which the physical one is chosen
- 
-================================================================================================== 
- */
-
-double Y_LinearEquation_1( double Z, double K, double phi, double a, double b, double c, double d )
-{
-	return b - 12*phi*(-a/8. - b/6. + d*pow(Z,-2) + c*(pow(Z,-2) - exp(-Z)*(0.5 + (1 + Z)*pow(Z,-2))));
-}
-
-double Y_LinearEquation_2( double Z, double K, double phi, double a, double b, double c, double d )
-{
-	return 1 - a - 12*phi*(-a/3. - b/2. + d*pow(Z,-1) + c*(pow(Z,-1) - (1 + Z)*exp(-Z)*pow(Z,-1)));
-}
-
-double Y_LinearEquation_3( double Z, double K, double phi, double a, double b, double c, double d )
-{
-	return K*exp(Z) - Z*d*(1-12*phi*Y_q(Z, Z, a, b, c, d));
-}
-
-double Y_NonlinearEquation( double Z, double K, double phi, double a, double b, double c, double d )
-{
-	return c + d - 12*phi*((c + d)*Y_sigma(Z, Z, a, b, c, d) - c*exp(-Z)*Y_tau(Z, Z, a, b, c));
-}
-
-// Check the computed solutions satisfy the system of equations 
-int Y_CheckSolution( double Z, double K, double phi, 
-					 double a, double b, double c, double d )
-{
-	double eq_1 = chop( Y_LinearEquation_1 ( Z, K, phi, a, b, c, d ) );
-	double eq_2 = chop( Y_LinearEquation_2 ( Z, K, phi, a, b, c, d ) );
-	double eq_3 = chop( Y_LinearEquation_3 ( Z, K, phi, a, b, c, d ) );
-	double eq_4 = chop( Y_NonlinearEquation( Z, K,  phi, a, b, c, d ) );
-	
-	// check if all equation are zero
-	return eq_1 == 0 && eq_2 == 0 && eq_3 == 0 && eq_4 == 0;
-}
-
-int Y_SolveEquations( double Z, double K, double phi, double* a, double* b, double* c, double* d, int debug )
-{
-	char buf[256];
-
-	// at most there are 4 solutions for a,b,c,d
-	double sol_a[4], sol_b[4], sol_c[4], sol_d[4];
-	
-	double m11 = (3*phi)/2.;
-	double m13 = 6*phi*exp(-Z)*(2 + Z*(2 + Z) - 2*exp(Z))*pow(Z,-2);
-	double m23 = -12*phi*exp(-Z)*(-1 - Z + exp(Z))*pow(Z,-1);
-	double m31 = -6*phi*exp(-Z)*pow(Z,-2)*(2*(1 + Z) + exp(Z)*(-2 + pow(Z,2)));
-	double m32 = -12*phi*(-1 + Z + exp(-Z))*pow(Z,-1);
-	double m33 = 6*phi*exp(-2*Z)*pow(-1 + exp(Z),2);
-	
-	double delta = m23*m31 - m13*m32 + m11*(-4*m13*m31 + (4*m23*m31)/3. + (8*m13*m32)/3. - m23*m32) + m33 + (4*(-3 + m11)*m11*m33)/9.;
-	double a1 = -(K*(m23 + (4*m11*(-3*m13 + m23))/3.)*exp(Z));
-	double a2 = -(m13*(m32 + 4*m11*Z)) + ((3 + 4*m11)*(m33 + m23*Z))/3.;
-	double a3 = -2*phi*pow(Z,-2)*(6*m23*m32 - 24*m11*m33 + 2*Z*((3 + 4*m11)*m33 - 3*m13*(m32 + 2*m11*Z)) + (3 + 4*m11)*m23*pow(Z,2));
-	
-	double b1 = -(K*((-3 + 8*m11)*m13 - 3*m11*m23)*exp(Z))/3.;
-	double b2 = m13*(m31 - Z + (8*m11*Z)/3.) - m11*(m33 + m23*Z);
-	double b3 = 2*phi*pow(Z,-2)*(m13*Z*(-6*m31 + 3*Z - 8*m11*Z) + 2*m33*(3 - 8*m11 + 3*m11*Z) + 3*m23*(2*m31 + m11*pow(Z,2)));
-	
-	double c1 = -(K*exp(Z)*pow(3 - 2*m11,2))/9.;
-	double c2 = -((3 + 4*m11)*m31)/3. + m11*m32 + Z + (4*(-3 + m11)*m11*Z)/9.;
-	double c3 = (-2*phi*pow(Z,-2)*(6*(12*m11*m31 + 3*m32 - 8*m11*m32) - 6*((3 + 4*m11)*m31 - 3*m11*m32)*Z + pow(3 - 2*m11,2)*pow(Z,2)))/3.;
-	
-	// determine d, as roots of the polynomial, from that build a,b,c
-	
-	double real_coefficient[5];
-	double imag_coefficient[5];
-	
-	double real_root[4];
-	double imag_root[4];
-	
-	double zeta = 24*phi*pow(-6*phi*Z*cosh(Z/2.) + (12*phi + (-1 + phi)*pow(Z,2))*sinh(Z/2.),2);	
-	double A[5];
-	int degree,i,j,n_roots;
-	double x,y;
-	int n,selected_root;
-	double qmax,q,dq,min,sum,dr;
-	double *sq,*gr;
-	
-	
-	A[0] = -(exp(3*Z)*pow(K,2)*pow(-1 + phi,2)*pow(Z,3) / zeta );
-	A[1] = K*Z*exp(Z)*(6*phi*(2 + 4*phi + (2 + phi)*Z) + exp(Z)*
-					   ((-24 + Z*(18 + (-6 + Z)*Z))*pow(phi,2) - 2*phi*(6 + (-3 + Z)*pow(Z,2)) + pow(Z,3))) / zeta;
-	A[2] = -12*K*phi*exp(Z)*pow(-1 + phi,2)*pow(Z,3)/zeta;
-	A[3] = 6*phi*Z*exp(-Z)*(-12*phi*(1 + 2*phi)*(-1 + exp(Z)) + 6*phi*Z*(3*phi + (2 + phi)*exp(Z)) + 
-							6*(-1 + phi)*phi*pow(Z,2) + pow(-1 + phi,2)*pow(Z,3))/zeta;
-	A[4] = -36*exp(-Z)*pow(-1 + phi,2)*pow(phi,2)*pow(Z,3)/zeta;
-/*	
-	if ( debug )
-	{
-		sprintf (buf, "(Z,K,phi) = (%g, %g, %g)\r", K, Z, phi );
-		XOPNotice(buf);
-		sprintf (buf, "A = (%g, %g, %g, %g, %g)\r", A[0], A[1], A[2], A[3], A[4] );
-		XOPNotice(buf);
-	}
-*/	
-	//integer degree of polynomial
-	degree = 4;
-	
-	// vector of real and imaginary coefficients in order of decreasing powers
-	for ( i = 0; i <= degree; i++ )
-	{
-		real_coefficient[i] = A[4-i];
-		imag_coefficient[i] = 0.;
-	}
-	
-	// Jenkins-Traub method to approximate the roots of the polynomial
-	cpoly( real_coefficient, imag_coefficient, degree, real_root, imag_root );
-	
-	// show the result if in debug mode
-/*
-	if ( debug )
-	{
-		for ( i = 0; i < degree; i++ )
-		{
-			x = real_root[i];
-			y = imag_root[i];
-			sprintf(buf, "root(%d) = %g + %g i\r", i+1, x, y );
-			XOPNotice(buf);
-		}
-		sprintf(buf, "\r" );
-		XOPNotice(buf);
-	}
- */
-	// determine the set of solutions for a,b,c,d,
-	j = 0;
-	for ( i = 0; i < degree; i++ ) 
-	{
-		x = real_root[i];
-		y = imag_root[i];
-		
-		if ( chop( y ) == 0 ) 
-		{
-			sol_a[j] = ( a1 + a2 * x + a3 * x * x ) / ( delta * x );
-			sol_b[j] = ( b1 + b2 * x + b3 * x * x ) / ( delta * x );
-			sol_c[j] = ( c1 + c2 * x + c3 * x * x ) / ( delta * x );
-			sol_d[j] = x;
-	
-			j++;
-		}
-	}
-
-	// number  remaining roots 
-	n_roots = j;
-	
-//	sprintf(buf, "inside Y_solveEquations OK, before malloc: n_roots = %d\r",n_roots);
-//	XOPNotice(buf);	
-	
-	// if there is still more than one root left, than choose the one with the minimum
-	// average value inside the hardcore
-	
-	
-	
-	if ( n_roots > 1 )
-	{
-		// the number of q values should be a power of 2
-		// in order to speed up the FFT
-		n = 1 << 14;		//= 16384
-		
-		// the maximum q value should be large enough 
-		// to enable a reasoble approximation of g(r)
-		qmax = 1000.;
-		dq = qmax / ( n - 1 );
-		
-		// step size for g(r) = dr
-		
-		// allocate memory for pair correlation function g(r)
-		// and structure factor S(q)
-		// (note that sq and gr are pointers)
-		sq = malloc( sizeof( double ) * n );
-		gr = malloc( sizeof( double ) * n );
-		
-		// loop over all remaining roots
-		min = 1e99;
-		selected_root=0;	
-		
-//		sprintf(buf, "after malloc: n,dq = %d  %g\r",n,dq);
-//		XOPNotice(buf);
-				
-		for ( j = 0; j < n_roots; j++) 
-		{
-			// calculate structure factor at different q values
-			for ( i = 0; i < n ; i++) 
-			{
-				q = dq * i;
-				sq[i] = SqOneYukawa( q, Z, K, phi, sol_a[j], sol_b[j], sol_c[j], sol_d[j] );
-/*				
-				if(i<20 && debug) {
-					sprintf(buf, "after SqOneYukawa: s(q) = %g\r",sq[i] );
-					XOPNotice(buf);	
-				}
- */
-			}
-						
-			// calculate pair correlation function for given
-			// structure factor, g(r) is computed at values
-			// r(i) = i * dr
-			PairCorrelation( phi, dq, sq, &dr, gr, n );
-			
-//			sprintf(buf, "after PairCorrelation: \r");
-//			XOPNotice(buf);
-			
-			// determine sum inside the hardcore 
-			// 0 =< r < 1 of the pair-correlation function
-			sum = 0;
-			for (i = 0; i < floor( 1. / dr ); i++ ) 
-			{
-				sum += fabs( gr[i] );
-/*				
-				if(i<20 && debug) {
-					sprintf(buf, "g(r) in core = %g\r",fabs(gr[i]));
-					XOPNotice(buf);
-				}
- */
-			}
-			
-//			sprintf(buf, "after hard core: sum, min = %g %g\r",sum,min);
-//			XOPNotice(buf);
-			
-			if ( sum < min )
-			{
-				min = sum;
-				selected_root = j;
-			}
-			
-			
-		}	
-		free( gr );
-		free( sq );
-		
-//		sprintf(buf, "after free: selected root = %d\r",selected_root);
-//		XOPNotice(buf);
-		
-		// physical solution was found
-		*a = sol_a[ selected_root ];
-		*b = sol_b[ selected_root ];
-		*c = sol_c[ selected_root ];
-		*d = sol_d[ selected_root ];
-		
-//		sprintf(buf, "after solution found (ret 1): \r");
-//		XOPNotice(buf);
-		
-		return 1;
-	}
-	else if ( n_roots == 1 ) 
-	{
-		*a = sol_a[0];
-		*b = sol_b[0];
-		*c = sol_c[0];
-		*d = sol_d[0];
-		
-		return 1;
-	}
-	// no solution was found
-	return 0;
-}
Index: src/sas/models/c_extension/libigor/2Y_OneYukawa.h
===================================================================
--- src/sas/models/c_extension/libigor/2Y_OneYukawa.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/*
- *  Yukawa.h
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/12/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-int Y_CheckSolution( double Z, double K, double phi, double a, double b, double c, double d );
-int Y_SolveEquations( double Z, double K, double phi, 
-					  double* a, double* b, double* c, double* d, int debug );
-double SqOneYukawa( double q, 
-				double Z, double K, double phi,
-				double a, double b, double c, double d );
Index: src/sas/models/c_extension/libigor/2Y_PairCorrelation.c
===================================================================
--- src/sas/models/c_extension/libigor/2Y_PairCorrelation.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/*
- *  PairCorrelation.c
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/9/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "2Y_PairCorrelation.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-//#include <gsl/gsl_errno.h> 
-//#include <gsl/gsl_fft_real.h>
-
-/*
-=================================================================================================== 
-
- Source: J.B.Hayter: A Program for the fast bi-directional transforms
- between g(r) and S(Q), ILL internal scientific report, October 1979
- 
- The transformation between structure factor and pair correlation 
- function is given by 
- 
- g(x) = 1 + 1 / (12*pi*phi*x) * int( [S(q)-q]*q*sin(q*x), { 0, inf } )
- 
- where phi is the volume frcation, x and q are dimensionless variables, 
- scaled by the radius a of the particles:
- 
- r = x * a;
- Q = q / a
- 
- Discretizing the integral leads to
- 
- x[k] = 2*pi*k / (N * dq)
- g(x[k]) = 1 + N*dq^3 / (24*pi^2*phi*k) * Im{ sum(S[n]*exp(2*pi*i*n*k/N),{n,0,N-1}) }
- 
- where S[n] = n*(S(q[n])-1) with q[n]=n * dq
-
-=================================================================================================== 
-*/
-
-/*
-int PairCorrelation_GSL( double phi, double dq, double* Sq, double* dr, double* gr, int N )
-{
-	double* data = malloc( sizeof(double) * N );
-	int n;
-	for ( n = 0; n < N; n++ )
-		data[n] = n * ( Sq[n] - 1 );
-	
-	// data[k] -> sum( data[n] * exp(-2*pi*i*n*k/N), {n, 0, N-1 })
-	int stride = 1;
-	int error  = gsl_fft_real_radix2_transform( data, stride, N );
-	
-	// if no errors detected 
-	if ( error == GSL_SUCCESS ) 
-	{
-		double alpha = N * pow( dq, 3 ) / ( 24 * M_PI * M_PI * phi );
-	
-	
-		*dr = 2 * M_PI / ( N * dq );  
-		int k;
-		double real, imag;
-		for ( k = 0; k < N; k++ )
-		{
-			// the solutions of the transform is stored in data, 
-			// consult GSL manual for more details
-			if ( k == 0 || k == N / 2)
-			{ 
-				real = data[k];
-				imag = 0;
-			}
-			else if ( k < N / 2 ) 
-			{
-				real = data[k];
-				imag = data[N-k];
-			}
-			else if ( k > N / 2 )
-			{
-				real =  data[N-k];
-				imag = -data[k];	
-			}
-			
-			if ( k == 0 ) 
-				gr[k] = 0;
-			else
-				gr[k] = 1. + alpha / k * (-imag);
-		} 
-	} 
-	// if N is not a power of two
-	else if ( error == GSL_EDOM )
-	{
-		printf( "N is not a power of 2\n" );
-	}
-	else
-	{
-		printf( "Could not perform DFT (discrete fourier transform)\n" );
-	}
-	// release allocated memory
-	free( data );
-	
-	// return error value
-	return error;
-}
- */
-
-
-// this uses numerical recipes for the FFT
-//
-int PairCorrelation( double phi, double dq, double* Sq, double* dr, double* gr, int N )
-{
-	double* data = malloc( sizeof(double) * N * 2);
-	int n,error,k;
-	double alpha,real,imag;
-	double Pi = 3.14159265358979323846264338327950288;   /* pi */
-
-	
-	for ( n = 0; n < N; n++ ) {
-		data[2*n] = n * ( Sq[n] - 1 );
-		data[2*n+1] = 0;
-	}
-	//	printf("start of new fft\n");
-	
-	// data[k] -> sum( data[n] * exp(-2*pi*i*n*k/N), {n, 0, N-1 })
-	//	int error  = gsl_fft_real_radix2_transform( data, stride, N );
-	error  = 1;
-	dfour1( data-1, N, 1 );		//N is the number of complex points
-	
-	//	printf("dfour1 is done\n");
-	
-	// if no errors detected 
-	if ( error == 1 ) 
-	{
-		alpha = N * pow( dq, 3 ) / ( 24 * Pi * Pi * phi );
-		
-		*dr = 2 * Pi / ( N * dq );  
-		for ( k = 0; k < N; k++ )
-		{
-			// the solutions of the transform is stored in data, 
-			// consult GSL manual for more details
-			if ( 2*k == 0 || 2*k == 2*N / 2)
-			{ 
-				real = data[2*k];
-				imag = 0;
-			}
-			else if ( 2*k < 2*N / 2 ) 
-			{
-				real = data[2*k];
-				imag = data[2*k+1];
-			}
-			else if ( 2*k > 2*N / 2 )
-			{
-				real =  data[2*k];
-				imag = -data[2*k+1];	
-			}
-			
-			if ( k == 0 ) 
-				gr[k] = 0;
-			else
-//				gr[k] = 1. + alpha / k * (-imag);		//if using GSL
-				gr[k] = 1. + alpha / k * (imag);		//if using NR
-		} 
-	} 
-	
-	// release allocated memory
-	free( data );
-	
-//	printf(" done with FFT assignment -- Using Numerical Recipes, not GSL\n");
-	
-	// return error value
-	return error;
-}
-
-
-// isign == 1 means no scaling of output. isign == -1 multiplies output by nn
-//
-//
-#define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr
-
-void dfour1(double data[], unsigned long nn, int isign)
-{
-	unsigned long n,mmax,m,j,istep,i;
-	double wtemp,wr,wpr,wpi,wi,theta;
-	double tempr,tempi;
-	
-	n=nn << 1;
-	j=1;
-	for (i=1;i<n;i+=2) {
-		if (j > i) {
-			SWAP(data[j],data[i]);
-			SWAP(data[j+1],data[i+1]);
-		}
-		m=n >> 1;
-		while (m >= 2 && j > m) {
-			j -= m;
-			m >>= 1;
-		}
-		j += m;
-	}
-	mmax=2;
-	while (n > mmax) {
-		istep=mmax << 1;
-		theta=isign*(6.28318530717959/mmax);
-		wtemp=sin(0.5*theta);
-		wpr = -2.0*wtemp*wtemp;
-		wpi=sin(theta);
-		wr=1.0;
-		wi=0.0;
-		for (m=1;m<mmax;m+=2) {
-			for (i=m;i<=n;i+=istep) {
-				j=i+mmax;
-				tempr=wr*data[j]-wi*data[j+1];
-				tempi=wr*data[j+1]+wi*data[j];
-				data[j]=data[i]-tempr;
-				data[j+1]=data[i+1]-tempi;
-				data[i] += tempr;
-				data[i+1] += tempi;
-			}
-			wr=(wtemp=wr)*wpr-wi*wpi+wr;
-			wi=wi*wpr+wtemp*wpi+wi;
-		}
-		mmax=istep;
-	}
-}
-#undef SWAP
Index: src/sas/models/c_extension/libigor/2Y_PairCorrelation.h
===================================================================
--- src/sas/models/c_extension/libigor/2Y_PairCorrelation.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,13 +1,0 @@
-/*
- *  PairCorrelation.h
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/9/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-
-//int PairCorrelation_GSL( double phi, double dq, double* Sq, double* dr, double* gr, int N );
-int PairCorrelation( double phi, double dq, double* Sq, double* dr, double* gr, int N );
-
-void dfour1(double data[], unsigned long nn, int isign);
Index: src/sas/models/c_extension/libigor/2Y_TwoYukawa.c
===================================================================
--- src/sas/models/c_extension/libigor/2Y_TwoYukawa.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,1113 +1,0 @@
-/*
- *  twoyukawa.c
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/7/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "2Y_TwoYukawa.h"
-#include "2Y_cpoly.h"
-#include "2Y_utility.h"
-#include "2Y_PairCorrelation.h"
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-
-/*
- ================================================================================================== 
- 
- The two-yukawa structure factor is uniquley determined by 6 parameters a, b, c1, c2, d1, d2,
- which are the solution of a system of 6 equations ( 4 linear, 2 nonlinear ). The solution can 
- constructed by the roots of a polynomial of 22nd degree. For more details see attached 
- Mathematica snotebook, where a derivation is given
- 
- ================================================================================================== 
- */
-
-double TY_q22;
-double TY_qa12, TY_qa21, TY_qa22, TY_qa23, TY_qa32;
-double TY_qb12, TY_qb21, TY_qb22, TY_qb23, TY_qb32;
-double TY_qc112, TY_qc121, TY_qc122, TY_qc123, TY_qc132;
-double TY_qc212, TY_qc221, TY_qc222, TY_qc223, TY_qc232;
-double TY_A12, TY_A21, TY_A22, TY_A23, TY_A32, TY_A41, TY_A42, TY_A43, TY_A52;
-double TY_B12, TY_B14, TY_B21, TY_B22, TY_B23, TY_B24, TY_B25, TY_B32, TY_B34;
-double TY_F14, TY_F16, TY_F18, TY_F23, TY_F24, TY_F25, TY_F26, TY_F27, TY_F28, TY_F29, TY_F32, TY_F33, TY_F34, TY_F35, TY_F36, TY_F37, TY_F38, TY_F39, TY_F310;
-double TY_G13, TY_G14, TY_G15, TY_G16, TY_G17, TY_G18, TY_G19, TY_G110, TY_G111, TY_G112, TY_G113, TY_G22, TY_G23, TY_G24, TY_G25, TY_G26, TY_G27, TY_G28, TY_G29, TY_G210, TY_G211, TY_G212, TY_G213, TY_G214;
-double TY_w[23];
-
-double TY_sigma( double s, 
-				 double Z1, double Z2, 
-			     double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return -(a / 2. + b + c1 * exp( -Z1 ) + c2 * exp( -Z2 )) / s + a * pow( s, -3 ) + b * pow( s, -2 ) + 
-	( c1 + d1 ) * pow( s + Z1, -1 ) + ( c2 + d2 ) * pow( s + Z2, -1 );
-}
-
-double TY_tau( double s, 
-			   double Z1, double Z2, 
-		       double a, double b, double c1, double c2 )
-{
-	return b * pow( s, -2 ) + a * ( pow( s, -3 ) + pow( s, -2 ) ) - pow( s, -1 ) * ( c1 * Z1 * exp( -Z1 ) * 
-																					pow( s + Z1, -1 ) + c2 * Z2 * exp( -Z2 ) * pow( s + Z2, -1 ) );
-} 
-
-double TY_q( double s, 
-			     double Z1, double Z2, 
-			     double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return TY_sigma(s, Z1, Z2, a, b, c1, c2, d1, d2) - exp( -s ) * TY_tau(s, Z1, Z2, a,b, c1, c2);
-}
-
-double TY_g( double s, 
-		     double phi, double Z1, double Z2, 
-		     double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return s * TY_tau( s, Z1, Z2, a, b, c1, c2 ) * exp( -s ) / ( 1 - 12 * phi * TY_q( s, Z1, Z2, a, b, c1, c2, d1, d2 ) );
-}
-
-/*
- ================================================================================================== 
- 
- Structure factor for the potential 
- 
- V(r) = -kB * T * ( K1 * exp[ -Z1 * (r - 1)] / r + K2 * exp[ -Z2 * (r - 1)] / r ) for r > 1
- V(r) = inf for r <= 1
- 
- The structure factor is parametrized by (a, b, c1, c2, d1, d2) 
- which depend on (K1, K2, Z1, Z2, phi).  
- 
- ================================================================================================== 
- */
-
-double TY_hq( double q, double Z, double K, double v )
-{
-	double t1, t2, t3, t4;
-
-	if ( q == 0) 
-	{
-		return (exp(-2*Z)*(v + (v*(-1 + Z) - 2*K*Z)*exp(Z))*(-(v*(1 + Z)) + (v + 2*K*Z*(1 + Z))*exp(Z))*pow(K,-1)*pow(Z,-4))/4.;
-	}
-	else 
-	{
-		
-		t1 = ( 1 - v / ( 2 * K * Z * exp( Z ) ) ) * ( ( 1 - cos( q ) ) / ( q*q ) - 1 / ( Z*Z + q*q ) );
-		t2 = ( v*v * ( q * cos( q ) - Z * sin( q ) ) ) / ( 4 * K * Z*Z * q * ( Z*Z + q*q ) );
-		t3 = ( q * cos( q ) + Z * sin( q ) ) / ( q * ( Z*Z + q*q ) );
-		t4 = v / ( Z * exp( Z ) ) - v*v / ( 4 * K * Z*Z * exp( 2 * Z ) ) - K;
-		
-		return v / Z * t1 - t2 + t3 * t4;
-	}
-}
-
-double TY_pc( double q, 
-			  double Z1, double Z2,double K1, double K2, double phi,
-			  double a, double b, double c1, double c2, double d1, double d2 )
-{	
-	double v1 = 24 * phi * K1 * exp( Z1 ) * TY_g( Z1, phi, Z1, Z2, a, b, c1, c2, d1, d2 );
-	double v2 = 24 * phi * K2 * exp( Z2 ) * TY_g( Z2, phi, Z1, Z2, a, b, c1, c2, d1, d2 );
-	
-	double a0 = a * a;
-	double b0 = -12 * phi *( pow( a + b,2 ) / 2 + a * ( c1 * exp( -Z1 ) + c2 * exp( -Z2 ) ) );
-	
-	double t1, t2, t3,t4;
-	
-	if ( q == 0 ) 
-	{
-		t1 = a0 / 3;
-		t2 = b0 / 4;
-		t3 = a0 * phi / 12;
-	}
-	else 
-	{
-		t1 = a0 * ( sin( q ) - q * cos( q ) ) / pow( q, 3 );
-		t2 = b0 * ( 2 * q * sin( q ) - ( q * q - 2 ) * cos( q ) - 2 ) / pow( q, 4 );
-		t3 = a0 * phi * ( ( q*q - 6 ) * 4 * q * sin( q ) - ( pow( q, 4 ) - 12 * q*q + 24) * cos( q ) + 24 ) / ( 2 * pow( q, 6 ) );
-	}
-	t4 = TY_hq( q, Z1, K1, v1 ) + TY_hq( q, Z2, K2, v2 );
-	return -24 * phi * ( t1 + t2 + t3 + t4 );
-}
-
-double SqTwoYukawa( double q, 
-				    double Z1, double Z2, double K1, double K2, double phi,
-				    double a, double b, double c1, double c2, double d1, double d2 )
-{
-	if ( Z1 == Z2 ) 
-	{
-		// one-yukawa potential
-		return 0;
-	} 
-	else 
-	{
-		// two-yukawa potential
-		return 1. / ( 1. - TY_pc( q, Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	}
-}
-
-/*
-================================================================================================== 
-
- Non-linear eqaution system that determines the parameter for structure factor
-  
-================================================================================================== 
-*/
-
-double TY_LinearEquation_1( double Z1, double Z2, double K1, double K2, double phi, 
-						    double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return b - 12 * phi * ( -a / 8. - b / 6. + d1 * pow( Z1, -2 ) + c1 * ( pow( Z1, -2 )  - exp( -Z1 ) * 
-		    ( 0.5 + ( 1 + Z1 ) * pow( Z1, -2 ) ) ) + d2 * pow( Z2, -2 ) + c2 * ( pow( Z2, -2 ) - exp( -Z2 )
-			* ( 0.5 + ( 1 + Z2 ) * pow( Z2, -2 ) ) ) );
-}
-
-double TY_LinearEquation_2( double Z1, double Z2, double K1, double K2, double phi, 
-							double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return 1 - a - 12 * phi * ( -a / 3. - b / 2. + d1 * pow( Z1, -1 ) + c1 * ( pow( Z1, -1 ) - ( 1 + Z1 ) * 
-		   exp( -Z1 ) * pow( Z1, -1 ) ) + d2 * pow( Z2, -1 ) + c2 * ( pow( Z2, -1 ) - ( 1 + Z2 ) * exp( -Z2 ) * pow( Z2, -1 ) ) );
-}	
-
-double TY_LinearEquation_3( double Z1, double Z2, double K1, double K2, double phi, 
-						    double a, double b, double c1, double c2, double d1, double d2 )
-{								
-	return K1 * exp( Z1 ) - d1 * Z1 * ( 1 - 12 * phi * TY_q( Z1, Z1, Z2, a, b, c1, c2, d1, d2 ) ); 
-}
-
-double TY_LinearEquation_4( double Z1, double Z2, double K1, double K2, double phi, 
-						    double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return K2 * exp( Z2 ) - d2 * Z2 * ( 1 - 12 * phi * TY_q( Z2, Z1, Z2, a, b, c1, c2, d1, d2 ) );
-}
-
-double TY_NonlinearEquation_1( double Z1, double Z2, double K1, double K2, double phi, 
-						       double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return c1 + d1 - 12 * phi * ( ( c1 + d1 ) * TY_sigma( Z1, Z1, Z2, a, b, c1, c2, d1, d2 ) 
-								 - c1 * TY_tau( Z1, Z1, Z2, a, b, c1, c2 ) * exp( -Z1 ) );
-}
-
-double TY_NonlinearEquation_2( double Z1, double Z2, double K1, double K2, double phi, 
-						       double a, double b, double c1, double c2, double d1, double d2 )
-{
-	return c2 + d2 - 12 * phi * ( ( c2 + d2 ) * TY_sigma( Z2, Z1, Z2, a, b, c1, c2, d1, d2 ) 
-								 - c2 * TY_tau( Z2, Z1, Z2, a, b, c1, c2 ) * exp( -Z2 ) );
-}
-
-// Check the computed solutions satisfy the system of equations 
-int TY_CheckSolution( double Z1, double Z2, double K1, double K2, double phi, 
-				      double a, double b, double c1, double c2, double d1, double d2 )
-{
-	double eq_1 = chop( TY_LinearEquation_1( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	double eq_2 = chop( TY_LinearEquation_2( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	double eq_3 = chop( TY_LinearEquation_3( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	double eq_4 = chop( TY_LinearEquation_4( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	double eq_5 = chop( TY_NonlinearEquation_1( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	double eq_6 = chop( TY_NonlinearEquation_2( Z1, Z2, K1, K2, phi, a, b, c1, c2, d1, d2 ) );
-	
-	// check if all equation are zero
-	return eq_1 == 0 && eq_2 == 0 && eq_3 == 0 && eq_4 == 0 && eq_5 == 0 && eq_6 == 0;
-}
-
-void TY_ReduceNonlinearSystem( double Z1, double Z2, double K1, double K2, double phi, int debug )
-{
-	/* solution of the 4 linear equations depending on d1 and d2, the solution is polynomial
-	 in d1, d2. We represend the solution as determiants obtained by Cramer's rule
-	 which can be expressed by their coefficient matrices
-	 */
-	char buf[256];
-	
-	double m11 = (3*phi)/2.;
-	double m13 = 6*phi*exp(-Z1)*(2 + Z1*(2 + Z1) - 2*exp(Z1))*pow(Z1,-2);
-	double m14 = 6*phi*exp(-Z2)*(2 + Z2*(2 + Z2) - 2*exp(Z2))*pow(Z2,-2);
-	double m23 = -12*phi*exp(-Z1)*(-1 - Z1 + exp(Z1))*pow(Z1,-1);
-	double m24 = -12*phi*exp(-Z2)*(-1 - Z2 + exp(Z2))*pow(Z2,-1);
-	double m31 = -6*phi*exp(-Z1)*pow(Z1,-2)*(2*(1 + Z1) + exp(Z1)*(-2 + pow(Z1,2)));
-	double m32 = -12*phi*(-1 + Z1 + exp(-Z1))*pow(Z1,-1);
-	double m33 = 6*phi*exp(-2*Z1)*pow(-1 + exp(Z1),2);
-	double m34 = 12*phi*exp(-Z1 - Z2)*(Z2 - (Z1 + Z2)*exp(Z1) + Z1*exp(Z1 + Z2))*pow(Z1 + Z2,-1);
-	double m41 = -6*phi*exp(-Z2)*pow(Z2,-2)*(2*(1 + Z2) + exp(Z2)*(-2 + pow(Z2,2)));
-	double m42 = -12*phi*(-1 + Z2 + exp(-Z2))*pow(Z2,-1);
-	double m43 = 12*phi*exp(-Z1 - Z2)*(Z1 - (Z1 + Z2 - Z2*exp(Z1))*exp(Z2))*pow(Z1 + Z2,-1);	
-	double m44 = 6*phi*exp(-2*Z2)*pow(-1 + exp(Z2),2);
-	
-	/* determinant of the linear system expressed as coefficient matrix in d1, d2 */
-	
-	TY_q22 = m14*(-(m33*m42) + m23*(m32*m41 - m31*m42) + m32*m43 + (4*m11*(-3*m33*m41 + 2*m33*m42 + 3*m31*m43 - 2*m32*m43))/3.) + 
-		  m13*(m34*m42 + m24*(-(m32*m41) + m31*m42) - m32*m44 + (4*m11*(3*m34*m41 - 2*m34*m42 - 3*m31*m44 + 2*m32*m44))/3.) + (3*m24*
-		  (m33*(3*m41 + 4*m11*m41 - 3*m11*m42) + (-3*m31 - 4*m11*m31 + 3*m11*m32)*m43) + 3*m23*(-3*m34*m41 - 4*m11*m34*m41 + 
-		  3*m11*m34*m42 + 3*m31*m44 + 4*m11*m31*m44 - 3*m11*m32*m44) - (m34*m43 - m33*m44)*pow(3 - 2*m11,2))/9.;
-/*	
-	if( debug ) 
-	{
-		sprintf(buf,"\rDet = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t%f\r%f\t%f\r", 0., 0., 0., TY_q22 );
-		XOPNotice(buf);
-	}
-*/
-	
-	/* Matrix representation of the determinant of the of the system where row refering to 
-	 the variable a is replaced by solution vector */
-	
-	TY_qa12 = (K1*(3*m14*(m23*m42 - 4*m11*m43) - 3*m13*(m24*m42 - 4*m11*m44) + (3 + 4*m11)*(m24*m43 - m23*m44))*exp(Z1))/3.;
-	
-	TY_qa21 = -(K2*(3*m14*(m23*m32 - 4*m11*m33) - 3*m13*(m24*m32 - 4*m11*m34) + (3 + 4*m11)*(m24*m33 - m23*m34))*exp(Z2))/3.;
-	
-	TY_qa22 = m14*(-(m23*m42*Z1) + 4*m11*m43*Z1 - m33*(m42 + 4*m11*Z2) + m32*(m43 + m23*Z2)) + 
-		   (3*m13*(m24*m42*Z1 - 4*m11*m44*Z1 + m34*(m42 + 4*m11*Z2) - m32*(m44 + m24*Z2)) + 
-		   (3 + 4*m11)*(-(m24*m43*Z1) + m23*m44*Z1 - m34*(m43 + m23*Z2) + m33*(m44 + m24*Z2)))/3.;	
-	
-	TY_qa23 = 2*phi*pow(Z2,-2)*(m24*(2*(-3*m13*m42 + 3*m43 + 4*m11*m43)*Z1*pow(Z2,2) - m33*(Z1 + Z2)*(6*m42 + (3 + 4*m11)*pow(Z2,2)) + 
-		   3*m32*(Z1 + Z2)*(2*m43 + m13*pow(Z2,2))) + 
-		   m23*(2*(3*m14*m42 - 3*m44 - 4*m11*m44)*Z1*pow(Z2,2) + m34*(Z1 + Z2)*(6*m42 + (3 + 4*m11)*pow(Z2,2)) - 
-		   3*m32*(Z1 + Z2)*(2*m44 + m14*pow(Z2,2))) + 
-		   2*(3*(m14*m33*m42 - m13*m34*m42 - m14*m32*m43 + m34*m43 + m13*m32*m44 - m33*m44)*Z2*(Z1 + Z2) + 
-		   2*m11*(6*(-(m14*m43) + m13*m44)*Z1*pow(Z2,2) + m34*(Z1 + Z2)*(2*m43*(-3 + Z2) - 3*m13*pow(Z2,2)) + 
-		  m33*(Z1 + Z2)*(6*m44 - 2*m44*Z2 + 3*m14*pow(Z2,2)))))*pow(Z1 + Z2,-1);	
-	
-	TY_qa32 = 2*phi*pow(Z1,-2)*(m24*((-3*m13*m42 + (3 + 4*m11)*m43)*(Z1 + Z2)*pow(Z1,2) - 
-		   2*m33*(3*m42*(Z1 + Z2) + (3 + 4*m11)*Z2*pow(Z1,2)) + 6*m32*(m43*(Z1 + Z2) + m13*Z2*pow(Z1,2))) + 
-		   m23*((3*m14*m42 - (3 + 4*m11)*m44)*(Z1 + Z2)*pow(Z1,2) + m34*(6*m42*(Z1 + Z2) + 2*(3 + 4*m11)*Z2*pow(Z1,2)) - 
-		   6*m32*(m44*(Z1 + Z2) + m14*Z2*pow(Z1,2))) + 
-		   2*(3*(m14*m33*m42 - m13*m34*m42 - m14*m32*m43 + m34*m43 + m13*m32*m44 - m33*m44)*Z1*(Z1 + Z2) + 
-		   2*m11*(-3*(m14*m43 - m13*m44)*(Z1 + Z2)*pow(Z1,2) + 2*m34*(m43*(-3 + Z1)*(Z1 + Z2) - 3*m13*Z2*pow(Z1,2)) + 
-		  m33*(-2*m44*(-3 + Z1)*(Z1 + Z2) + 6*m14*Z2*pow(Z1,2)))))*pow(Z1 + Z2,-1);
-/*		
-	if( debug ) 
-	{
-		sprintf(buf,"\rDet_a = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t%f\t%f\r%f\t%f\t%f\r%f\t%f\t%f\r", 
-			   0., TY_qa12, 0., 
-			   TY_qa21, TY_qa22, TY_qa23, 
-			   0.,    TY_qa32, 0. );
-		XOPNotice(buf);
-	}
-*/
-	
-	/* Matrix representation of the determinant of the of the system where row refering to 
-	 the variable b is replaced by solution vector */
-	
-	TY_qb12 = (K1*(-3*m11*m24*m43 + m14*(-3*m23*m41 + (-3 + 8*m11)*m43) + 3*m11*m23*m44 + m13*(3*m24*m41 + 3*m44 - 8*m11*m44))*exp(Z1))/3.;
-	
-	TY_qb21 = (K2*(-3*m13*m24*m31 + 3*m11*m24*m33 + m14*(3*m23*m31 + (3 - 8*m11)*m33) - 3*m13*m34 + 8*m11*m13*m34 - 3*m11*m23*m34)*
-			exp(Z2))/3.;
-	
-	TY_qb22 = m13*(m31*m44 - m24*m41*Z1 - m44*Z1 + (8*m11*m44*Z1)/3. + m24*m31*Z2 + m34*(-m41 + Z2 - (8*m11*Z2)/3.)) + 
-		   m14*(m23*m41*Z1 + m43*Z1 - (8*m11*m43*Z1)/3. + m33*(m41 - Z2 + (8*m11*Z2)/3.) - m31*(m43 + m23*Z2)) + 
-		   m11*(m24*m43*Z1 - m23*m44*Z1 + m34*(m43 + m23*Z2) - m33*(m44 + m24*Z2));	
-	
-	TY_qb23 = 2*phi*(3*m14*m23*m31 - 3*m13*m24*m31 + 3*m14*m33 - 8*m11*m14*m33 + 3*m11*m24*m33 - 3*m13*m34 + 8*m11*m13*m34 - 
-		   3*m11*m23*m34 + 2*(3*m24*(m33*m41 - m31*m43) + m23*(-3*m34*m41 + 3*m31*m44) + (-3 + 8*m11)*(m34*m43 - m33*m44))*
-		   pow(Z2,-2) + 6*(-(m14*m33*m41) + m13*m34*m41 + m14*m31*m43 - m11*m34*m43 - m13*m31*m44 + m11*m33*m44)*pow(Z2,-1) + 
-		   2*(-3*m11*m24*m43 + m14*(-3*m23*m41 + (-3 + 8*m11)*m43) + 3*m11*m23*m44 + m13*(3*m24*m41 + 3*m44 - 8*m11*m44))*Z1*
-		   pow(Z1 + Z2,-1));
-	
-	TY_qb32 = 2*phi*pow(Z1,-2)*(6*(-(m34*(m23*m41 + m43)) + m24*(m33*m41 - m31*m43) + (m23*m31 + m33)*m44) + 
-		   6*(-(m14*m33*m41) + m13*m34*m41 + m14*m31*m43 - m13*m31*m44)*Z1 + 
-		   3*(m14*(2*m23*m31 + 2*m33 - m23*m41 - m43) + m13*(-2*m34 + m24*(-2*m31 + m41) + m44))*pow(Z1,2) + 
-		   (m11*Z2*(16*m34*m43 - 16*m33*m44 - 6*m34*m43*Z1 + 6*m33*m44*Z1 + 
-		   (6*m24*m33 - 3*m24*m43 + 8*m14*(-2*m33 + m43) + (8*m13 - 3*m23)*(2*m34 - m44))*pow(Z1,2)) + 
-		   m11*Z1*(2*m34*m43*(8 - 3*Z1) + 2*m33*m44*(-8 + 3*Z1) + (8*m14*m43 - 3*m24*m43 - 8*m13*m44 + 3*m23*m44)*pow(Z1,2)))*
-		   pow(Z1 + Z2,-1) + 6*(-(m14*(m23*m31 + m33)) + m13*(m24*m31 + m34))*pow(Z1,3)*pow(Z1 + Z2,-1));
-/*		
-	if( debug ) 
-	{
-		sprintf(buf,"\rDet_b = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t%f\t%f\r%f\t%f\t%f\r%f\t%f\t%f\r", 
-			   0., TY_qb12, 0.,
-			   TY_qb21, TY_qb22, TY_qb23,
-			   0., TY_qb32, 0. );
-		XOPNotice(buf);
-	}
-*/
-	
-	/* Matrix representation of the determinant of the of the system where row refering to 
-	 the variable c1 is replaced by solution vector */
-	
-	TY_qc112 = -(K1*exp(Z1)*(9*m24*m41 - 9*m14*m42 + 3*m11*(-12*m14*m41 + 4*m24*m41 + 8*m14*m42 - 3*m24*m42) + m44*pow(3 - 2*m11,2)))/9.;
-	
-	TY_qc121 = (K2*exp(Z2)*(9*m24*m31 - 9*m14*m32 + 3*m11*(-12*m14*m31 + 4*m24*m31 + 8*m14*m32 - 3*m24*m32) + m34*pow(3 - 2*m11,2)))/9.;
-	
-	TY_qc122 = m14*(-4*m11*m41*Z1 - m42*Z1 + (8*m11*m42*Z1)/3. + m32*(-m41 + Z2 - (8*m11*Z2)/3.) + m31*(m42 + 4*m11*Z2)) + 
-			(3*m34*((3 + 4*m11)*m41 - 3*m11*m42) + 9*m11*m32*m44 + 9*m24*m41*Z1 + 12*m11*m24*m41*Z1 - 9*m11*m24*m42*Z1 + 9*m44*Z1 - 
-			12*m11*m44*Z1 + 9*m11*m24*m32*Z2 - 3*(3 + 4*m11)*m31*(m44 + m24*Z2) - m34*Z2*pow(3 - 2*m11,2) + 4*m44*Z1*pow(m11,2))/9.;
-	
-	TY_qc123 = (2*phi*pow(Z2,-2)*(9*(m34*(Z1 + Z2)*(2*m42 + Z2*(-2*m41 + Z2)) - m32*(Z1 + Z2)*(2*m44 + m14*Z2*(-2*m41 + Z2)) - 
-			2*(m14*m42 - m44)*Z2*(-(Z1*Z2) + m31*(Z1 + Z2))) + 4*(-2*m44*Z1 + m34*(Z1 + Z2))*pow(m11,2)*pow(Z2,2) - 
-			3*m24*(2*(3*m41 + 4*m11*m41 - 3*m11*m42)*Z1*pow(Z2,2) + 3*m32*(Z1 + Z2)*(2*m41 + m11*pow(Z2,2)) - 
-			m31*(Z1 + Z2)*(6*m42 + (3 + 4*m11)*pow(Z2,2))) - 
-			6*m11*(-8*m32*m44*Z1 + m32*m44*(-8 + 3*Z1)*Z2 + (3*m32*m44 - 4*(m14*(m32 + 3*m41 - 2*m42) + m44)*Z1)*pow(Z2,2) + 
-			m34*(Z1 + Z2)*(8*m42 + 4*m41*(-3 + Z2) - 3*m42*Z2 + 2*pow(Z2,2)) + 2*m31*(Z1 + Z2)*(6*m44 - 2*m44*Z2 + 3*m14*pow(Z2,2)) - 
-			4*m14*m32*pow(Z2,3)))*pow(Z1 + Z2,-1))/3.;
-	
-	TY_qc132 = (-2*phi*pow(Z1,-2)*(9*((m14*m42 - m44)*(2*m31 - Z1)*Z1*(Z1 + Z2) - 2*m34*(m42*(Z1 + Z2) - Z1*(-(Z1*Z2) + m41*(Z1 + Z2))) + 
-			2*m32*(m44*(Z1 + Z2) - m14*Z1*(-(Z1*Z2) + m41*(Z1 + Z2)))) + 4*(-2*m34*Z2 + m44*(Z1 + Z2))*pow(m11,2)*pow(Z1,2) + 
-			3*m24*(((3 + 4*m11)*m41 - 3*m11*m42)*(Z1 + Z2)*pow(Z1,2) + 6*m32*(m41*(Z1 + Z2) + m11*Z2*pow(Z1,2)) - 
-			2*m31*(3*m42*(Z1 + Z2) + (3 + 4*m11)*Z2*pow(Z1,2))) + 
-			6*m11*(Z1*(-8*m32*m44 + m34*(m42*(8 - 3*Z1) + 4*m41*(-3 + Z1)) - 4*m31*m44*(-3 + Z1) + 3*m32*m44*Z1 - 
-			2*(3*m14*m41 - 2*m14*m42 + m44)*pow(Z1,2)) + 
-			Z2*(4*(3*m31 - 2*m32)*m44 + Z1*(-4*m31*m44 + 3*m32*m44 - 2*(m14*(-6*m31 + 4*m32 + 3*m41 - 2*m42) + m44)*Z1) + 
-			m34*(m42*(8 - 3*Z1) + 4*m41*(-3 + Z1) + 4*pow(Z1,2)))))*pow(Z1 + Z2,-1))/3.;
-/*		
-	if( debug ) 
-	{
-		sprintf(buf,"\rDet_c1 = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t%f\t%f\r%f\t%f\t%f\r%f\t%f\t%f\r", 
-			    0., TY_qc112, 0., 
-			   TY_qc121, TY_qc122, TY_qc123,
-			   0., TY_qc132, 0. );
-		XOPNotice(buf);
-	}
- */
-	/* Matrix representation of the determinant of the of the system where row refering to 
-	 the variable c1 is replaced by solution vector */
-	
-	TY_qc212 = (K1*exp(Z1)*(9*m23*m41 - 9*m13*m42 + 3*m11*(-12*m13*m41 + 4*m23*m41 + 8*m13*m42 - 3*m23*m42) + m43*pow(3 - 2*m11,2)))/9.;
-	
-	TY_qc221 = -(K2*exp(Z2)*(9*m23*m31 - 9*m13*m32 + 3*m11*(-12*m13*m31 + 4*m23*m31 + 8*m13*m32 - 3*m23*m32) + m33*pow(3 - 2*m11,2)))/9.;
-	
-	TY_qc222 = m13*(4*m11*m41*Z1 + m42*Z1 - (8*m11*m42*Z1)/3. + m32*(m41 - Z2 + (8*m11*Z2)/3.) - m31*(m42 + 4*m11*Z2)) + 
-			(9*m31*m43 - 9*(m23*m41 + m43)*Z1 + 9*m23*m31*Z2 + 3*m11*
-			((-4*m23*m41 + 3*m23*m42 + 4*m43)*Z1 + 4*m31*(m43 + m23*Z2) - 3*m32*(m43 + m23*Z2)) + 
-			m33*(-3*(3 + 4*m11)*m41 + 9*m11*m42 + Z2*pow(3 - 2*m11,2)) - 4*m43*Z1*pow(m11,2))/9.;
-	
-	TY_qc223 = (2*phi*pow(Z2,-2)*(9*(-(m33*(Z1 + Z2)*(2*m42 + Z2*(-2*m41 + Z2))) + m32*(Z1 + Z2)*(2*m43 + m13*Z2*(-2*m41 + Z2)) + 
-			2*(m13*m42 - m43)*Z2*(-(Z1*Z2) + m31*(Z1 + Z2))) - 4*(-2*m43*Z1 + m33*(Z1 + Z2))*pow(m11,2)*pow(Z2,2) + 
-			3*m23*(2*(3*m41 + 4*m11*m41 - 3*m11*m42)*Z1*pow(Z2,2) + 3*m32*(Z1 + Z2)*(2*m41 + m11*pow(Z2,2)) - 
-			m31*(Z1 + Z2)*(6*m42 + (3 + 4*m11)*pow(Z2,2))) + 
-			6*m11*(-8*m32*m43*Z1 + m32*m43*(-8 + 3*Z1)*Z2 + (3*m32*m43 - 4*(m13*(m32 + 3*m41 - 2*m42) + m43)*Z1)*pow(Z2,2) + 
-			m33*(Z1 + Z2)*(8*m42 + 4*m41*(-3 + Z2) - 3*m42*Z2 + 2*pow(Z2,2)) + 2*m31*(Z1 + Z2)*(6*m43 - 2*m43*Z2 + 3*m13*pow(Z2,2)) - 
-			4*m13*m32*pow(Z2,3)))*pow(Z1 + Z2,-1))/3.;
-	
-	TY_qc232 = (2*phi*pow(Z1,-2)*(9*((m13*m42 - m43)*(2*m31 - Z1)*Z1*(Z1 + Z2) - 2*m33*(m42*(Z1 + Z2) - Z1*(-(Z1*Z2) + m41*(Z1 + Z2))) + 
-			2*m32*(m43*(Z1 + Z2) - m13*Z1*(-(Z1*Z2) + m41*(Z1 + Z2)))) + 4*(-2*m33*Z2 + m43*(Z1 + Z2))*pow(m11,2)*pow(Z1,2) + 
-			3*m23*(((3 + 4*m11)*m41 - 3*m11*m42)*(Z1 + Z2)*pow(Z1,2) + 6*m32*(m41*(Z1 + Z2) + m11*Z2*pow(Z1,2)) - 
-			2*m31*(3*m42*(Z1 + Z2) + (3 + 4*m11)*Z2*pow(Z1,2))) + 
-			6*m11*(Z1*(-8*m32*m43 + m33*(m42*(8 - 3*Z1) + 4*m41*(-3 + Z1)) - 4*m31*m43*(-3 + Z1) + 3*m32*m43*Z1 - 
-			2*(3*m13*m41 - 2*m13*m42 + m43)*pow(Z1,2)) + 
-			Z2*(4*(3*m31 - 2*m32)*m43 + Z1*(-4*m31*m43 + 3*m32*m43 - 2*(m13*(-6*m31 + 4*m32 + 3*m41 - 2*m42) + m43)*Z1) + 
-			m33*(m42*(8 - 3*Z1) + 4*m41*(-3 + Z1) + 4*pow(Z1,2)))))*pow(Z1 + Z2,-1))/3.;
-/*		
-	if( debug ) 
-	{
-		sprintf(buf,"\rDet_c2 = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t%f\t%f\r%f\t%f\t%f\r%f\t%f\t%f\r", 
-			   0., TY_qc212, 0., 
-			   TY_qc221, TY_qc222, TY_qc223, 
-			   0., TY_qc232, 0. );
-		XOPNotice(buf);
-	}	
-*/
-	
-	/* coefficient matrices of nonlinear equation 1 */
-	
-	TY_A12 = 6*phi*TY_qc112*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc212*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(exp(2*Z1)*(Z1*(2*TY_qb12*(-1 + Z1)*(Z1 + Z2) - Z1*(2*TY_qc212*Z1 + TY_qc112*(Z1 + Z2))) + TY_qa12*(Z1 + Z2)*(-2 + pow(Z1,2))) - 
-		  TY_qc112*(Z1 + Z2)*pow(Z1,2) + 2*(Z1 + Z2)*exp(Z1)*(TY_qa12 + (TY_qa12 + TY_qb12)*Z1 + TY_qc112*pow(Z1,2))))*pow(Z1 + Z2,-1);
-	
-	TY_A21 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc121*TY_qc212 + TY_qc112*TY_qc221)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(2*(TY_qa12*TY_qc121 + TY_qa21*TY_qc112*(1 + Z1) + Z1*(TY_qb21*TY_qc112 + TY_qc121*(TY_qa12 + TY_qb12 + 2*TY_qc112*Z1)))*(Z1 + Z2)*exp(Z1) + 
-		  exp(2*Z1)*(2*Z1*(TY_qb21*TY_qc112*(-1 + Z1)*(Z1 + Z2) + TY_qb12*TY_qc121*(-1 + Z1)*(Z1 + Z2) - 
-		  Z1*(TY_qc121*TY_qc212*Z1 + TY_qc112*(TY_qc121 + TY_qc221)*Z1 + TY_qc112*TY_qc121*Z2)) + TY_qa21*TY_qc112*(Z1 + Z2)*(-2 + pow(Z1,2)) + 
-		  TY_qa12*TY_qc121*(Z1 + Z2)*(-2 + pow(Z1,2))) - 2*TY_qc112*TY_qc121*(Z1 + Z2)*pow(Z1,2)))*pow(Z1 + Z2,-1);
-	
-	TY_A22 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(12*phi*(TY_qc122*TY_qc212 + TY_qc112*TY_qc222)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(12*phi*(TY_qa12*TY_qc122 + TY_qa22*TY_qc112*(1 + Z1) + Z1*(TY_qb22*TY_qc112 + TY_qc122*(TY_qa12 + TY_qb12 + 2*TY_qc112*Z1)))*(Z1 + Z2)*exp(Z1) - 
-		  2*phi*TY_qc112*TY_qc122*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*
-		  (6*phi*(2*Z1*(TY_qb22*TY_qc112*(-1 + Z1)*(Z1 + Z2) + TY_qb12*TY_qc122*(-1 + Z1)*(Z1 + Z2) - 
-		  Z1*(TY_qc122*TY_qc212*Z1 + TY_qc112*(TY_qc122 + TY_qc222)*Z1 + TY_qc112*TY_qc122*Z2)) + TY_qa22*TY_qc112*(Z1 + Z2)*(-2 + pow(Z1,2)) + 
-		  TY_qa12*TY_qc122*(Z1 + Z2)*(-2 + pow(Z1,2))) + TY_q22*TY_qc112*(Z1 + Z2)*pow(Z1,3))))*pow(Z1 + Z2,-1);
-	
-	TY_A23 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc123*TY_qc212 + TY_qc112*TY_qc223)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(2*(TY_qa12*TY_qc123 + TY_qa23*TY_qc112*(1 + Z1) + Z1*(TY_qb23*TY_qc112 + TY_qc123*(TY_qa12 + TY_qb12 + 2*TY_qc112*Z1)))*(Z1 + Z2)*exp(Z1) + 
-		  exp(2*Z1)*(2*Z1*(TY_qb23*TY_qc112*(-1 + Z1)*(Z1 + Z2) + TY_qb12*TY_qc123*(-1 + Z1)*(Z1 + Z2) - 
-		  Z1*((TY_q22*TY_qc112 + TY_qc123*(TY_qc112 + TY_qc212) + TY_qc112*TY_qc223)*Z1 + TY_qc112*TY_qc123*Z2)) + TY_qa23*TY_qc112*(Z1 + Z2)*(-2 + pow(Z1,2)) + 
-		  TY_qa12*TY_qc123*(Z1 + Z2)*(-2 + pow(Z1,2))) - 2*TY_qc112*TY_qc123*(Z1 + Z2)*pow(Z1,2)))*pow(Z1 + Z2,-1);
-	
-	TY_A32 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(12*phi*(TY_qa23*TY_qc121 + TY_qa22*TY_qc122 + TY_qa21*TY_qc123 + TY_qa12*TY_qc132 + TY_qa32*TY_qc112*(1 + Z1) + 
-		  Z1*(TY_qb32*TY_qc112 + (TY_qa23 + TY_qb23)*TY_qc121 + (TY_qa21 + TY_qb21)*TY_qc123 + (TY_qa12 + TY_qb12)*TY_qc132 + TY_q22*TY_qc112*Z1 + 
-		  2*(TY_qc121*TY_qc123 + TY_qc112*TY_qc132)*Z1 + TY_qc122*(TY_qa22 + TY_qb22 + TY_qc122*Z1)))*(Z1 + Z2)*exp(Z1 + Z2) - 
-		  12*phi*(TY_qc132*TY_qc212 + TY_qc123*TY_qc221 + TY_qc122*TY_qc222 + TY_qc121*TY_qc223 + TY_qc112*TY_qc232)*Z2*exp(Z1)*pow(Z1,2) + 
-		  12*phi*((TY_q22 + TY_qc132)*TY_qc212 + TY_qc123*TY_qc221 + TY_qc122*TY_qc222 + TY_qc121*TY_qc223 + TY_qc112*TY_qc232)*(Z1 + Z2)*exp(2*Z1)*pow(Z1,2) - 
-		  6*phi*(Z1 + Z2)*exp(Z2)*(2*TY_qc121*TY_qc123 + 2*TY_qc112*TY_qc132 + pow(TY_qc122,2))*pow(Z1,2) + 
-		  exp(2*Z1 + Z2)*(TY_q22*(6*phi*(2*Z1*(TY_qb12*(-1 + Z1)*(Z1 + Z2) - Z1*((TY_qc112 + TY_qc121 + TY_qc212)*Z1 + TY_qc112*Z2)) + 
-		  TY_qa12*(Z1 + Z2)*(-2 + pow(Z1,2))) + TY_qc122*(Z1 + Z2)*pow(Z1,3)) + 
-		  6*phi*(-2*TY_qa22*TY_qc122*Z1 - 2*TY_qa21*TY_qc123*Z1 - 2*TY_qa12*TY_qc132*Z1 + TY_qa32*TY_qc112*(Z1 + Z2)*(-2 + pow(Z1,2)) + 
-		  TY_qa23*TY_qc121*(Z1 + Z2)*(-2 + pow(Z1,2)) - 2*TY_qb32*TY_qc112*pow(Z1,2) - 2*TY_qb23*TY_qc121*pow(Z1,2) - 2*TY_qb22*TY_qc122*pow(Z1,2) - 
-		  2*TY_qb21*TY_qc123*pow(Z1,2) - 2*TY_qb12*TY_qc132*pow(Z1,2) + 
-		  Z2*(-2*(TY_qa22*TY_qc122 + TY_qa21*TY_qc123 + TY_qa12*TY_qc132) - 2*(TY_qb32*TY_qc112 + TY_qb23*TY_qc121 + TY_qb22*TY_qc122 + TY_qb21*TY_qc123 + TY_qb12*TY_qc132)*Z1 + 
-		  (2*TY_qb32*TY_qc112 + 2*TY_qb23*TY_qc121 + (TY_qa22 + 2*TY_qb22 - TY_qc122)*TY_qc122 + (TY_qa21 + 2*TY_qb21 - 2*TY_qc121)*TY_qc123 + 
-		  (TY_qa12 + 2*TY_qb12 - 2*TY_qc112)*TY_qc132)*pow(Z1,2)) + 2*TY_qb32*TY_qc112*pow(Z1,3) + 2*TY_qb23*TY_qc121*pow(Z1,3) + TY_qa22*TY_qc122*pow(Z1,3) + 
-		  2*TY_qb22*TY_qc122*pow(Z1,3) + TY_qa21*TY_qc123*pow(Z1,3) + 2*TY_qb21*TY_qc123*pow(Z1,3) - 2*TY_qc121*TY_qc123*pow(Z1,3) + TY_qa12*TY_qc132*pow(Z1,3) + 
-		  2*TY_qb12*TY_qc132*pow(Z1,3) - 2*TY_qc112*TY_qc132*pow(Z1,3) - 2*TY_qc132*TY_qc212*pow(Z1,3) - 2*TY_qc123*TY_qc221*pow(Z1,3) - 
-		  2*TY_qc122*TY_qc222*pow(Z1,3) - 2*TY_qc121*TY_qc223*pow(Z1,3) - 2*TY_qc112*TY_qc232*pow(Z1,3) - pow(TY_qc122,2)*pow(Z1,3))))*pow(Z1 + Z2,-1);
-	
-	TY_A41 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*
-		  ((-(TY_qc132*TY_qc221) - TY_qc121*TY_qc232)*Z2 + ((TY_q22 + TY_qc132)*TY_qc221 + TY_qc121*TY_qc232)*(Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(2*(TY_qa21*TY_qc132 + TY_qa32*TY_qc121*(1 + Z1) + Z1*(TY_qb32*TY_qc121 + (TY_qa21 + TY_qb21)*TY_qc132 + TY_qc121*(TY_q22 + 2*TY_qc132)*Z1))*(Z1 + Z2)*
-		  exp(Z1) - 2*TY_qc121*TY_qc132*(Z1 + Z2)*pow(Z1,2) + 
-		  exp(2*Z1)*(Z2*(-2*(TY_qa32*TY_qc121 + TY_qa21*(TY_q22 + TY_qc132)) - 2*(TY_qb32*TY_qc121 + TY_qb21*(TY_q22 + TY_qc132))*Z1 + 
-		  (TY_q22*(TY_qa21 + 2*TY_qb21 - 2*TY_qc121) + TY_qc121*(TY_qa32 + 2*TY_qb32 - 2*TY_qc132) + (TY_qa21 + 2*TY_qb21)*TY_qc132)*pow(Z1,2)) + 
-		  Z1*(-2*(TY_qa32*TY_qc121 + TY_qa21*(TY_q22 + TY_qc132)) - 2*(TY_qb32*TY_qc121 + TY_qb21*(TY_q22 + TY_qc132))*Z1 + 
-		  (TY_qa32*TY_qc121 + 2*TY_qb32*TY_qc121 + TY_qa21*TY_qc132 + 2*TY_qb21*TY_qc132 - 2*TY_qc121*TY_qc132 + TY_q22*(TY_qa21 + 2*TY_qb21 - 2*TY_qc121 - 2*TY_qc221) - 
-		  2*TY_qc132*TY_qc221 - 2*TY_qc121*TY_qc232)*pow(Z1,2)))))*pow(Z1 + Z2,-1);
-	
-	TY_A42 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(12*phi*(TY_qa22*TY_qc132 + TY_qa32*TY_qc122*(1 + Z1) + 
-		  Z1*(TY_qb32*TY_qc122 + (TY_qa22 + TY_qb22)*TY_qc132 + TY_qc122*(TY_q22 + 2*TY_qc132)*Z1))*(Z1 + Z2)*exp(Z1 + Z2) - 
-		  12*phi*(TY_qc132*TY_qc222 + TY_qc122*TY_qc232)*Z2*exp(Z1)*pow(Z1,2) + 
-		  12*phi*((TY_q22 + TY_qc132)*TY_qc222 + TY_qc122*TY_qc232)*(Z1 + Z2)*exp(2*Z1)*pow(Z1,2) - 12*phi*TY_qc122*TY_qc132*(Z1 + Z2)*exp(Z2)*pow(Z1,2) + 
-		  exp(2*Z1 + Z2)*(6*phi*(2*Z1*(TY_qb32*TY_qc122*(-1 + Z1)*(Z1 + Z2) + TY_qb22*TY_qc132*(-1 + Z1)*(Z1 + Z2) - 
-		  Z1*(TY_qc132*TY_qc222*Z1 + TY_qc122*(TY_qc132 + TY_qc232)*Z1 + TY_qc122*TY_qc132*Z2)) + TY_qa32*TY_qc122*(Z1 + Z2)*(-2 + pow(Z1,2)) + 
-		  TY_qa22*TY_qc132*(Z1 + Z2)*(-2 + pow(Z1,2))) + (Z1 + Z2)*pow(TY_q22,2)*pow(Z1,3) + 
-		  TY_q22*(6*phi*(2*Z1*(TY_qb22*(-1 + Z1)*(Z1 + Z2) - Z1*((TY_qc122 + TY_qc222)*Z1 + TY_qc122*Z2)) + TY_qa22*(Z1 + Z2)*(-2 + pow(Z1,2))) + 
-		  TY_qc132*(Z1 + Z2)*pow(Z1,3))))*pow(Z1 + Z2,-1);
-	
-	TY_A43 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*
-		  ((TY_qc132*TY_qc223 + TY_qc123*TY_qc232)*Z2 - ((TY_q22 + TY_qc132)*TY_qc223 + TY_qc123*TY_qc232)*(Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*(-2*(TY_qa23*TY_qc132 + TY_qa32*TY_qc123*(1 + Z1) + Z1*(TY_qb32*TY_qc123 + (TY_qa23 + TY_qb23)*TY_qc132 + TY_qc123*(TY_q22 + 2*TY_qc132)*Z1))*(Z1 + Z2)*
-		  exp(Z1) + 2*TY_qc123*TY_qc132*(Z1 + Z2)*pow(Z1,2) + 
-		  exp(2*Z1)*(Z2*(2*TY_qa32*TY_qc123 + 2*TY_qa23*(TY_q22 + TY_qc132) + 2*(TY_qb32*TY_qc123 + TY_qb23*(TY_q22 + TY_qc132))*Z1 - 
-		  (TY_q22*(TY_qa23 + 2*TY_qb23 - 2*TY_qc123) + TY_qc123*(TY_qa32 + 2*TY_qb32 - 2*TY_qc132) + (TY_qa23 + 2*TY_qb23)*TY_qc132)*pow(Z1,2)) + 
-		  Z1*(2*TY_qa32*TY_qc123 + 2*TY_qa23*(TY_q22 + TY_qc132) + 2*(TY_qb32*TY_qc123 + TY_qb23*(TY_q22 + TY_qc132))*Z1 + 
-		  (-(TY_qa32*TY_qc123) - (TY_qa23 + 2*TY_qb23)*TY_qc132 + TY_q22*(-TY_qa23 + 2*(-TY_qb23 + TY_qc123 + TY_qc132 + TY_qc223)) + 
-		  2*(-(TY_qb32*TY_qc123) + TY_qc132*(TY_qc123 + TY_qc223) + TY_qc123*TY_qc232) + 2*pow(TY_q22,2))*pow(Z1,2)))))*pow(Z1 + Z2,-1);
-	
-	TY_A52 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc232*exp(Z1)*(TY_qc132*Z2 - (TY_q22 + TY_qc132)*(Z1 + Z2)*exp(Z1))*pow(Z1,2) + 
-		  exp(Z2)*((TY_q22 + TY_qc132)*exp(2*Z1)*(Z1*(-2*TY_qb32*(-1 + Z1)*(Z1 + Z2) + Z1*((TY_q22 + TY_qc132 + 2*TY_qc232)*Z1 + (TY_q22 + TY_qc132)*Z2)) - 
-		  TY_qa32*(Z1 + Z2)*(-2 + pow(Z1,2))) + (Z1 + Z2)*pow(TY_qc132,2)*pow(Z1,2) - 
-		  2*TY_qc132*(Z1 + Z2)*exp(Z1)*(TY_qa32 + (TY_qa32 + TY_qb32)*Z1 + (TY_q22 + TY_qc132)*pow(Z1,2))))*pow(Z1 + Z2,-1);
-	
-	// normalize A
-	/*double norm_A = sqrt(pow(TY_A52,2)+pow(TY_A43,2)+pow(TY_A42, 2)+pow(TY_A41, 2)+pow(TY_A32, 2)+
-						 pow(TY_A23,2)+pow(TY_A22,2)+pow(TY_A21, 2)+pow(TY_A12, 2));
-	TY_A12 /= norm_A;
-	TY_A21 /= norm_A;
-	TY_A22 /= norm_A;
-	TY_A23 /= norm_A;
-	TY_A32 /= norm_A;
-	TY_A41 /= norm_A;
-	TY_A42 /= norm_A;
-	TY_A43 /= norm_A;
-	TY_A52 /= norm_A;*/
-/*	
-	if( debug ) 
-	{
-		sprintf(buf,"\rNonlinear equation 1 = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\r", 0.,   TY_A12, 0.   );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\r", TY_A21, TY_A22, TY_A23 );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\r",  0.,  TY_A32, 0.   );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\r", TY_A41, TY_A42, TY_A43 );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\r", 0.,   TY_A52, 0. );		
-		XOPNotice(buf);
-	}
- */
-	
-	/* coefficient matrices of nonlinear equation 2 */
-	
-	TY_B12 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc221*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 
-		  2*exp(Z2)*((Z1 + Z2)*(TY_qa12*TY_qc221 + TY_qa21*TY_qc212*(1 + Z2) + Z2*(TY_qb21*TY_qc212 + TY_qc221*(TY_qa12 + TY_qb12 + 2*TY_qc212*Z2)))*exp(Z1) + 
-		  (-(TY_qc121*TY_qc212) - TY_qc112*TY_qc221)*Z1*pow(Z2,2)) + 
-		  exp(2*Z2)*(exp(Z1)*(2*Z2*(TY_qb21*TY_qc212*(-1 + Z2)*(Z1 + Z2) + TY_qb12*TY_qc221*(-1 + Z2)*(Z1 + Z2) - 
-		  Z2*(TY_qc212*TY_qc221*Z1 + TY_qc112*TY_qc221*Z2 + TY_qc212*(TY_qc121 + TY_qc221)*Z2)) + TY_qa21*TY_qc212*(Z1 + Z2)*(-2 + pow(Z2,2)) + 
-		  TY_qa12*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2))) + 2*(TY_qc121*TY_qc212 + TY_qc112*TY_qc221)*(Z1 + Z2)*pow(Z2,2)))*pow(Z1 + Z2,-1);
-	
-	TY_B14 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc223*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 
-		  2*exp(Z2)*((Z1 + Z2)*(TY_qa12*TY_qc223 + TY_qa23*TY_qc212*(1 + Z2) + Z2*(TY_qb23*TY_qc212 + (TY_qa12 + TY_qb12)*TY_qc223 + TY_qc212*(TY_q22 + 2*TY_qc223)*Z2))*
-		  exp(Z1) + (-(TY_qc123*TY_qc212) - TY_qc112*TY_qc223)*Z1*pow(Z2,2)) + 
-		  exp(2*Z2)*(2*(TY_qc123*TY_qc212 + TY_qc112*(TY_q22 + TY_qc223))*(Z1 + Z2)*pow(Z2,2) + 
-		  exp(Z1)*(-2*(TY_qa23*TY_qc212 + TY_qa12*(TY_q22 + TY_qc223))*Z1 - 
-		  2*(TY_qa23*TY_qc212 + TY_qa12*(TY_q22 + TY_qc223) + (TY_qb23*TY_qc212 + TY_qb12*(TY_q22 + TY_qc223))*Z1)*Z2 + 
-		  (-2*(TY_qb23*TY_qc212 + TY_qb12*(TY_q22 + TY_qc223)) + (TY_q22*(TY_qa12 + 2*TY_qb12 - 2*TY_qc212) + TY_qc212*(TY_qa23 + 2*TY_qb23 - 2*TY_qc223) + 
-		  (TY_qa12 + 2*TY_qb12)*TY_qc223)*Z1)*pow(Z2,2) + 
-		  (TY_q22*(TY_qa12 + 2*TY_qb12 - 2*TY_qc112 - 2*TY_qc212) + TY_qc212*(TY_qa23 + 2*TY_qb23 - 2*TY_qc123 - 2*TY_qc223) + (TY_qa12 + 2*TY_qb12 - 2*TY_qc112)*TY_qc223)*
-		  pow(Z2,3))))*pow(Z1 + Z2,-1);
-	
-	TY_B21 = 6*phi*TY_qc221*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-(TY_qc221*(Z1 + Z2)*exp(Z1)*pow(Z2,2)) + 
-		  exp(2*Z2)*(exp(Z1)*(Z2*(2*TY_qb21*(-1 + Z2)*(Z1 + Z2) - Z2*(2*TY_qc121*Z2 + TY_qc221*(Z1 + Z2))) + TY_qa21*(Z1 + Z2)*(-2 + pow(Z2,2))) + 
-		  2*TY_qc121*(Z1 + Z2)*pow(Z2,2)) + 2*exp(Z2)*(-(TY_qc121*Z1*pow(Z2,2)) + (Z1 + Z2)*exp(Z1)*(TY_qa21 + (TY_qa21 + TY_qb21)*Z2 + TY_qc221*pow(Z2,2)))
-		  )*pow(Z1 + Z2,-1);
-	
-	TY_B22 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-12*phi*TY_qc221*TY_qc222*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 
-		  12*phi*exp(Z2)*((Z1 + Z2)*(TY_qa21*TY_qc222 + TY_qa22*TY_qc221*(1 + Z2) + Z2*(TY_qb22*TY_qc221 + TY_qc222*(TY_qa21 + TY_qb21 + 2*TY_qc221*Z2)))*exp(Z1) + 
-		  (-(TY_qc122*TY_qc221) - TY_qc121*TY_qc222)*Z1*pow(Z2,2)) + 
-		  exp(2*Z2)*(12*phi*(TY_qc122*TY_qc221 + TY_qc121*TY_qc222)*(Z1 + Z2)*pow(Z2,2) + 
-		  exp(Z1)*(6*phi*(2*Z2*(TY_qb22*TY_qc221*(-1 + Z2)*(Z1 + Z2) + TY_qb21*TY_qc222*(-1 + Z2)*(Z1 + Z2) - 
-		  Z2*(TY_qc221*TY_qc222*Z1 + TY_qc121*TY_qc222*Z2 + TY_qc221*(TY_qc122 + TY_qc222)*Z2)) + TY_qa22*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2)) + 
-		  TY_qa21*TY_qc222*(Z1 + Z2)*(-2 + pow(Z2,2))) + TY_q22*TY_qc221*(Z1 + Z2)*pow(Z2,3))))*pow(Z1 + Z2,-1);
-	
-	TY_B23 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-6*phi*(Z1 + Z2)*exp(Z1)*(2*TY_qc221*TY_qc223 + 2*TY_qc212*TY_qc232 + pow(TY_qc222,2))*pow(Z2,2) + 
-		  12*phi*exp(Z2)*((Z1 + Z2)*exp(Z1)*(TY_qa23*TY_qc221 + TY_qa22*TY_qc222 + TY_qa21*TY_qc223 + TY_qa12*TY_qc232 + TY_qa32*TY_qc212*(1 + Z2) + 
-		  Z2*(TY_qb32*TY_qc212 + (TY_qa23 + TY_qb23)*TY_qc221 + (TY_qa22 + TY_qb22)*TY_qc222 + (TY_qa21 + TY_qb21)*TY_qc223 + (TY_qa12 + TY_qb12)*TY_qc232 + 
-		  Z2*(TY_q22*TY_qc221 + 2*TY_qc221*TY_qc223 + 2*TY_qc212*TY_qc232 + pow(TY_qc222,2)))) + 
-		  (-(TY_qc132*TY_qc212) - TY_qc123*TY_qc221 - TY_qc122*TY_qc222 - TY_qc121*TY_qc223 - TY_qc112*TY_qc232)*Z1*pow(Z2,2)) + 
-		  exp(2*Z2)*(12*phi*(TY_qc132*TY_qc212 + TY_qc123*TY_qc221 + TY_qc122*TY_qc222 + TY_qc121*(TY_q22 + TY_qc223) + TY_qc112*TY_qc232)*(Z1 + Z2)*pow(Z2,2) + 
-		  exp(Z1)*(TY_q22*TY_qc222*(Z1 + Z2)*pow(Z2,3) - 6*phi*
-		  (2*(TY_qa32*TY_qc212 + TY_qa23*TY_qc221 + TY_qa22*TY_qc222 + TY_qa21*(TY_q22 + TY_qc223) + TY_qa12*TY_qc232)*Z1 + 
-		  2*(TY_qa32*TY_qc212 + TY_qa23*TY_qc221 + TY_qa22*TY_qc222 + TY_qa21*(TY_q22 + TY_qc223) + TY_qa12*TY_qc232 + 
-		  (TY_qb32*TY_qc212 + TY_qb23*TY_qc221 + TY_qb22*TY_qc222 + TY_qb21*(TY_q22 + TY_qc223) + TY_qb12*TY_qc232)*Z1)*Z2 - 
-		  (-2*(TY_qb32*TY_qc212 + TY_qb23*TY_qc221 + TY_qb22*TY_qc222 + TY_qb21*(TY_q22 + TY_qc223) + TY_qb12*TY_qc232) + 
-		  (TY_q22*(TY_qa21 + 2*TY_qb21 - 2*TY_qc221) + (TY_qa22 + 2*TY_qb22 - TY_qc222)*TY_qc222 + TY_qc221*(TY_qa23 + 2*TY_qb23 - 2*TY_qc223) + TY_qa21*TY_qc223 + 
-		  2*TY_qb21*TY_qc223 + TY_qc212*(TY_qa32 + 2*TY_qb32 - 2*TY_qc232) + TY_qa12*TY_qc232 + 2*TY_qb12*TY_qc232)*Z1)*pow(Z2,2) - 
-		  (TY_q22*(TY_qa21 + 2*TY_qb21 - 2*TY_qc121 - 2*TY_qc212 - 2*TY_qc221) + (TY_qa22 + 2*TY_qb22 - 2*TY_qc122 - TY_qc222)*TY_qc222 + 
-		  TY_qc221*(TY_qa23 + 2*TY_qb23 - 2*TY_qc123 - 2*TY_qc223) + (TY_qa21 + 2*TY_qb21 - 2*TY_qc121)*TY_qc223 + 
-		  TY_qc212*(TY_qa32 + 2*TY_qb32 - 2*TY_qc132 - 2*TY_qc232) + (TY_qa12 + 2*TY_qb12 - 2*TY_qc112)*TY_qc232)*pow(Z2,3)))))*pow(Z1 + Z2,-1);
-	
-	TY_B24 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(12*phi*(Z1 + Z2)*
-		  (TY_qa22*TY_qc223 + TY_qa23*TY_qc222*(1 + Z2) + Z2*(TY_qb23*TY_qc222 + (TY_qa22 + TY_qb22)*TY_qc223 + TY_qc222*(TY_q22 + 2*TY_qc223)*Z2))*exp(Z1 + Z2) - 
-		  12*phi*TY_qc222*TY_qc223*(Z1 + Z2)*exp(Z1)*pow(Z2,2) - 12*phi*(TY_qc123*TY_qc222 + TY_qc122*TY_qc223)*Z1*exp(Z2)*pow(Z2,2) + 
-		  12*phi*(TY_qc123*TY_qc222 + TY_qc122*(TY_q22 + TY_qc223))*(Z1 + Z2)*exp(2*Z2)*pow(Z2,2) + 
-		  exp(Z1 + 2*Z2)*(6*phi*(2*Z2*(TY_qb23*TY_qc222*(-1 + Z2)*(Z1 + Z2) + TY_qb22*TY_qc223*(-1 + Z2)*(Z1 + Z2) - 
-		  Z2*(TY_qc222*TY_qc223*Z1 + TY_qc122*TY_qc223*Z2 + TY_qc222*(TY_qc123 + TY_qc223)*Z2)) + TY_qa23*TY_qc222*(Z1 + Z2)*(-2 + pow(Z2,2)) + 
-		  TY_qa22*TY_qc223*(Z1 + Z2)*(-2 + pow(Z2,2))) + (Z1 + Z2)*pow(TY_q22,2)*pow(Z2,3) + 
-		  TY_q22*(6*phi*(2*Z2*(TY_qb22*(-1 + Z2)*(Z1 + Z2) - Z2*(TY_qc222*Z1 + (TY_qc122 + TY_qc222)*Z2)) + TY_qa22*(Z1 + Z2)*(-2 + pow(Z2,2))) + 
-		  TY_qc223*(Z1 + Z2)*pow(Z2,3))))*pow(Z1 + Z2,-1);
-	
-	TY_B25 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*((Z1 + Z2)*exp(Z1)*pow(TY_qc223,2)*pow(Z2,2) + 
-		  (TY_q22 + TY_qc223)*exp(2*Z2)*(exp(Z1)*(Z2*(-2*TY_qb23*(-1 + Z2)*(Z1 + Z2) + Z2*((TY_q22 + TY_qc223)*Z1 + (TY_q22 + 2*TY_qc123 + TY_qc223)*Z2)) - 
-		  TY_qa23*(Z1 + Z2)*(-2 + pow(Z2,2))) - 2*TY_qc123*(Z1 + Z2)*pow(Z2,2)) + 
-		  2*TY_qc223*exp(Z2)*(TY_qc123*Z1*pow(Z2,2) - (Z1 + Z2)*exp(Z1)*(TY_qa23 + (TY_qa23 + TY_qb23)*Z2 + (TY_q22 + TY_qc223)*pow(Z2,2))))*pow(Z1 + Z2,-1);
-	
-	TY_B32 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc221*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 
-		  2*exp(Z2)*((Z1 + Z2)*(TY_qa21*TY_qc232 + TY_qa32*TY_qc221*(1 + Z2) + Z2*(TY_qb32*TY_qc221 + TY_qc232*(TY_qa21 + TY_qb21 + 2*TY_qc221*Z2)))*exp(Z1) + 
-		  (-(TY_qc132*TY_qc221) - TY_qc121*TY_qc232)*Z1*pow(Z2,2)) + 
-		  exp(2*Z2)*(exp(Z1)*(2*Z2*(TY_qb32*TY_qc221*(-1 + Z2)*(Z1 + Z2) + TY_qb21*TY_qc232*(-1 + Z2)*(Z1 + Z2) - 
-		  Z2*(TY_qc221*TY_qc232*Z1 + TY_qc121*TY_qc232*Z2 + TY_qc221*(TY_q22 + TY_qc132 + TY_qc232)*Z2)) + TY_qa32*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2)) + 
-		  TY_qa21*TY_qc232*(Z1 + Z2)*(-2 + pow(Z2,2))) + 2*(TY_qc132*TY_qc221 + TY_qc121*TY_qc232)*(Z1 + Z2)*pow(Z2,2)))*pow(Z1 + Z2,-1);
-	
-	TY_B34 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(2*TY_qc223*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 
-		  2*exp(Z2)*(-((Z1 + Z2)*(TY_qa23*TY_qc232 + TY_qa32*TY_qc223*(1 + Z2) + Z2*(TY_qb32*TY_qc223 + TY_qc232*(TY_qa23 + TY_qb23 + TY_q22*Z2 + 2*TY_qc223*Z2)))*exp(Z1)) + 
-		  (TY_qc132*TY_qc223 + TY_qc123*TY_qc232)*Z1*pow(Z2,2)) + exp(2*Z2)*
-		  (-2*(TY_qc132*(TY_q22 + TY_qc223) + TY_qc123*TY_qc232)*(Z1 + Z2)*pow(Z2,2) + 
-		  exp(Z1)*(2*(TY_qa32*(TY_q22 + TY_qc223) + TY_qa23*TY_qc232)*Z1 + 
-		  2*(TY_qa32*(TY_q22 + TY_qc223) + TY_qa23*TY_qc232 + (TY_qb32*(TY_q22 + TY_qc223) + TY_qb23*TY_qc232)*Z1)*Z2 - 
-		  (-2*(TY_qb32*(TY_q22 + TY_qc223) + TY_qb23*TY_qc232) + ((TY_qa32 + 2*TY_qb32)*(TY_q22 + TY_qc223) + (-2*TY_q22 + TY_qa23 + 2*TY_qb23 - 2*TY_qc223)*TY_qc232)*Z1)*
-		  pow(Z2,2) + ((2*TY_q22 - TY_qa32 - 2*TY_qb32 + 2*TY_qc132)*(TY_q22 + TY_qc223) + (2*TY_q22 - TY_qa23 + 2*(-TY_qb23 + TY_qc123 + TY_qc223))*TY_qc232)*pow(Z2,3))))*pow(Z1 + Z2,-1);
-	
-	/*double norm_B = sqrt(pow(TY_B12, 2)+pow(TY_B14, 2)+pow(TY_B21, 2)+pow(TY_B22, 2)+pow(TY_B23, 2)+pow(TY_B24, 2)+pow(TY_B25, 2)+pow(TY_B32, 2)+pow(TY_B34, 2));
-	
-	TY_B12 /= norm_B;
-	TY_B14 /= norm_B;
-	TY_B21 /= norm_B;
-	TY_B22 /= norm_B;
-	TY_B23 /= norm_B;
-	TY_B24 /= norm_B;
-	TY_B25 /= norm_B;
-	TY_B32 /= norm_B;
-	TY_B34 /= norm_B; */
-/*	
-	if( debug ) 
-	{
-		sprintf(buf,"\rNonlinear equation 2 = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0.,  TY_B12, 0.,  TY_B14, 0.  );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\r", TY_B21, TY_B22, TY_B23, TY_B24, TY_B25 );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0.,  TY_B32, 0.,  TY_B34, 0.  );
-		XOPNotice(buf);
-	}
-*/
-	
-	/* decrease order of nonlinear equation 1 by means of equation 2 */
-	
-	TY_F14 = -(TY_A32*TY_B12*TY_B32) + TY_A52*pow(TY_B12,2) + TY_A12*pow(TY_B32,2);
-	TY_F16 = 2*TY_A52*TY_B12*TY_B14 - TY_A32*TY_B14*TY_B32 - TY_A32*TY_B12*TY_B34 + 2*TY_A12*TY_B32*TY_B34;
-	TY_F18 = -(TY_A32*TY_B14*TY_B34) + TY_A52*pow(TY_B14,2) + TY_A12*pow(TY_B34,2);
-	TY_F23 = 2*TY_A52*TY_B12*TY_B21 - TY_A41*TY_B12*TY_B32 - TY_A32*TY_B21*TY_B32 + TY_A21*pow(TY_B32,2);
-	TY_F24 = 2*TY_A52*TY_B12*TY_B22 - TY_A42*TY_B12*TY_B32 - TY_A32*TY_B22*TY_B32 + TY_A22*pow(TY_B32,2);
-	TY_F25 = 2*TY_A52*TY_B14*TY_B21 + 2*TY_A52*TY_B12*TY_B23 - TY_A43*TY_B12*TY_B32 - TY_A41*TY_B14*TY_B32 - TY_A32*TY_B23*TY_B32 - TY_A41*TY_B12*TY_B34 - TY_A32*TY_B21*TY_B34 + 2*TY_A21*TY_B32*TY_B34 + TY_A23*pow(TY_B32,2);
-	TY_F26 = 2*TY_A52*TY_B14*TY_B22 + 2*TY_A52*TY_B12*TY_B24 - TY_A42*TY_B14*TY_B32 - TY_A32*TY_B24*TY_B32 - TY_A42*TY_B12*TY_B34 - TY_A32*TY_B22*TY_B34 + 2*TY_A22*TY_B32*TY_B34;
-	TY_F27 = 2*TY_A52*TY_B14*TY_B23 + 2*TY_A52*TY_B12*TY_B25 - TY_A43*TY_B14*TY_B32 - TY_A32*TY_B25*TY_B32 - TY_A43*TY_B12*TY_B34 - TY_A41*TY_B14*TY_B34 - TY_A32*TY_B23*TY_B34 + 2*TY_A23*TY_B32*TY_B34 + TY_A21*pow(TY_B34,2);
-	TY_F28 = 2*TY_A52*TY_B14*TY_B24 - TY_A42*TY_B14*TY_B34 - TY_A32*TY_B24*TY_B34 + TY_A22*pow(TY_B34,2);
-	TY_F29 = 2*TY_A52*TY_B14*TY_B25 - TY_A43*TY_B14*TY_B34 - TY_A32*TY_B25*TY_B34 + TY_A23*pow(TY_B34,2);
-	TY_F32 = -(TY_A41*TY_B21*TY_B32) + TY_A52*pow(TY_B21,2);
-	TY_F33 = 2*TY_A52*TY_B21*TY_B22 - TY_A42*TY_B21*TY_B32 - TY_A41*TY_B22*TY_B32;
-	TY_F34 = 2*TY_A52*TY_B21*TY_B23 - TY_A43*TY_B21*TY_B32 - TY_A42*TY_B22*TY_B32 - TY_A41*TY_B23*TY_B32 - TY_A41*TY_B21*TY_B34 + TY_A52*pow(TY_B22,2);
-	TY_F35 = 2*TY_A52*TY_B22*TY_B23 + 2*TY_A52*TY_B21*TY_B24 - TY_A43*TY_B22*TY_B32 - TY_A42*TY_B23*TY_B32 - TY_A41*TY_B24*TY_B32 - TY_A42*TY_B21*TY_B34 - TY_A41*TY_B22*TY_B34;
-	TY_F36 = 2*TY_A52*TY_B22*TY_B24 + 2*TY_A52*TY_B21*TY_B25 - TY_A43*TY_B23*TY_B32 - TY_A42*TY_B24*TY_B32 - TY_A41*TY_B25*TY_B32 - TY_A43*TY_B21*TY_B34 - TY_A42*TY_B22*TY_B34 - TY_A41*TY_B23*TY_B34 + TY_A52*pow(TY_B23,2);
-	TY_F37 = 2*TY_A52*TY_B23*TY_B24 + 2*TY_A52*TY_B22*TY_B25 - TY_A43*TY_B24*TY_B32 - TY_A42*TY_B25*TY_B32 - TY_A43*TY_B22*TY_B34 - TY_A42*TY_B23*TY_B34 - TY_A41*TY_B24*TY_B34;
-	TY_F38 = 2*TY_A52*TY_B23*TY_B25 - TY_A43*TY_B25*TY_B32 - TY_A43*TY_B23*TY_B34 - TY_A42*TY_B24*TY_B34 - TY_A41*TY_B25*TY_B34 + TY_A52*pow(TY_B24,2);
-	TY_F39 = 2*TY_A52*TY_B24*TY_B25 - TY_A43*TY_B24*TY_B34 - TY_A42*TY_B25*TY_B34;
-	TY_F310 = -(TY_A43*TY_B25*TY_B34) + TY_A52*pow(TY_B25,2);
-
-/*
-	if( debug ) 
-	{
-		sprintf(buf,"\rF = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0., 0.,  0.,  TY_F14, 0.,  TY_F16, 0.,  TY_F18, 0.,  0.    );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0., 0.,  TY_F23, TY_F24, TY_F25, TY_F26, TY_F27, TY_F28, TY_F29, 0.    );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0., TY_F32, TY_F33, TY_F34, TY_F35, TY_F36, TY_F37, TY_F38, TY_F39, TY_F310 );
-		XOPNotice(buf);
-	}
-*/
- 
-	TY_G13  = -(TY_B12*TY_F32);
-	TY_G14  = -(TY_B12*TY_F33);
-	TY_G15  = TY_B32*TY_F14 - TY_B14*TY_F32 - TY_B12*TY_F34;
-	TY_G16  = -(TY_B14*TY_F33) - TY_B12*TY_F35;
-	TY_G17  = TY_B34*TY_F14 + TY_B32*TY_F16 - TY_B14*TY_F34 - TY_B12*TY_F36;
-	TY_G18  = -(TY_B14*TY_F35) - TY_B12*TY_F37;
-	TY_G19  = TY_B34*TY_F16 + TY_B32*TY_F18 - TY_B14*TY_F36 - TY_B12*TY_F38;
-	TY_G110 = -(TY_B14*TY_F37) - TY_B12*TY_F39;
-	TY_G111 = TY_B34*TY_F18 - TY_B12*TY_F310 - TY_B14*TY_F38;
-	TY_G112 = -(TY_B14*TY_F39);
-	TY_G113 = -(TY_B14*TY_F310);
-	TY_G22  = -(TY_B21*TY_F32);
-	TY_G23  = -(TY_B22*TY_F32) - TY_B21*TY_F33;
-	TY_G24  = TY_B32*TY_F23 - TY_B23*TY_F32 - TY_B22*TY_F33 - TY_B21*TY_F34;
-	TY_G25  = TY_B32*TY_F24 - TY_B24*TY_F32 - TY_B23*TY_F33 - TY_B22*TY_F34 - TY_B21*TY_F35;
-	TY_G26  = TY_B34*TY_F23 + TY_B32*TY_F25 - TY_B25*TY_F32 - TY_B24*TY_F33 - TY_B23*TY_F34 - TY_B22*TY_F35 - TY_B21*TY_F36;
-	TY_G27  = TY_B34*TY_F24 + TY_B32*TY_F26 - TY_B25*TY_F33 - TY_B24*TY_F34 - TY_B23*TY_F35 - TY_B22*TY_F36 - TY_B21*TY_F37;
-	TY_G28  = TY_B34*TY_F25 + TY_B32*TY_F27 - TY_B25*TY_F34 - TY_B24*TY_F35 - TY_B23*TY_F36 - TY_B22*TY_F37 - TY_B21*TY_F38;
-	TY_G29  = TY_B34*TY_F26 + TY_B32*TY_F28 - TY_B25*TY_F35 - TY_B24*TY_F36 - TY_B23*TY_F37 - TY_B22*TY_F38 - TY_B21*TY_F39;
-	TY_G210 = TY_B34*TY_F27 + TY_B32*TY_F29 - TY_B21*TY_F310 - TY_B25*TY_F36 - TY_B24*TY_F37 - TY_B23*TY_F38 - TY_B22*TY_F39;
-	TY_G211 = TY_B34*TY_F28 - TY_B22*TY_F310 - TY_B25*TY_F37 - TY_B24*TY_F38 - TY_B23*TY_F39;
-	TY_G212 = TY_B34*TY_F29 - TY_B23*TY_F310 - TY_B25*TY_F38 - TY_B24*TY_F39;
-	TY_G213 = -(TY_B24*TY_F310) - TY_B25*TY_F39;
-	TY_G214 = -(TY_B25*TY_F310);
-/*	
-	if( debug ) 
-	{
-		sprintf(buf,"\rG = \r" );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0., 0.,  TY_G13, TY_G14, TY_G15, TY_G16, TY_G17, TY_G18, TY_G19, TY_G110, TY_G111, TY_G112, TY_G113, 0. );
-		XOPNotice(buf);
-		sprintf(buf, "%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\t\t%f\r", 0., TY_G22, TY_G23, TY_G24, TY_G25, TY_G26, TY_G27, TY_G28, TY_G29, TY_G210, TY_G211, TY_G212, TY_G213, TY_G214 );
-		XOPNotice(buf);
-	}
-*/	
-	// coefficients for polynomial
-	TY_w[0] = (-(TY_A21*TY_B12) + TY_A12*TY_B21)*(TY_A52*TY_B21 - TY_A41*TY_B32)*pow(TY_B21,2)*pow(TY_B32,3);
-	
-	TY_w[1] = 2*TY_B32*TY_G13*TY_G14 - TY_B24*TY_G13*TY_G22 - TY_B23*TY_G14*TY_G22 - TY_B22*TY_G15*TY_G22 - TY_B21*TY_G16*TY_G22 - TY_B23*TY_G13*TY_G23 - TY_B22*TY_G14*TY_G23 - TY_B21*TY_G15*TY_G23 + 2*TY_B14*TY_G22*TY_G23 - 
-	TY_B22*TY_G13*TY_G24 - TY_B21*TY_G14*TY_G24 + 2*TY_B12*TY_G23*TY_G24 - TY_B21*TY_G13*TY_G25 + 2*TY_B12*TY_G22*TY_G25;
-	
-	TY_w[2] = -(TY_B25*TY_G13*TY_G22) - TY_B24*TY_G14*TY_G22 - TY_B23*TY_G15*TY_G22 - TY_B22*TY_G16*TY_G22 - TY_B21*TY_G17*TY_G22 - TY_B24*TY_G13*TY_G23 - TY_B23*TY_G14*TY_G23 - TY_B22*TY_G15*TY_G23 - TY_B21*TY_G16*TY_G23 - 
-	TY_B23*TY_G13*TY_G24 - TY_B22*TY_G14*TY_G24 - TY_B21*TY_G15*TY_G24 + 2*TY_B14*TY_G22*TY_G24 - TY_B22*TY_G13*TY_G25 - TY_B21*TY_G14*TY_G25 + 2*TY_B12*TY_G23*TY_G25 - TY_B21*TY_G13*TY_G26 + 2*TY_B12*TY_G22*TY_G26 + 
-	TY_B34*pow(TY_G13,2) + TY_B32*(2*TY_G13*TY_G15 + pow(TY_G14,2)) + TY_B14*pow(TY_G23,2) + TY_B12*pow(TY_G24,2);
-	
-	TY_w[3] = 2*TY_B34*TY_G13*TY_G14 + 2*TY_B32*(TY_G14*TY_G15 + TY_G13*TY_G16) - TY_B25*TY_G14*TY_G22 - TY_B24*TY_G15*TY_G22 - TY_B23*TY_G16*TY_G22 - TY_B22*TY_G17*TY_G22 - TY_B21*TY_G18*TY_G22 - TY_B25*TY_G13*TY_G23 - 
-	TY_B24*TY_G14*TY_G23 - TY_B23*TY_G15*TY_G23 - TY_B22*TY_G16*TY_G23 - TY_B21*TY_G17*TY_G23 - TY_B24*TY_G13*TY_G24 - TY_B23*TY_G14*TY_G24 - TY_B22*TY_G15*TY_G24 - TY_B21*TY_G16*TY_G24 + 2*TY_B14*TY_G23*TY_G24 - 
-	TY_B23*TY_G13*TY_G25 - TY_B22*TY_G14*TY_G25 - TY_B21*TY_G15*TY_G25 + 2*TY_B14*TY_G22*TY_G25 + 2*TY_B12*TY_G24*TY_G25 - TY_B22*TY_G13*TY_G26 - TY_B21*TY_G14*TY_G26 + 2*TY_B12*TY_G23*TY_G26 - TY_B21*TY_G13*TY_G27 + 
-	2*TY_B12*TY_G22*TY_G27;
-	
-	TY_w[4] = -(TY_B25*TY_G15*TY_G22) - TY_B24*TY_G16*TY_G22 - TY_B23*TY_G17*TY_G22 - TY_B22*TY_G18*TY_G22 - TY_B21*TY_G19*TY_G22 - TY_B25*TY_G14*TY_G23 - TY_B24*TY_G15*TY_G23 - TY_B23*TY_G16*TY_G23 - TY_B22*TY_G17*TY_G23 - 
-	TY_B21*TY_G18*TY_G23 - TY_B25*TY_G13*TY_G24 - TY_B24*TY_G14*TY_G24 - TY_B23*TY_G15*TY_G24 - TY_B22*TY_G16*TY_G24 - TY_B21*TY_G17*TY_G24 - TY_B24*TY_G13*TY_G25 - TY_B23*TY_G14*TY_G25 - TY_B22*TY_G15*TY_G25 - 
-	TY_B21*TY_G16*TY_G25 + 2*TY_B14*TY_G23*TY_G25 - TY_B23*TY_G13*TY_G26 - TY_B22*TY_G14*TY_G26 - TY_B21*TY_G15*TY_G26 + 2*TY_B14*TY_G22*TY_G26 + 2*TY_B12*TY_G24*TY_G26 - TY_B22*TY_G13*TY_G27 - TY_B21*TY_G14*TY_G27 + 
-	2*TY_B12*TY_G23*TY_G27 - TY_B21*TY_G13*TY_G28 + 2*TY_B12*TY_G22*TY_G28 + TY_B34*(2*TY_G13*TY_G15 + pow(TY_G14,2)) + TY_B32*(2*TY_G14*TY_G16 + 2*TY_G13*TY_G17 + pow(TY_G15,2)) + TY_B14*pow(TY_G24,2) + 
-	TY_B12*pow(TY_G25,2);
-	
-	TY_w[5] = 2*TY_B34*(TY_G14*TY_G15 + TY_G13*TY_G16) + 2*TY_B32*(TY_G15*TY_G16 + TY_G14*TY_G17 + TY_G13*TY_G18) - TY_B21*TY_G110*TY_G22 - TY_B25*TY_G16*TY_G22 - TY_B24*TY_G17*TY_G22 - TY_B23*TY_G18*TY_G22 - TY_B22*TY_G19*TY_G22 - 
-	TY_B25*TY_G15*TY_G23 - TY_B24*TY_G16*TY_G23 - TY_B23*TY_G17*TY_G23 - TY_B22*TY_G18*TY_G23 - TY_B21*TY_G19*TY_G23 - TY_B25*TY_G14*TY_G24 - TY_B24*TY_G15*TY_G24 - TY_B23*TY_G16*TY_G24 - TY_B22*TY_G17*TY_G24 - 
-	TY_B21*TY_G18*TY_G24 - TY_B25*TY_G13*TY_G25 - TY_B24*TY_G14*TY_G25 - TY_B23*TY_G15*TY_G25 - TY_B22*TY_G16*TY_G25 - TY_B21*TY_G17*TY_G25 + 2*TY_B14*TY_G24*TY_G25 - TY_B24*TY_G13*TY_G26 - TY_B23*TY_G14*TY_G26 - 
-	TY_B22*TY_G15*TY_G26 - TY_B21*TY_G16*TY_G26 + 2*TY_B14*TY_G23*TY_G26 + 2*TY_B12*TY_G25*TY_G26 - TY_B23*TY_G13*TY_G27 - TY_B22*TY_G14*TY_G27 - TY_B21*TY_G15*TY_G27 + 2*TY_B14*TY_G22*TY_G27 + 2*TY_B12*TY_G24*TY_G27 - 
-	TY_B22*TY_G13*TY_G28 - TY_B21*TY_G14*TY_G28 + 2*TY_B12*TY_G23*TY_G28 - TY_B21*TY_G13*TY_G29 + 2*TY_B12*TY_G22*TY_G29;
-	
-	TY_w[6] = -(TY_B22*TY_G110*TY_G22) - TY_B21*TY_G111*TY_G22 - TY_B25*TY_G17*TY_G22 - TY_B24*TY_G18*TY_G22 - TY_B23*TY_G19*TY_G22 + TY_G210*(-(TY_B21*TY_G13) + 2*TY_B12*TY_G22) - TY_B21*TY_G110*TY_G23 - TY_B25*TY_G16*TY_G23 - 
-	TY_B24*TY_G17*TY_G23 - TY_B23*TY_G18*TY_G23 - TY_B22*TY_G19*TY_G23 - TY_B25*TY_G15*TY_G24 - TY_B24*TY_G16*TY_G24 - TY_B23*TY_G17*TY_G24 - TY_B22*TY_G18*TY_G24 - TY_B21*TY_G19*TY_G24 - TY_B25*TY_G14*TY_G25 - 
-	TY_B24*TY_G15*TY_G25 - TY_B23*TY_G16*TY_G25 - TY_B22*TY_G17*TY_G25 - TY_B21*TY_G18*TY_G25 - TY_B25*TY_G13*TY_G26 - TY_B24*TY_G14*TY_G26 - TY_B23*TY_G15*TY_G26 - TY_B22*TY_G16*TY_G26 - TY_B21*TY_G17*TY_G26 + 
-	2*TY_B14*TY_G24*TY_G26 - TY_B24*TY_G13*TY_G27 - TY_B23*TY_G14*TY_G27 - TY_B22*TY_G15*TY_G27 - TY_B21*TY_G16*TY_G27 + 2*TY_B14*TY_G23*TY_G27 + 2*TY_B12*TY_G25*TY_G27 - TY_B23*TY_G13*TY_G28 - TY_B22*TY_G14*TY_G28 - 
-	TY_B21*TY_G15*TY_G28 + 2*TY_B14*TY_G22*TY_G28 + 2*TY_B12*TY_G24*TY_G28 - TY_B22*TY_G13*TY_G29 - TY_B21*TY_G14*TY_G29 + 2*TY_B12*TY_G23*TY_G29 + TY_B34*(2*TY_G14*TY_G16 + 2*TY_G13*TY_G17 + pow(TY_G15,2)) + 
-	TY_B32*(2*(TY_G15*TY_G17 + TY_G14*TY_G18 + TY_G13*TY_G19) + pow(TY_G16,2)) + TY_B14*pow(TY_G25,2) + TY_B12*pow(TY_G26,2);
-	
-	TY_w[7] = 2*TY_B34*(TY_G15*TY_G16 + TY_G14*TY_G17 + TY_G13*TY_G18) + 2*TY_B32*(TY_G110*TY_G13 + TY_G16*TY_G17 + TY_G15*TY_G18 + TY_G14*TY_G19) - TY_B22*TY_G13*TY_G210 - TY_B21*TY_G14*TY_G210 - TY_B23*TY_G110*TY_G22 - 
-	TY_B22*TY_G111*TY_G22 - TY_B21*TY_G112*TY_G22 - TY_B25*TY_G18*TY_G22 - TY_B24*TY_G19*TY_G22 + TY_G211*(-(TY_B21*TY_G13) + 2*TY_B12*TY_G22) - TY_B22*TY_G110*TY_G23 - TY_B21*TY_G111*TY_G23 - TY_B25*TY_G17*TY_G23 - 
-	TY_B24*TY_G18*TY_G23 - TY_B23*TY_G19*TY_G23 + 2*TY_B12*TY_G210*TY_G23 - TY_B21*TY_G110*TY_G24 - TY_B25*TY_G16*TY_G24 - TY_B24*TY_G17*TY_G24 - TY_B23*TY_G18*TY_G24 - TY_B22*TY_G19*TY_G24 - TY_B25*TY_G15*TY_G25 - 
-	TY_B24*TY_G16*TY_G25 - TY_B23*TY_G17*TY_G25 - TY_B22*TY_G18*TY_G25 - TY_B21*TY_G19*TY_G25 - TY_B25*TY_G14*TY_G26 - TY_B24*TY_G15*TY_G26 - TY_B23*TY_G16*TY_G26 - TY_B22*TY_G17*TY_G26 - TY_B21*TY_G18*TY_G26 + 
-	2*TY_B14*TY_G25*TY_G26 - TY_B25*TY_G13*TY_G27 - TY_B24*TY_G14*TY_G27 - TY_B23*TY_G15*TY_G27 - TY_B22*TY_G16*TY_G27 - TY_B21*TY_G17*TY_G27 + 2*TY_B14*TY_G24*TY_G27 + 2*TY_B12*TY_G26*TY_G27 - TY_B24*TY_G13*TY_G28 - 
-	TY_B23*TY_G14*TY_G28 - TY_B22*TY_G15*TY_G28 - TY_B21*TY_G16*TY_G28 + 2*TY_B14*TY_G23*TY_G28 + 2*TY_B12*TY_G25*TY_G28 - TY_B23*TY_G13*TY_G29 - TY_B22*TY_G14*TY_G29 - TY_B21*TY_G15*TY_G29 + 2*TY_B14*TY_G22*TY_G29 + 
-	2*TY_B12*TY_G24*TY_G29;
-	
-	TY_w[8] = -(TY_B23*TY_G13*TY_G210) - TY_B22*TY_G14*TY_G210 - TY_B21*TY_G15*TY_G210 - TY_B22*TY_G13*TY_G211 - TY_B21*TY_G14*TY_G211 - TY_B21*TY_G13*TY_G212 - TY_B24*TY_G110*TY_G22 - TY_B23*TY_G111*TY_G22 - TY_B22*TY_G112*TY_G22 - 
-	TY_B21*TY_G113*TY_G22 - TY_B25*TY_G19*TY_G22 + 2*TY_B14*TY_G210*TY_G22 + 2*TY_B12*TY_G212*TY_G22 - TY_B23*TY_G110*TY_G23 - TY_B22*TY_G111*TY_G23 - TY_B21*TY_G112*TY_G23 - TY_B25*TY_G18*TY_G23 - TY_B24*TY_G19*TY_G23 + 
-	2*TY_B12*TY_G211*TY_G23 - TY_B22*TY_G110*TY_G24 - TY_B21*TY_G111*TY_G24 - TY_B25*TY_G17*TY_G24 - TY_B24*TY_G18*TY_G24 - TY_B23*TY_G19*TY_G24 + 2*TY_B12*TY_G210*TY_G24 - TY_B21*TY_G110*TY_G25 - TY_B25*TY_G16*TY_G25 - 
-	TY_B24*TY_G17*TY_G25 - TY_B23*TY_G18*TY_G25 - TY_B22*TY_G19*TY_G25 - TY_B25*TY_G15*TY_G26 - TY_B24*TY_G16*TY_G26 - TY_B23*TY_G17*TY_G26 - TY_B22*TY_G18*TY_G26 - TY_B21*TY_G19*TY_G26 - TY_B25*TY_G14*TY_G27 - 
-	TY_B24*TY_G15*TY_G27 - TY_B23*TY_G16*TY_G27 - TY_B22*TY_G17*TY_G27 - TY_B21*TY_G18*TY_G27 + 2*TY_B14*TY_G25*TY_G27 - TY_B25*TY_G13*TY_G28 - TY_B24*TY_G14*TY_G28 - TY_B23*TY_G15*TY_G28 - TY_B22*TY_G16*TY_G28 - 
-	TY_B21*TY_G17*TY_G28 + 2*TY_B14*TY_G24*TY_G28 + 2*TY_B12*TY_G26*TY_G28 - TY_B24*TY_G13*TY_G29 - TY_B23*TY_G14*TY_G29 - TY_B22*TY_G15*TY_G29 - TY_B21*TY_G16*TY_G29 + 2*TY_B14*TY_G23*TY_G29 + 2*TY_B12*TY_G25*TY_G29 + 
-	TY_B34*(2*(TY_G15*TY_G17 + TY_G14*TY_G18 + TY_G13*TY_G19) + pow(TY_G16,2)) + TY_B32*(2*(TY_G111*TY_G13 + TY_G110*TY_G14 + TY_G16*TY_G18 + TY_G15*TY_G19) + pow(TY_G17,2)) + TY_B14*pow(TY_G26,2) + 
-	TY_B12*pow(TY_G27,2);
-	
-	TY_w[9] = 2*TY_B34*(TY_G110*TY_G13 + TY_G16*TY_G17 + TY_G15*TY_G18 + TY_G14*TY_G19) + 2*TY_B32*(TY_G112*TY_G13 + TY_G111*TY_G14 + TY_G110*TY_G15 + TY_G17*TY_G18 + TY_G16*TY_G19) - TY_B24*TY_G13*TY_G210 - TY_B23*TY_G14*TY_G210 - 
-	TY_B22*TY_G15*TY_G210 - TY_B21*TY_G16*TY_G210 - TY_B23*TY_G13*TY_G211 - TY_B22*TY_G14*TY_G211 - TY_B21*TY_G15*TY_G211 - TY_B22*TY_G13*TY_G212 - TY_B21*TY_G14*TY_G212 - TY_B25*TY_G110*TY_G22 - TY_B24*TY_G111*TY_G22 - 
-	TY_B23*TY_G112*TY_G22 - TY_B22*TY_G113*TY_G22 + 2*TY_B14*TY_G211*TY_G22 + TY_G213*(-(TY_B21*TY_G13) + 2*TY_B12*TY_G22) - TY_B24*TY_G110*TY_G23 - TY_B23*TY_G111*TY_G23 - TY_B22*TY_G112*TY_G23 - 
-	TY_B21*TY_G113*TY_G23 - TY_B25*TY_G19*TY_G23 + 2*TY_B14*TY_G210*TY_G23 + 2*TY_B12*TY_G212*TY_G23 - TY_B23*TY_G110*TY_G24 - TY_B22*TY_G111*TY_G24 - TY_B21*TY_G112*TY_G24 - TY_B25*TY_G18*TY_G24 - TY_B24*TY_G19*TY_G24 + 
-	2*TY_B12*TY_G211*TY_G24 - TY_B22*TY_G110*TY_G25 - TY_B21*TY_G111*TY_G25 - TY_B25*TY_G17*TY_G25 - TY_B24*TY_G18*TY_G25 - TY_B23*TY_G19*TY_G25 + 2*TY_B12*TY_G210*TY_G25 - TY_B21*TY_G110*TY_G26 - TY_B25*TY_G16*TY_G26 - 
-	TY_B24*TY_G17*TY_G26 - TY_B23*TY_G18*TY_G26 - TY_B22*TY_G19*TY_G26 - TY_B25*TY_G15*TY_G27 - TY_B24*TY_G16*TY_G27 - TY_B23*TY_G17*TY_G27 - TY_B22*TY_G18*TY_G27 - TY_B21*TY_G19*TY_G27 + 2*TY_B14*TY_G26*TY_G27 - 
-	TY_B25*TY_G14*TY_G28 - TY_B24*TY_G15*TY_G28 - TY_B23*TY_G16*TY_G28 - TY_B22*TY_G17*TY_G28 - TY_B21*TY_G18*TY_G28 + 2*TY_B14*TY_G25*TY_G28 + 2*TY_B12*TY_G27*TY_G28 - TY_B25*TY_G13*TY_G29 - TY_B24*TY_G14*TY_G29 - 
-	TY_B23*TY_G15*TY_G29 - TY_B22*TY_G16*TY_G29 - TY_B21*TY_G17*TY_G29 + 2*TY_B14*TY_G24*TY_G29 + 2*TY_B12*TY_G26*TY_G29;
-	
-	TY_w[10] = -(TY_B25*TY_G13*TY_G210) - TY_B24*TY_G14*TY_G210 - TY_B23*TY_G15*TY_G210 - TY_B22*TY_G16*TY_G210 - TY_B21*TY_G17*TY_G210 - TY_B24*TY_G13*TY_G211 - TY_B23*TY_G14*TY_G211 - TY_B22*TY_G15*TY_G211 - TY_B21*TY_G16*TY_G211 - 
-	TY_B23*TY_G13*TY_G212 - TY_B22*TY_G14*TY_G212 - TY_B21*TY_G15*TY_G212 - TY_B22*TY_G13*TY_G213 - TY_B21*TY_G14*TY_G213 - TY_B21*TY_G13*TY_G214 - TY_B25*TY_G111*TY_G22 - TY_B24*TY_G112*TY_G22 - TY_B23*TY_G113*TY_G22 + 
-	2*TY_B14*TY_G212*TY_G22 + 2*TY_B12*TY_G214*TY_G22 - TY_B25*TY_G110*TY_G23 - TY_B24*TY_G111*TY_G23 - TY_B23*TY_G112*TY_G23 - TY_B22*TY_G113*TY_G23 + 2*TY_B14*TY_G211*TY_G23 + 2*TY_B12*TY_G213*TY_G23 - 
-	TY_B24*TY_G110*TY_G24 - TY_B23*TY_G111*TY_G24 - TY_B22*TY_G112*TY_G24 - TY_B21*TY_G113*TY_G24 - TY_B25*TY_G19*TY_G24 + 2*TY_B14*TY_G210*TY_G24 + 2*TY_B12*TY_G212*TY_G24 - TY_B23*TY_G110*TY_G25 - 
-	TY_B22*TY_G111*TY_G25 - TY_B21*TY_G112*TY_G25 - TY_B25*TY_G18*TY_G25 - TY_B24*TY_G19*TY_G25 + 2*TY_B12*TY_G211*TY_G25 - TY_B22*TY_G110*TY_G26 - TY_B21*TY_G111*TY_G26 - TY_B25*TY_G17*TY_G26 - TY_B24*TY_G18*TY_G26 - 
-	TY_B23*TY_G19*TY_G26 + 2*TY_B12*TY_G210*TY_G26 - TY_B21*TY_G110*TY_G27 - TY_B25*TY_G16*TY_G27 - TY_B24*TY_G17*TY_G27 - TY_B23*TY_G18*TY_G27 - TY_B22*TY_G19*TY_G27 - TY_B25*TY_G15*TY_G28 - TY_B24*TY_G16*TY_G28 - 
-	TY_B23*TY_G17*TY_G28 - TY_B22*TY_G18*TY_G28 - TY_B21*TY_G19*TY_G28 + 2*TY_B14*TY_G26*TY_G28 - TY_B25*TY_G14*TY_G29 - TY_B24*TY_G15*TY_G29 - TY_B23*TY_G16*TY_G29 - TY_B22*TY_G17*TY_G29 - TY_B21*TY_G18*TY_G29 + 
-	2*TY_B14*TY_G25*TY_G29 + 2*TY_B12*TY_G27*TY_G29 + TY_B34*(2*(TY_G111*TY_G13 + TY_G110*TY_G14 + TY_G16*TY_G18 + TY_G15*TY_G19) + pow(TY_G17,2)) + 
-	TY_B32*(2*(TY_G113*TY_G13 + TY_G112*TY_G14 + TY_G111*TY_G15 + TY_G110*TY_G16 + TY_G17*TY_G19) + pow(TY_G18,2)) + TY_B14*pow(TY_G27,2) + TY_B12*pow(TY_G28,2);
-	
-	TY_w[11] = 2*TY_B34*(TY_G112*TY_G13 + TY_G111*TY_G14 + TY_G110*TY_G15 + TY_G17*TY_G18 + TY_G16*TY_G19) + 2*TY_B32*(TY_G113*TY_G14 + TY_G112*TY_G15 + TY_G111*TY_G16 + TY_G110*TY_G17 + TY_G18*TY_G19) - TY_B25*TY_G14*TY_G210 - 
-	TY_B24*TY_G15*TY_G210 - TY_B23*TY_G16*TY_G210 - TY_B22*TY_G17*TY_G210 - TY_B21*TY_G18*TY_G210 - TY_B25*TY_G13*TY_G211 - TY_B24*TY_G14*TY_G211 - TY_B23*TY_G15*TY_G211 - TY_B22*TY_G16*TY_G211 - TY_B21*TY_G17*TY_G211 - 
-	TY_B24*TY_G13*TY_G212 - TY_B23*TY_G14*TY_G212 - TY_B22*TY_G15*TY_G212 - TY_B21*TY_G16*TY_G212 - TY_B23*TY_G13*TY_G213 - TY_B22*TY_G14*TY_G213 - TY_B21*TY_G15*TY_G213 - TY_B25*TY_G112*TY_G22 - TY_B24*TY_G113*TY_G22 + 
-	2*TY_B14*TY_G213*TY_G22 - TY_B25*TY_G111*TY_G23 - TY_B24*TY_G112*TY_G23 - TY_B23*TY_G113*TY_G23 + 2*TY_B14*TY_G212*TY_G23 - TY_G214*(TY_B22*TY_G13 + TY_B21*TY_G14 - 2*TY_B12*TY_G23) - TY_B25*TY_G110*TY_G24 - 
-	TY_B24*TY_G111*TY_G24 - TY_B23*TY_G112*TY_G24 - TY_B22*TY_G113*TY_G24 + 2*TY_B14*TY_G211*TY_G24 + 2*TY_B12*TY_G213*TY_G24 - TY_B24*TY_G110*TY_G25 - TY_B23*TY_G111*TY_G25 - TY_B22*TY_G112*TY_G25 - 
-	TY_B21*TY_G113*TY_G25 - TY_B25*TY_G19*TY_G25 + 2*TY_B14*TY_G210*TY_G25 + 2*TY_B12*TY_G212*TY_G25 - TY_B23*TY_G110*TY_G26 - TY_B22*TY_G111*TY_G26 - TY_B21*TY_G112*TY_G26 - TY_B25*TY_G18*TY_G26 - TY_B24*TY_G19*TY_G26 + 
-	2*TY_B12*TY_G211*TY_G26 - TY_B22*TY_G110*TY_G27 - TY_B21*TY_G111*TY_G27 - TY_B25*TY_G17*TY_G27 - TY_B24*TY_G18*TY_G27 - TY_B23*TY_G19*TY_G27 + 2*TY_B12*TY_G210*TY_G27 - TY_B21*TY_G110*TY_G28 - TY_B25*TY_G16*TY_G28 - 
-	TY_B24*TY_G17*TY_G28 - TY_B23*TY_G18*TY_G28 - TY_B22*TY_G19*TY_G28 + 2*TY_B14*TY_G27*TY_G28 - TY_B25*TY_G15*TY_G29 - TY_B24*TY_G16*TY_G29 - TY_B23*TY_G17*TY_G29 - TY_B22*TY_G18*TY_G29 - TY_B21*TY_G19*TY_G29 + 
-	2*TY_B14*TY_G26*TY_G29 + 2*TY_B12*TY_G28*TY_G29;
-	
-	TY_w[12] = -(TY_B25*TY_G15*TY_G210) - TY_B24*TY_G16*TY_G210 - TY_B23*TY_G17*TY_G210 - TY_B22*TY_G18*TY_G210 - TY_B21*TY_G19*TY_G210 - TY_B25*TY_G14*TY_G211 - TY_B24*TY_G15*TY_G211 - TY_B23*TY_G16*TY_G211 - TY_B22*TY_G17*TY_G211 - 
-	TY_B21*TY_G18*TY_G211 - TY_B25*TY_G13*TY_G212 - TY_B24*TY_G14*TY_G212 - TY_B23*TY_G15*TY_G212 - TY_B22*TY_G16*TY_G212 - TY_B21*TY_G17*TY_G212 - TY_B24*TY_G13*TY_G213 - TY_B23*TY_G14*TY_G213 - TY_B22*TY_G15*TY_G213 - 
-	TY_B21*TY_G16*TY_G213 - TY_B25*TY_G113*TY_G22 - TY_B25*TY_G112*TY_G23 - TY_B24*TY_G113*TY_G23 + 2*TY_B14*TY_G213*TY_G23 - TY_B25*TY_G111*TY_G24 - TY_B24*TY_G112*TY_G24 - TY_B23*TY_G113*TY_G24 + 
-	2*TY_B14*TY_G212*TY_G24 - TY_G214*(TY_B23*TY_G13 + TY_B22*TY_G14 + TY_B21*TY_G15 - 2*TY_B14*TY_G22 - 2*TY_B12*TY_G24) - TY_B25*TY_G110*TY_G25 - TY_B24*TY_G111*TY_G25 - TY_B23*TY_G112*TY_G25 - 
-	TY_B22*TY_G113*TY_G25 + 2*TY_B14*TY_G211*TY_G25 + 2*TY_B12*TY_G213*TY_G25 - TY_B24*TY_G110*TY_G26 - TY_B23*TY_G111*TY_G26 - TY_B22*TY_G112*TY_G26 - TY_B21*TY_G113*TY_G26 - TY_B25*TY_G19*TY_G26 + 
-	2*TY_B14*TY_G210*TY_G26 + 2*TY_B12*TY_G212*TY_G26 - TY_B23*TY_G110*TY_G27 - TY_B22*TY_G111*TY_G27 - TY_B21*TY_G112*TY_G27 - TY_B25*TY_G18*TY_G27 - TY_B24*TY_G19*TY_G27 + 2*TY_B12*TY_G211*TY_G27 - 
-	TY_B22*TY_G110*TY_G28 - TY_B21*TY_G111*TY_G28 - TY_B25*TY_G17*TY_G28 - TY_B24*TY_G18*TY_G28 - TY_B23*TY_G19*TY_G28 + 2*TY_B12*TY_G210*TY_G28 - TY_B21*TY_G110*TY_G29 - TY_B25*TY_G16*TY_G29 - TY_B24*TY_G17*TY_G29 - 
-	TY_B23*TY_G18*TY_G29 - TY_B22*TY_G19*TY_G29 + 2*TY_B14*TY_G27*TY_G29 + TY_B34*(2*(TY_G113*TY_G13 + TY_G112*TY_G14 + TY_G111*TY_G15 + TY_G110*TY_G16 + TY_G17*TY_G19) + pow(TY_G18,2)) + 
-	TY_B32*(2*(TY_G113*TY_G15 + TY_G112*TY_G16 + TY_G111*TY_G17 + TY_G110*TY_G18) + pow(TY_G19,2)) + TY_B14*pow(TY_G28,2) + TY_B12*pow(TY_G29,2);
-	
-	TY_w[13] = 2*TY_B32*(TY_G113*TY_G16 + TY_G112*TY_G17 + TY_G111*TY_G18 + TY_G110*TY_G19) + 2*TY_B34*(TY_G113*TY_G14 + TY_G112*TY_G15 + TY_G111*TY_G16 + TY_G110*TY_G17 + TY_G18*TY_G19) - TY_B21*TY_G110*TY_G210 - 
-	TY_B25*TY_G16*TY_G210 - TY_B24*TY_G17*TY_G210 - TY_B23*TY_G18*TY_G210 - TY_B22*TY_G19*TY_G210 - TY_B25*TY_G15*TY_G211 - TY_B24*TY_G16*TY_G211 - TY_B23*TY_G17*TY_G211 - TY_B22*TY_G18*TY_G211 - TY_B21*TY_G19*TY_G211 - 
-	TY_B25*TY_G14*TY_G212 - TY_B24*TY_G15*TY_G212 - TY_B23*TY_G16*TY_G212 - TY_B22*TY_G17*TY_G212 - TY_B21*TY_G18*TY_G212 - TY_B25*TY_G13*TY_G213 - TY_B24*TY_G14*TY_G213 - TY_B23*TY_G15*TY_G213 - TY_B22*TY_G16*TY_G213 - 
-	TY_B21*TY_G17*TY_G213 - TY_B25*TY_G113*TY_G23 - TY_B25*TY_G112*TY_G24 - TY_B24*TY_G113*TY_G24 + 2*TY_B14*TY_G213*TY_G24 - TY_B25*TY_G111*TY_G25 - TY_B24*TY_G112*TY_G25 - TY_B23*TY_G113*TY_G25 + 
-	2*TY_B14*TY_G212*TY_G25 - TY_G214*(TY_B24*TY_G13 + TY_B23*TY_G14 + TY_B22*TY_G15 + TY_B21*TY_G16 - 2*TY_B14*TY_G23 - 2*TY_B12*TY_G25) - TY_B25*TY_G110*TY_G26 - TY_B24*TY_G111*TY_G26 - TY_B23*TY_G112*TY_G26 - 
-	TY_B22*TY_G113*TY_G26 + 2*TY_B14*TY_G211*TY_G26 + 2*TY_B12*TY_G213*TY_G26 - TY_B24*TY_G110*TY_G27 - TY_B23*TY_G111*TY_G27 - TY_B22*TY_G112*TY_G27 - TY_B21*TY_G113*TY_G27 - TY_B25*TY_G19*TY_G27 + 
-	2*TY_B14*TY_G210*TY_G27 + 2*TY_B12*TY_G212*TY_G27 - TY_B23*TY_G110*TY_G28 - TY_B22*TY_G111*TY_G28 - TY_B21*TY_G112*TY_G28 - TY_B25*TY_G18*TY_G28 - TY_B24*TY_G19*TY_G28 + 2*TY_B12*TY_G211*TY_G28 - 
-	TY_B22*TY_G110*TY_G29 - TY_B21*TY_G111*TY_G29 - TY_B25*TY_G17*TY_G29 - TY_B24*TY_G18*TY_G29 - TY_B23*TY_G19*TY_G29 + 2*TY_B12*TY_G210*TY_G29 + 2*TY_B14*TY_G28*TY_G29;
-	
-	TY_w[14] = -(TY_B22*TY_G110*TY_G210) - TY_B21*TY_G111*TY_G210 - TY_B25*TY_G17*TY_G210 - TY_B24*TY_G18*TY_G210 - TY_B23*TY_G19*TY_G210 - TY_B21*TY_G110*TY_G211 - TY_B25*TY_G16*TY_G211 - TY_B24*TY_G17*TY_G211 - 
-	TY_B23*TY_G18*TY_G211 - TY_B22*TY_G19*TY_G211 - TY_B25*TY_G15*TY_G212 - TY_B24*TY_G16*TY_G212 - TY_B23*TY_G17*TY_G212 - TY_B22*TY_G18*TY_G212 - TY_B21*TY_G19*TY_G212 - TY_B25*TY_G14*TY_G213 - TY_B24*TY_G15*TY_G213 - 
-	TY_B23*TY_G16*TY_G213 - TY_B22*TY_G17*TY_G213 - TY_B21*TY_G18*TY_G213 - TY_B25*TY_G113*TY_G24 - TY_B25*TY_G112*TY_G25 - TY_B24*TY_G113*TY_G25 + 2*TY_B14*TY_G213*TY_G25 - TY_B25*TY_G111*TY_G26 - TY_B24*TY_G112*TY_G26 - 
-	TY_B23*TY_G113*TY_G26 + 2*TY_B14*TY_G212*TY_G26 - TY_G214*(TY_B25*TY_G13 + TY_B24*TY_G14 + TY_B23*TY_G15 + TY_B22*TY_G16 + TY_B21*TY_G17 - 2*TY_B14*TY_G24 - 2*TY_B12*TY_G26) - TY_B25*TY_G110*TY_G27 - 
-	TY_B24*TY_G111*TY_G27 - TY_B23*TY_G112*TY_G27 - TY_B22*TY_G113*TY_G27 + 2*TY_B14*TY_G211*TY_G27 + 2*TY_B12*TY_G213*TY_G27 - TY_B24*TY_G110*TY_G28 - TY_B23*TY_G111*TY_G28 - TY_B22*TY_G112*TY_G28 - 
-	TY_B21*TY_G113*TY_G28 - TY_B25*TY_G19*TY_G28 + 2*TY_B14*TY_G210*TY_G28 + 2*TY_B12*TY_G212*TY_G28 - TY_B23*TY_G110*TY_G29 - TY_B22*TY_G111*TY_G29 - TY_B21*TY_G112*TY_G29 - TY_B25*TY_G18*TY_G29 - TY_B24*TY_G19*TY_G29 + 
-	2*TY_B12*TY_G211*TY_G29 + TY_B32*(2*(TY_G113*TY_G17 + TY_G112*TY_G18 + TY_G111*TY_G19) + pow(TY_G110,2)) + 
-	TY_B34*(2*(TY_G113*TY_G15 + TY_G112*TY_G16 + TY_G111*TY_G17 + TY_G110*TY_G18) + pow(TY_G19,2)) + TY_B12*pow(TY_G210,2) + TY_B14*pow(TY_G29,2); 
-	
-	TY_w[15] = 2*TY_B34*(TY_G113*TY_G16 + TY_G112*TY_G17 + TY_G111*TY_G18 + TY_G110*TY_G19) + 2*TY_B32*(TY_G110*TY_G111 + TY_G113*TY_G18 + TY_G112*TY_G19) - TY_B23*TY_G110*TY_G210 - TY_B22*TY_G111*TY_G210 - 
-	TY_B21*TY_G112*TY_G210 - TY_B25*TY_G18*TY_G210 - TY_B24*TY_G19*TY_G210 - TY_B22*TY_G110*TY_G211 - TY_B21*TY_G111*TY_G211 - TY_B25*TY_G17*TY_G211 - TY_B24*TY_G18*TY_G211 - TY_B23*TY_G19*TY_G211 + 
-	2*TY_B12*TY_G210*TY_G211 - TY_B21*TY_G110*TY_G212 - TY_B25*TY_G16*TY_G212 - TY_B24*TY_G17*TY_G212 - TY_B23*TY_G18*TY_G212 - TY_B22*TY_G19*TY_G212 - TY_B25*TY_G15*TY_G213 - TY_B24*TY_G16*TY_G213 - 
-	TY_B23*TY_G17*TY_G213 - TY_B22*TY_G18*TY_G213 - TY_B21*TY_G19*TY_G213 - TY_B25*TY_G113*TY_G25 - TY_B25*TY_G112*TY_G26 - TY_B24*TY_G113*TY_G26 + 2*TY_B14*TY_G213*TY_G26 - TY_B25*TY_G111*TY_G27 - TY_B24*TY_G112*TY_G27 - 
-	TY_B23*TY_G113*TY_G27 + 2*TY_B14*TY_G212*TY_G27 - TY_G214*(TY_B25*TY_G14 + TY_B24*TY_G15 + TY_B23*TY_G16 + TY_B22*TY_G17 + TY_B21*TY_G18 - 2*TY_B14*TY_G25 - 2*TY_B12*TY_G27) - TY_B25*TY_G110*TY_G28 - 
-	TY_B24*TY_G111*TY_G28 - TY_B23*TY_G112*TY_G28 - TY_B22*TY_G113*TY_G28 + 2*TY_B14*TY_G211*TY_G28 + 2*TY_B12*TY_G213*TY_G28 - TY_B24*TY_G110*TY_G29 - TY_B23*TY_G111*TY_G29 - TY_B22*TY_G112*TY_G29 - 
-	TY_B21*TY_G113*TY_G29 - TY_B25*TY_G19*TY_G29 + 2*TY_B14*TY_G210*TY_G29 + 2*TY_B12*TY_G212*TY_G29;
-	
-	TY_w[16] = -(TY_B24*TY_G110*TY_G210) - TY_B23*TY_G111*TY_G210 - TY_B22*TY_G112*TY_G210 - TY_B21*TY_G113*TY_G210 - TY_B25*TY_G19*TY_G210 - TY_B23*TY_G110*TY_G211 - TY_B22*TY_G111*TY_G211 - TY_B21*TY_G112*TY_G211 - 
-	TY_B25*TY_G18*TY_G211 - TY_B24*TY_G19*TY_G211 - TY_B22*TY_G110*TY_G212 - TY_B21*TY_G111*TY_G212 - TY_B25*TY_G17*TY_G212 - TY_B24*TY_G18*TY_G212 - TY_B23*TY_G19*TY_G212 + 2*TY_B12*TY_G210*TY_G212 - 
-	TY_B21*TY_G110*TY_G213 - TY_B25*TY_G16*TY_G213 - TY_B24*TY_G17*TY_G213 - TY_B23*TY_G18*TY_G213 - TY_B22*TY_G19*TY_G213 - TY_B25*TY_G113*TY_G26 - TY_B25*TY_G112*TY_G27 - TY_B24*TY_G113*TY_G27 + 
-	2*TY_B14*TY_G213*TY_G27 - TY_B25*TY_G111*TY_G28 - TY_B24*TY_G112*TY_G28 - TY_B23*TY_G113*TY_G28 + 2*TY_B14*TY_G212*TY_G28 - 
-	TY_G214*(TY_B25*TY_G15 + TY_B24*TY_G16 + TY_B23*TY_G17 + TY_B22*TY_G18 + TY_B21*TY_G19 - 2*TY_B14*TY_G26 - 2*TY_B12*TY_G28) - TY_B25*TY_G110*TY_G29 - TY_B24*TY_G111*TY_G29 - TY_B23*TY_G112*TY_G29 - 
-	TY_B22*TY_G113*TY_G29 + 2*TY_B14*TY_G211*TY_G29 + 2*TY_B12*TY_G213*TY_G29 + TY_B34*(2*(TY_G113*TY_G17 + TY_G112*TY_G18 + TY_G111*TY_G19) + pow(TY_G110,2)) + 
-	TY_B32*(2*TY_G110*TY_G112 + 2*TY_G113*TY_G19 + pow(TY_G111,2)) + TY_B14*pow(TY_G210,2) + TY_B12*pow(TY_G211,2);
-	
-	TY_w[17] = 2*TY_B32*(TY_G111*TY_G112 + TY_G110*TY_G113) + 2*TY_B34*(TY_G110*TY_G111 + TY_G113*TY_G18 + TY_G112*TY_G19) - TY_B25*TY_G110*TY_G210 - TY_B24*TY_G111*TY_G210 - TY_B23*TY_G112*TY_G210 - TY_B22*TY_G113*TY_G210 - 
-	TY_B24*TY_G110*TY_G211 - TY_B23*TY_G111*TY_G211 - TY_B22*TY_G112*TY_G211 - TY_B21*TY_G113*TY_G211 - TY_B25*TY_G19*TY_G211 + 2*TY_B14*TY_G210*TY_G211 - TY_B23*TY_G110*TY_G212 - TY_B22*TY_G111*TY_G212 - 
-	TY_B21*TY_G112*TY_G212 - TY_B25*TY_G18*TY_G212 - TY_B24*TY_G19*TY_G212 + 2*TY_B12*TY_G211*TY_G212 - TY_B22*TY_G110*TY_G213 - TY_B21*TY_G111*TY_G213 - TY_B25*TY_G17*TY_G213 - TY_B24*TY_G18*TY_G213 - 
-	TY_B23*TY_G19*TY_G213 + 2*TY_B12*TY_G210*TY_G213 - TY_B25*TY_G113*TY_G27 - TY_B25*TY_G112*TY_G28 - TY_B24*TY_G113*TY_G28 + 2*TY_B14*TY_G213*TY_G28 - TY_B25*TY_G111*TY_G29 - TY_B24*TY_G112*TY_G29 - 
-	TY_B23*TY_G113*TY_G29 + 2*TY_B14*TY_G212*TY_G29 - TY_G214*(TY_B21*TY_G110 + TY_B25*TY_G16 + TY_B24*TY_G17 + TY_B23*TY_G18 + TY_B22*TY_G19 - 2*TY_B14*TY_G27 - 2*TY_B12*TY_G29);
-	
-	TY_w[18] = -(TY_B25*TY_G111*TY_G210) - TY_B24*TY_G112*TY_G210 - TY_B23*TY_G113*TY_G210 - TY_B25*TY_G110*TY_G211 - TY_B24*TY_G111*TY_G211 - TY_B23*TY_G112*TY_G211 - TY_B22*TY_G113*TY_G211 - TY_B24*TY_G110*TY_G212 - 
-	TY_B23*TY_G111*TY_G212 - TY_B22*TY_G112*TY_G212 - TY_B21*TY_G113*TY_G212 - TY_B25*TY_G19*TY_G212 + 2*TY_B14*TY_G210*TY_G212 - TY_B23*TY_G110*TY_G213 - TY_B22*TY_G111*TY_G213 - TY_B21*TY_G112*TY_G213 - 
-	TY_B25*TY_G18*TY_G213 - TY_B24*TY_G19*TY_G213 + 2*TY_B12*TY_G211*TY_G213 - TY_B25*TY_G113*TY_G28 - 
-	TY_G214*(TY_B22*TY_G110 + TY_B21*TY_G111 + TY_B25*TY_G17 + TY_B24*TY_G18 + TY_B23*TY_G19 - 2*TY_B12*TY_G210 - 2*TY_B14*TY_G28) - TY_B25*TY_G112*TY_G29 - TY_B24*TY_G113*TY_G29 + 2*TY_B14*TY_G213*TY_G29 + 
-	TY_B34*(2*TY_G110*TY_G112 + 2*TY_G113*TY_G19 + pow(TY_G111,2)) + TY_B32*(2*TY_G111*TY_G113 + pow(TY_G112,2)) + TY_B14*pow(TY_G211,2) + TY_B12*pow(TY_G212,2);
-	
-	TY_w[19] = 2*TY_B32*TY_G112*TY_G113 + 2*TY_B34*(TY_G111*TY_G112 + TY_G110*TY_G113) - TY_B25*TY_G112*TY_G210 - TY_B24*TY_G113*TY_G210 - TY_B25*TY_G111*TY_G211 - TY_B24*TY_G112*TY_G211 - TY_B23*TY_G113*TY_G211 - 
-	TY_B25*TY_G110*TY_G212 - TY_B24*TY_G111*TY_G212 - TY_B23*TY_G112*TY_G212 - TY_B22*TY_G113*TY_G212 + 2*TY_B14*TY_G211*TY_G212 - TY_B24*TY_G110*TY_G213 - TY_B23*TY_G111*TY_G213 - TY_B22*TY_G112*TY_G213 - 
-	TY_B21*TY_G113*TY_G213 - TY_B25*TY_G19*TY_G213 + 2*TY_B14*TY_G210*TY_G213 + 2*TY_B12*TY_G212*TY_G213 - TY_B25*TY_G113*TY_G29 - 
-	TY_G214*(TY_B23*TY_G110 + TY_B22*TY_G111 + TY_B21*TY_G112 + TY_B25*TY_G18 + TY_B24*TY_G19 - 2*TY_B12*TY_G211 - 2*TY_B14*TY_G29);
-	
-	TY_w[20] = -(TY_B25*TY_G113*TY_G210) - TY_B25*TY_G112*TY_G211 - TY_B24*TY_G113*TY_G211 - TY_B25*TY_G111*TY_G212 - TY_B24*TY_G112*TY_G212 - TY_B23*TY_G113*TY_G212 - TY_B25*TY_G110*TY_G213 - TY_B24*TY_G111*TY_G213 - 
-	TY_B23*TY_G112*TY_G213 - TY_B22*TY_G113*TY_G213 + 2*TY_B14*TY_G211*TY_G213 - (TY_B24*TY_G110 + TY_B23*TY_G111 + TY_B22*TY_G112 + TY_B21*TY_G113 + TY_B25*TY_G19 - 2*TY_B14*TY_G210 - 2*TY_B12*TY_G212)*TY_G214 + 
-	TY_B34*(2*TY_G111*TY_G113 + pow(TY_G112,2)) + TY_B32*pow(TY_G113,2) + TY_B14*pow(TY_G212,2) + TY_B12*pow(TY_G213,2);
-	
-	TY_w[21] = TY_B25*(TY_A23*TY_B14*(-3*TY_A52*TY_B24*TY_B25 + (2*TY_A43*TY_B24 + TY_A42*TY_B25)*TY_B34) + TY_B25*(TY_A22*TY_B14*(-(TY_A52*TY_B25) + TY_A43*TY_B34) 
-																			 + TY_A12*(4*TY_A52*TY_B24*TY_B25 - (3*TY_A43*TY_B24 + TY_A42*TY_B25)*TY_B34)))*pow(TY_B34,3);
-	
-	TY_w[22] = (-(TY_A23*TY_B14) + TY_A12*TY_B25)*(TY_A52*TY_B25 - TY_A43*TY_B34)*pow(TY_B25,2)*pow(TY_B34,3);
-/*	
-	if( debug ) 
-	{
-		sprintf(buf,"\rCoefficients of polynomial\r");
-		XOPNotice(buf);
-		int i;
-		for ( i = 0; i < 23; i ++ ) {
-			sprintf(buf, "w[%d] = %f\r", i, TY_w[i] );
-			XOPNotice(buf);
-		}
-		sprintf(buf, "\r" );
-		XOPNotice(buf);
-	}
- */
-}
-
-double TY_Q( double d2 )
-{
-	return d2 * TY_B32 + pow( d2, 3 ) *  TY_B34;
-}
-
-double TY_V( double d2 )
-{
-	return	-( pow( d2, 2 ) * TY_G13 + pow( d2, 3 ) * TY_G14 + pow( d2, 4 ) * TY_G15 + pow( d2, 5 ) * TY_G16 + 
-			  pow( d2, 6 ) * TY_G17 + pow( d2, 7 ) *  TY_G18 + pow( d2, 8 ) * TY_G19 + pow( d2, 9 ) * TY_G110 + 
-			  pow( d2, 10 ) *  TY_G111 + pow( d2, 11 ) *  TY_G112 + pow( d2, 12 ) *  TY_G113 );
-}
-
-double TY_W( double d2 )
-{
-	return d2  * TY_G22 + pow( d2, 2 ) * TY_G23 + pow( d2, 3 ) * TY_G24 + pow( d2, 4 ) * TY_G25 + pow( d2, 5 ) * TY_G26 + 
-	pow( d2, 6 ) * TY_G27 + pow( d2, 7 ) *  TY_G28 + pow( d2, 8 ) *  TY_G29 + pow( d2, 9 ) * TY_G210 + 
-	pow( d2, 10 ) * TY_G211 + pow( d2, 11 ) * TY_G212 + pow( d2, 12 ) * TY_G213 + pow( d2, 13 ) * TY_G214;
-}
-
-double TY_X( double d2 )
-{
-	return TY_V( d2 ) / TY_W( d2 );
-}
-
-// solve the linear system depending on d1, d2 using Cramer's rule
-void TY_SolveLinearEquations( double d1, double d2, 
-						      double* a, double* b, double* c1, double* c2)
-{
-	double det    = TY_q22 * d1 * d2;
-	double det_a  = TY_qa12  * d2 + TY_qa21  * d1 + TY_qa22  * d1 * d2 + TY_qa23  * d1 * pow( d2, 2 ) + TY_qa32  * pow( d1, 2 ) * d2; 
-	double det_b  = TY_qb12  * d2 + TY_qb21  * d1 + TY_qb22  * d1 * d2 + TY_qb23  * d1 * pow( d2, 2 ) + TY_qb32  * pow( d1, 2 ) * d2; 
-	double det_c1 = TY_qc112 * d2 + TY_qc121 * d1 + TY_qc122 * d1 * d2 + TY_qc123 * d1 * pow( d2, 2 ) + TY_qc132 * pow( d1, 2 ) * d2; 
-	double det_c2 = TY_qc212 * d2 + TY_qc221 * d1 + TY_qc222 * d1 * d2 + TY_qc223 * d1 * pow( d2, 2 ) + TY_qc232 * pow( d1, 2 ) * d2;
-	
-	*a  = det_a  / det;
-	*b  = det_b  / det;
-	*c1 = det_c1 / det;
-	*c2 = det_c2 / det;
-}
-
-//Solve the system of linear and nonlinear equations for given Zi, Ki, phi which gives at 
-// most 22 solutions for the parameters a,b,ci,di. From the set of solutions choose the 
-// physical one and return it.
-int TY_SolveEquations( double Z1, double Z2, double K1, double K2, double phi, 
-					   double* a, double* b, double* c1, double* c2, double* d1, double* d2, 
-				       int debug )
-{
-	
-	// the two coupled non-linear eqautions were reduced to a
-	// 22nd order polynomial, the roots are give all possible solutions 
-	// for d2, than d1 can be computed by the function X 
-	char buf[256];
-	
- 	double real_coefficient[23];
-	double imag_coefficient[23];
-	
-	double real_root[22];
-	double imag_root[22];
-	
-	//integer degree of polynomial
-	int degree = 22;
-	int i;
-	double x,y;
-	double var_a, var_b, var_c1, var_c2, var_d1, var_d2;
-	double sol_a[22], sol_b[22], sol_c1[22], sol_c2[22], sol_d1[22], sol_d2[22];
-	
-	int j = 0;
-	
-	int n_roots,n,selected_root;
-	double dr,qmax,q,dq,min,sum;
-	double *sq,*gr;
-	double Pi = 3.14159265358979323846264338327950288;   /* pi */
-	
-	
-	// reduce system to a polynomial from which all solution are extracted
-	// by doing that a lot of global background variables are set
-	TY_ReduceNonlinearSystem( Z1, Z2, K1, K2, phi, debug );
-	
-	// vector of real and imaginary coefficients in order of decreasing powers
-	for ( i = 0; i <= degree; i++ )
-	{
-		// the global variablw TY_w was set by TY_ReduceNonlinearSystem
-		real_coefficient[i] = TY_w[ 22 - i ];
-		imag_coefficient[i] = 0.;
-	}
-	
-	// Jenkins-Traub method to approximate the roots of the polynomial
-	cpoly( real_coefficient, imag_coefficient, degree, real_root, imag_root );
-	
-	// show the result if in debug mode
-/*	
-	if ( debug )
-	{
-		for ( i = 0; i < degree; i++ )
-		{
-			x = real_root[i];
-			y = imag_root[i];
-			if ( chop( y ) == 0 )
-				sprintf(buf, "root(%d) = %g\r", i+1, x );
-			else
-				sprintf(buf, "root(%d) = %g + %g i\r", i+1, x, y );
-			XOPNotice(buf);
-		}
-		sprintf(buf, "\r" );
-		XOPNotice(buf);
-	}
- */
-	
-	// select real roots and those satisfying Q(x) != 0 and W(x) != 0
-	// Paper: Cluster formation in two-Yukawa Fluids, J. Chem. Phys. 122, 2005
-	// The right set of (a, b, c1, c2, d1, d2) should have the following properties:
-	// (1) a > 0 
-	// (2) d1, d2 are real
-	// (3) vi/Ki > 0 <=> g(Zi) > 0
-	// (4) if there is still more than root, calculate g(r) for each root
-	//     and g(r) of the correct root should have the minimum average value 
-	//	   inside the hardcore	
-
-	for ( i = 0; i < degree; i++ )
-	{
-		x = real_root[i];
-		y = imag_root[i];
-		
-		if ( chop( y ) == 0 && TY_W( x ) != 0 && TY_Q( x ) != 0 )
-		{
-			var_d1 = TY_X( x );
-			var_d2 = x;
-			
-			// solution of linear system for given d1, d2 to obtain a,b,ci,di
-			TY_SolveLinearEquations( var_d1, var_d2, &var_a, &var_b, &var_c1, &var_c2 );
-			
-			// select physical solutions, for details check paper: "Cluster formation in
-			// two-Yukawa fluids", J. Chem. Phys. 122 (2005)
-			if ( var_a > 0 && 
-				 TY_g( Z1, phi, Z1, Z2, var_a, var_b, var_c1, var_c2, var_d1, var_d2 ) > 0 &&
-	 			 TY_g( Z2, phi, Z1, Z2, var_a, var_b, var_c1, var_c2, var_d1, var_d2 ) > 0 )
-			{
-				sol_a[j]  = var_a;
-				sol_b[j]  = var_b;
-				sol_c1[j] = var_c1;
-				sol_c2[j] = var_c2;
-				sol_d1[j] = var_d1;
-				sol_d2[j] = var_d2;
-/*				
-				if ( debug )
-				{
-					double eq1 = chop( TY_LinearEquation_1( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					double eq2 = chop( TY_LinearEquation_2( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					double eq3 = chop( TY_LinearEquation_3( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					double eq4 = chop( TY_LinearEquation_4( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					double eq5 = chop( TY_NonlinearEquation_1( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					double eq6 = chop( TY_NonlinearEquation_2( Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] ) );
-					
-					sprintf(buf, "solution[%d] = (%g, %g, %g, %g, %g, %g), ( eq == 0 ) = (%g, %g, %g, %g, %g, %g)\r", j, 
-						   sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j], 
-						   eq1 , eq2, eq3, eq4, eq5, eq6 );
-					XOPNotice(buf);
-				}
- */
-				j++;
-			}
-		}
-	}
-	// number  remaining roots 
-	n_roots = j;
-	
-	
-	// if there is still more than one root left, than choose the one with the minimum
-	// average value inside the hardcore
-	if ( n_roots > 1 )
-	{
-		// the number of q values should be a power of 2
-		// in order to speed up the FFT
-		n = 1 << 14;
-		
-		// the maximum q value should be large enough 
-		// to enable a reasoble approximation of g(r)
-		qmax = 16 * 10 * 2 * Pi;
-		dq = qmax / ( n - 1 );
-		
-		// step size for g(r) = dr
-		
-		// allocate memory for pair correlation function g(r)
-		// and structure factor S(q)
-		sq = malloc( sizeof( double ) * n );
-		gr = malloc( sizeof( double ) * n );
-		
-		// loop over all remaining roots
-		min = 1e99;
-		selected_root = 10;	
-		sum = 0;
-		for ( j = 0; j < n_roots; j++) 
-		{
-			// calculate structure factor at different q values
-			for ( i = 0; i < n; i++) 
-			{
-				q = dq * i;
-				sq[i] = SqTwoYukawa( q, Z1, Z2, K1, K2, phi, sol_a[j], sol_b[j], sol_c1[j], sol_c2[j], sol_d1[j], sol_d2[j] );
-/*				
-				if(i<20 && debug) {
-					sprintf(buf, "after SqTwoYukawa: s(q) = %g\r",sq[i] );
-					XOPNotice(buf);	
-				}
- */
-			}
-			
-			// calculate pair correlation function for given
-			// structure factor, g(r) is computed at values
-			// r(i) = i * dr
-			PairCorrelation( phi, dq, sq, &dr, gr, n );
-			// determine sum inside the hardcore 
-			// 0 =< r < 1 of the pair-correlation function
-			sum = 0;
-			for (i = 0; i < floor( 1. / dr ); i++ )  {
-				sum += fabs( gr[i] );
-/*				
-				if(i<20 && debug) {
-					sprintf(buf, "g(r) in core = %g\r",fabs(gr[i]));
-					XOPNotice(buf);
-				}
-*/				
-			}
-
-			if ( sum < min )
-			{
-				min = sum;
-				selected_root = j;
-			}
-		}	
-		free( gr );
-		free( sq );
-		
-		// physical solution was found
-		*a  = sol_a [ selected_root ];//sol_a [ selected_root ];
-		*b  = sol_b [ selected_root ];
-		*c1 = sol_c1[ selected_root ];
-		*c2 = sol_c2[ selected_root ];
-		*d1 = sol_d1[ selected_root ];
-		*d2 = sol_d2[ selected_root ];
-		
-		return 1;
-	}
-	else if ( n_roots == 1 ) 
-	{
-		*a  = sol_a [0];
-		*b  = sol_b [0];
-		*c1 = sol_c1[0];
-		*c2 = sol_c2[0];
-		*d1 = sol_d1[0];
-		*d2 = sol_d2[0];
-		
-		return 1;
-	}
-
-	// no solution was found
-	return 0;
-}
Index: src/sas/models/c_extension/libigor/2Y_TwoYukawa.h
===================================================================
--- src/sas/models/c_extension/libigor/2Y_TwoYukawa.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,18 +1,0 @@
-/*
- *  TwoYukawa.h
- *  TwoYukawa
- *
- *  Created by Marcus Hennig on 5/8/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-int TY_SolveEquations( double Z1, double Z2, double K1, double K2, double phi, 
-				       double a[], double b[], double c1[], double c2[], double d1[], double d2[], 
-				       int debug );
-
-int TY_CheckSolution( double Z1, double Z2, double K1, double K2, double phi, 
-				      double a, double b, double c1, double c2, double d1, double d2 );
-
-double SqTwoYukawa( double q, 
-			        double Z1, double Z2, double K1, double K2, double phi,
-			        double a, double b, double c1, double c2, double d1, double d2 );
Index: src/sas/models/c_extension/libigor/2Y_cpoly.c
===================================================================
--- src/sas/models/c_extension/libigor/2Y_cpoly.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,660 +1,0 @@
-/*
- *******************************************************************************
- *
- *
- *                       Copyright (c) 2002
- *                       Henrik Vestermark
- *                       Denmark
- *
- *                       All Rights Reserved
- *
- *   This source file is subject to the terms and conditions of the
- *   Henrik Vestermark Software License Agreement which restricts the manner
- *   in which it may be used.
- *
- *******************************************************************************
- *
- *
- * Module name     :   cpoly.cpp
- * Module ID Nbr   :   
- * Description     :   cpoly.cpp -- Jenkins-Traub real polynomial root finder.
- *                     Translation of TOMS493 from FORTRAN to C. This
- *                     implementation of Jenkins-Traub partially adapts
- *                     the original code to a C environment by restruction
- *                     many of the 'goto' controls to better fit a block
- *                     structured form. It also eliminates the global memory
- *                     allocation in favor of local, dynamic memory management.
- *
- *                     The calling conventions are slightly modified to return
- *                     the number of roots found as the function value.
- *
- *                     INPUT:
- *                     opr - double precision vector of real coefficients in order of
- *                          decreasing powers.
- *                     opi - double precision vector of imaginary coefficients in order of
- *                          decreasing powers.
- *                     degree - integer degree of polynomial
- *
- *                     OUTPUT:
- *                     zeror,zeroi - output double precision vectors of the
- *                          real and imaginary parts of the zeros.
- *                            to be consistent with rpoly.cpp the zeros is inthe index
- *                            [0..max_degree-1]
- *
- *                     RETURN:
- *                     returnval:   -1 if leading coefficient is zero, otherwise
- *                          number of roots found. 
- * --------------------------------------------------------------------------
- * Change Record   :   
- *
- * Version	Author/Date		Description of changes
- * -------  -----------		----------------------
- * 01.01		HVE/021101		Initial release
- *
- * -- SRK changed name of *pi to *piw (and all occurances in this file) to avoid the conflict with pi in Apple's fp.h
- *
- * End of Change Record
- * --------------------------------------------------------------------------
- */
-
-
-/* define version string */
-
-#include <stdlib.h>
-#include <math.h>
-#include <float.h>
-
-static double sr, si, tr, ti, pvr, pvi, are, mre, eta, infin;
-static int nn;
-static double *pr, *piw, *hr, *hi, *qpr, *qpi, *qhr, *qhi, *shr, *shi; 
-
-static void noshft( const int l1 );
-static void fxshft( const int l2, double *zr, double *zi, int *conv );
-static void vrshft( const int l3, double *zr, double *zi, int *conv );
-static void calct( int *bol );
-static void nexth( const int bol );
-static void polyev( const int nn, const double sr, const double si, const double pr[], const double piw[], double qr[], double qi[], double *pvr, double *pvi );
-static double errev( const int nn, const double qr[], const double qi[], const double ms, const double mp, const double are, const double mre );
-static void cauchy( const int nn, double pt[], double q[], double *fn_val );
-static double scale( const int nn, const double pt[], const double eta, const double infin, const double smalno, const double base );
-static void cdivid( const double ar, const double ai, const double br, const double bi, double *cr, double *ci );
-static double cmod( const double r, const double i );
-static void mcon( double *eta, double *infiny, double *smalno, double *base );
-
-int cpoly( const double *opr, const double *opi, int degree, double *zeror, double *zeroi ) 
-{
-	int cnt1, cnt2, idnn2, i, conv;
-	double xx, yy, cosr, sinr, smalno, base, xxx, zr, zi, bnd;
-	
-	mcon( &eta, &infin, &smalno, &base );
-	are = eta;
-	mre = 2.0 * sqrt( 2.0 ) * eta;
-	xx = 0.70710678;
-	yy = -xx;
-	cosr = -0.060756474;
-	sinr = -0.99756405;
-	nn = degree;  
-	
-	// Algorithm fails if the leading coefficient is zero
-	if( opr[ 0 ] == 0 && opi[ 0 ] == 0 )
-		return -1;
-	
-	// Allocate arrays
-	pr = malloc( sizeof( double ) * ( degree + 1 ) );
-	piw = malloc( sizeof( double ) * ( degree + 1 ) );
-	hr =malloc( sizeof( double ) * ( degree + 1 ) );
-	hi = malloc( sizeof( double ) * ( degree + 1 ) );
-	qpr= malloc( sizeof( double ) * ( degree + 1 ) );
-	qpi= malloc( sizeof( double ) * ( degree + 1 ) );
-	qhr= malloc( sizeof( double ) * ( degree + 1 ) );
-	qhi= malloc( sizeof( double ) * ( degree + 1 ) );
-	shr= malloc( sizeof( double ) * ( degree + 1 ) );
-	shi= malloc( sizeof( double ) * ( degree + 1 ) );
-	
-	// Remove the zeros at the origin if any
-	while( opr[ nn ] == 0 && opi[ nn ] == 0 )
-	{
-		idnn2 = degree - nn;
-		zeror[ idnn2 ] = 0;
-		zeroi[ idnn2 ] = 0;
-		nn--;
-	}
-	
-	// Make a copy of the coefficients
-	for( i = 0; i <= nn; i++ )
-	{
-		pr[ i ] = opr[ i ];
-		piw[ i ] = opi[ i ];
-		shr[ i ] = cmod( pr[ i ], piw[ i ] );
-	}
-	
-	// Scale the polynomial
-	bnd = scale( nn, shr, eta, infin, smalno, base );
-	if( bnd != 1 )
-		for( i = 0; i <= nn; i++ )
-		{
-			pr[ i ] *= bnd;
-			piw[ i ] *= bnd;
-		}
-	
-search: 
-	if( nn <= 1 )
-	{
-		cdivid( -pr[ 1 ], -piw[ 1 ], pr[ 0 ], piw[ 0 ], &zeror[ degree-1 ], &zeroi[ degree-1 ] );
-		goto finish;
-	}
-	
-	// Calculate bnd, alower bound on the modulus of the zeros
-	for( i = 0; i<= nn; i++ )
-		shr[ i ] = cmod( pr[ i ], piw[ i ] );
-	
-	cauchy( nn, shr, shi, &bnd );
-	
-	// Outer loop to control 2 Major passes with different sequences of shifts
-	for( cnt1 = 1; cnt1 <= 2; cnt1++ )
-	{
-		// First stage  calculation , no shift
-		noshft( 5 );
-		
-		// Inner loop to select a shift
-		for( cnt2 = 1; cnt2 <= 9; cnt2++ )
-		{
-			// Shift is chosen with modulus bnd and amplitude rotated by 94 degree from the previous shif
-			xxx = cosr * xx - sinr * yy;
-			yy = sinr * xx + cosr * yy;
-			xx = xxx;
-			sr = bnd * xx;
-			si = bnd * yy;
-			
-			// Second stage calculation, fixed shift
-			fxshft( 10 * cnt2, &zr, &zi, &conv );
-			if( conv )
-            {
-				// The second stage jumps directly to the third stage ieration
-				// If successful the zero is stored and the polynomial deflated
-				idnn2 = degree - nn;
-				zeror[ idnn2 ] = zr;
-				zeroi[ idnn2 ] = zi;
-				nn--;
-				for( i = 0; i <= nn; i++ )
-				{
-					pr[ i ] = qpr[ i ];
-					piw[ i ] = qpi[ i ];
-				}
-				goto search;
-            }
-			// If the iteration is unsuccessful another shift is chosen
-		}
-		// if 9 shifts fail, the outer loop is repeated with another sequence of shifts
-	}
-	
-	// The zerofinder has failed on two major passes
-	// return empty handed with the number of roots found (less than the original degree)
-	degree -= nn;
-	
-finish:
-	// Deallocate arrays
-	free( pr );
-	free( piw );
-	free( hr );
-	free( hi );
-	free( qpr );
-	free( qpi );
-	free( qhr );
-	free( qhi );
-	free( shr );
-	free( shi );
-	
-	return degree;       
-}
-
-
-// COMPUTES  THE DERIVATIVE  POLYNOMIAL AS THE INITIAL H
-// POLYNOMIAL AND COMPUTES L1 NO-SHIFT H POLYNOMIALS.
-//
-static void noshft( const int l1 )
-{
-	int i, j, jj, n, nm1;
-	double xni, t1, t2;
-	
-	n = nn;
-	nm1 = n - 1;
-	for( i = 0; i < n; i++ )
-	{
-		xni = nn - i;
-		hr[ i ] = xni * pr[ i ] / n;
-		hi[ i ] = xni * piw[ i ] / n;
-	}
-	for( jj = 1; jj <= l1; jj++ )
-	{
-		if( cmod( hr[ n - 1 ], hi[ n - 1 ] ) > eta * 10 * cmod( pr[ n - 1 ], piw[ n - 1 ] ) )
-		{
-			cdivid( -pr[ nn ], -piw[ nn ], hr[ n - 1 ], hi[ n - 1 ], &tr, &ti );
-			for( i = 0; i < nm1; i++ )
-            {
-				j = nn - i - 1;
-				t1 = hr[ j - 1 ];
-				t2 = hi[ j - 1 ];
-				hr[ j ] = tr * t1 - ti * t2 + pr[ j ];
-				hi[ j ] = tr * t2 + ti * t1 + piw[ j ];
-            }
-			hr[ 0 ] = pr[ 0 ];
-			hi[ 0 ] = piw[ 0 ];
-		}
-		else
-		{
-			// If the constant term is essentially zero, shift H coefficients
-			for( i = 0; i < nm1; i++ )
-            {
-				j = nn - i - 1;
-				hr[ j ] = hr[ j - 1 ];
-				hi[ j ] = hi[ j - 1 ];
-            }
-			hr[ 0 ] = 0;
-			hi[ 0 ] = 0;
-		}
-	}
-}
-
-// COMPUTES L2 FIXED-SHIFT H POLYNOMIALS AND TESTS FOR CONVERGENCE.
-// INITIATES A VARIABLE-SHIFT ITERATION AND RETURNS WITH THE
-// APPROXIMATE ZERO IF SUCCESSFUL.
-// L2 - LIMIT OF FIXED SHIFT STEPS
-// ZR,ZI - APPROXIMATE ZERO IF CONV IS .TRUE.
-// CONV  - LOGICAL INDICATING CONVERGENCE OF STAGE 3 ITERATION
-//
-static void fxshft( const int l2, double *zr, double *zi, int *conv )
-{
-	int i, j, n;
-	int test, pasd, bol;
-	double otr, oti, svsr, svsi;
-	
-	n = nn;
-	polyev( nn, sr, si, pr, piw, qpr, qpi, &pvr, &pvi );
-	test = 1;
-	pasd = 0;
-	
-	// Calculate first T = -P(S)/H(S)
-	calct( &bol );
-	
-	// Main loop for second stage
-	for( j = 1; j <= l2; j++ )
-	{
-		otr = tr;
-		oti = ti;
-		
-		// Compute the next H Polynomial and new t
-		nexth( bol );
-		calct( &bol );
-		*zr = sr + tr;
-		*zi = si + ti;
-		
-		// Test for convergence unless stage 3 has failed once or this
-		// is the last H Polynomial
-		if( !( bol || !test || j == 12 ) )
-			if( cmod( tr - otr, ti - oti ) < 0.5 * cmod( *zr, *zi ) )
-            {
-				if( pasd )
-				{
-					// The weak convergence test has been passwed twice, start the third stage
-					// Iteration, after saving the current H polynomial and shift
-					for( i = 0; i < n; i++ )
-					{
-						shr[ i ] = hr[ i ];
-						shi[ i ] = hi[ i ];
-					}
-					svsr = sr;
-					svsi = si;
-					vrshft( 10, zr, zi, conv );
-					if( *conv ) return;
-					
-					//The iteration failed to converge. Turn off testing and restore h,s,pv and T
-					test = 0;
-					for( i = 0; i < n; i++ )
-					{
-						hr[ i ] = shr[ i ];
-						hi[ i ] = shi[ i ];
-					}
-					sr = svsr;
-					si = svsi;
-					polyev( nn, sr, si, pr, piw, qpr, qpi, &pvr, &pvi );
-					calct( &bol );
-					continue;
-				}
-				pasd = 1;
-            }
-			else
-				pasd = 0;
-	}
-	
-	// Attempt an iteration with final H polynomial from second stage
-	vrshft( 10, zr, zi, conv );
-}
-
-// CARRIES OUT THE THIRD STAGE ITERATION.
-// L3 - LIMIT OF STEPS IN STAGE 3.
-// ZR,ZI   - ON ENTRY CONTAINS THE INITIAL ITERATE, IF THE
-//           ITERATION CONVERGES IT CONTAINS THE FINAL ITERATE ON EXIT.
-// CONV    -  .TRUE. IF ITERATION CONVERGES
-//
-static void vrshft( const int l3, double *zr, double *zi, int *conv )
-{
-	int b, bol;
-	int i, j;
-	double mp, ms, omp, relstp, r1, r2, tp;
-	
-	*conv = 0;
-	b = 0;
-	sr = *zr;
-	si = *zi;
-	
-	// Main loop for stage three
-	for( i = 1; i <= l3; i++ )
-	{
-		// Evaluate P at S and test for convergence
-		polyev( nn, sr, si, pr, piw, qpr, qpi, &pvr, &pvi );
-		mp = cmod( pvr, pvi );
-		ms = cmod( sr, si );
-		if( mp <= 20 * errev( nn, qpr, qpi, ms, mp, are, mre ) )
-		{
-			// Polynomial value is smaller in value than a bound onthe error
-			// in evaluationg P, terminate the ietartion
-			*conv = 1;
-			*zr = sr;
-			*zi = si;
-			return;
-		}
-		if( i != 1 )
-		{
-			if( !( b || mp < omp || relstp >= 0.05 ) )
-            {
-				// Iteration has stalled. Probably a cluster of zeros. Do 5 fixed 
-				// shift steps into the cluster to force one zero to dominate
-				tp = relstp;
-				b = 1;
-				if( relstp < eta ) tp = eta;
-				r1 = sqrt( tp );
-				r2 = sr * ( 1 + r1 ) - si * r1;
-				si = sr * r1 + si * ( 1 + r1 );
-				sr = r2;
-				polyev( nn, sr, si, pr, piw, qpr, qpi, &pvr, &pvi );
-				for( j = 1; j <= 5; j++ )
-				{
-					calct( &bol );
-					nexth( bol );
-				}
-				omp = infin;
-				goto _20;
-            }
-			
-			// Exit if polynomial value increase significantly
-			if( mp *0.1 > omp ) return;
-		}
-		
-		omp = mp;
-		
-		// Calculate next iterate
-	_20:  calct( &bol );
-		nexth( bol );
-		calct( &bol );
-		if( !bol )
-		{
-			relstp = cmod( tr, ti ) / cmod( sr, si );
-			sr += tr;
-			si += ti;
-		}
-	}
-}
-
-// COMPUTES  T = -P(S)/H(S).
-// BOOL   - LOGICAL, SET TRUE IF H(S) IS ESSENTIALLY ZERO.
-static void calct( int *bol )
-{
-	int n;
-	double hvr, hvi;
-	
-	n = nn;
-	
-	// evaluate h(s)
-	polyev( n - 1, sr, si, hr, hi, qhr, qhi, &hvr, &hvi );
-	*bol = cmod( hvr, hvi ) <= are * 10 * cmod( hr[ n - 1 ], hi[ n - 1 ] ) ? 1 : 0;
-	if( !*bol )
-	{
-		cdivid( -pvr, -pvi, hvr, hvi, &tr, &ti );
-		return;
-	}
-	
-	tr = 0;
-	ti = 0;
-}
-
-// CALCULATES THE NEXT SHIFTED H POLYNOMIAL.
-// BOOL   -  LOGICAL, IF .TRUE. H(S) IS ESSENTIALLY ZERO
-//
-static void nexth( const int bol )
-{
-	int j, n;
-	double t1, t2;
-	
-	n = nn;
-	if( !bol )
-	{
-		for( j = 1; j < n; j++ )
-		{
-			t1 = qhr[ j - 1 ];
-			t2 = qhi[ j - 1 ];
-			hr[ j ] = tr * t1 - ti * t2 + qpr[ j ];
-			hi[ j ] = tr * t2 + ti * t1 + qpi[ j ];
-		}
-		hr[ 0 ] = qpr[ 0 ];
-		hi[ 0 ] = qpi[ 0 ];
-		return;
-	}
-	
-	// If h[s] is zero replace H with qh
-	for( j = 1; j < n; j++ )
-	{
-		hr[ j ] = qhr[ j - 1 ];
-		hi[ j ] = qhi[ j - 1 ];
-	}
-	hr[ 0 ] = 0;
-	hi[ 0 ] = 0;
-}
-
-// EVALUATES A POLYNOMIAL  P  AT  S  BY THE HORNER RECURRENCE
-// PLACING THE PARTIAL SUMS IN Q AND THE COMPUTED VALUE IN PV.
-//  
-static void polyev( const int nn, const double sr, const double si, const double pr[], const double piw[], double qr[], double qi[], double *pvr, double *pvi )  
-{
-	int i;
-	double t;
-	
-	qr[ 0 ] = pr[ 0 ];
-	qi[ 0 ] = piw[ 0 ];
-	*pvr = qr[ 0 ];
-	*pvi = qi[ 0 ];
-	
-	for( i = 1; i <= nn; i++ )
-	{
-		t = ( *pvr ) * sr - ( *pvi ) * si + pr[ i ];
-		*pvi = ( *pvr ) * si + ( *pvi ) * sr + piw[ i ];
-		*pvr = t;
-		qr[ i ] = *pvr;
-		qi[ i ] = *pvi;
-	}
-}
-
-// BOUNDS THE ERROR IN EVALUATING THE POLYNOMIAL BY THE HORNER RECURRENCE.
-// QR,QI - THE PARTIAL SUMS
-// MS    -MODULUS OF THE POINT
-// MP    -MODULUS OF POLYNOMIAL VALUE
-// ARE, MRE -ERROR BOUNDS ON COMPLEX ADDITION AND MULTIPLICATION
-//
-static double errev( const int nn, const double qr[], const double qi[], const double ms, const double mp, const double are, const double mre )
-{
-	int i;
-	double e;
-	
-	e = cmod( qr[ 0 ], qi[ 0 ] ) * mre / ( are + mre );
-	for( i = 0; i <= nn; i++ )
-		e = e * ms + cmod( qr[ i ], qi[ i ] );
-	
-	return e * ( are + mre ) - mp * mre;
-}
-
-// CAUCHY COMPUTES A LOWER BOUND ON THE MODULI OF THE ZEROS OF A
-// POLYNOMIAL - PT IS THE MODULUS OF THE COEFFICIENTS.
-//
-static void cauchy( const int nn, double pt[], double q[], double *fn_val )
-{
-	int i, n;
-	double x, xm, f, dx, df;
-	
-	pt[ nn ] = -pt[ nn ];
-	
-	// Compute upper estimate bound
-	n = nn;
-	x = exp( log( -pt[ nn ] ) - log( pt[ 0 ] ) ) / n;
-	if( pt[ n - 1 ] != 0 )
-	{
-		// Newton step at the origin is better, use it
-		xm = -pt[ nn ] / pt[ n - 1 ];
-		if( xm < x ) x = xm;
-	}
-	
-	// Chop the interval (0,x) until f < 0
-	while(1)
-	{
-		xm = x * 0.1;
-		f = pt[ 0 ];
-		for( i = 1; i <= nn; i++ )
-			f = f * xm + pt[ i ];
-		if( f <= 0 )
-			break;
-		x = xm;
-	}
-	dx = x;
-	
-	// Do Newton iteration until x converges to two decimal places
-	while( fabs( dx / x ) > 0.005 )
-	{
-		q[ 0 ] = pt[ 0 ];
-		for( i = 1; i <= nn; i++ )
-			q[ i ] = q[ i - 1 ] * x + pt[ i ];
-		f = q[ nn ];
-		df = q[ 0 ];
-		for( i = 1; i < n; i++ )
-			df = df * x + q[ i ];
-		dx = f / df;
-		x -= dx;
-	}
-	
-	*fn_val = x;
-}
-
-// RETURNS A SCALE FACTOR TO MULTIPLY THE COEFFICIENTS OF THE POLYNOMIAL.
-// THE SCALING IS DONE TO AVOID OVERFLOW AND TO AVOID UNDETECTED UNDERFLOW
-// INTERFERING WITH THE CONVERGENCE CRITERION.  THE FACTOR IS A POWER OF THE
-// BASE.
-// PT - MODULUS OF COEFFICIENTS OF P
-// ETA, INFIN, SMALNO, BASE - CONSTANTS DESCRIBING THE FLOATING POINT ARITHMETIC.
-//
-static double scale( const int nn, const double pt[], const double eta, const double infin, const double smalno, const double base )
-{
-	int i, l;
-	double hi, lo, max, min, x, sc;
-	double fn_val;
-	
-	// Find largest and smallest moduli of coefficients
-	hi = sqrt( infin );
-	lo = smalno / eta;
-	max = 0;
-	min = infin;
-	
-	for( i = 0; i <= nn; i++ )
-	{
-		x = pt[ i ];
-		if( x > max ) max = x;
-		if( x != 0 && x < min ) min = x;
-	}
-	
-	// Scale only if there are very large or very small components
-	fn_val = 1;
-	if( min >= lo && max <= hi ) return fn_val;
-	x = lo / min;
-	if( x <= 1 )
-		sc = 1 / ( sqrt( max )* sqrt( min ) );
-	else
-	{
-		sc = x;
-		if( infin / sc > max ) sc = 1;
-	}
-	l = (int)( log( sc ) / log(base ) + 0.5 );
-	fn_val = pow( base , l );
-	return fn_val;
-}
-
-// COMPLEX DIVISION C = A/B, AVOIDING OVERFLOW.
-//
-static void cdivid( const double ar, const double ai, const double br, const double bi, double *cr, double *ci )
-{
-	double r, d, t, infin;
-	
-	if( br == 0 && bi == 0 )
-	{
-		// Division by zero, c = infinity
-		mcon( &t, &infin, &t, &t );
-		*cr = infin;
-		*ci = infin;
-		return;
-	}
-	
-	if( fabs( br ) < fabs( bi ) )
-	{
-		r = br/ bi;
-		d = bi + r * br;
-		*cr = ( ar * r + ai ) / d;
-		*ci = ( ai * r - ar ) / d;
-		return;
-	}
-	
-	r = bi / br;
-	d = br + r * bi;
-	*cr = ( ar + ai * r ) / d;
-	*ci = ( ai - ar * r ) / d;
-}
-
-// MODULUS OF A COMPLEX NUMBER AVOIDING OVERFLOW.
-//
-static double cmod( const double r, const double i )
-{
-	double ar, ai;
-	
-	ar = fabs( r );
-	ai = fabs( i );
-	if( ar < ai )
-		return ai * sqrt( 1.0 + pow( ( ar / ai ), 2.0 ) );
-	
-	if( ar > ai )
-		return ar * sqrt( 1.0 + pow( ( ai / ar ), 2.0 ) );
-	
-	return ar * sqrt( 2.0 );
-}
-
-// MCON PROVIDES MACHINE CONSTANTS USED IN VARIOUS PARTS OF THE PROGRAM.
-// THE USER MAY EITHER SET THEM DIRECTLY OR USE THE STATEMENTS BELOW TO
-// COMPUTE THEM. THE MEANING OF THE FOUR CONSTANTS ARE -
-// ETA       THE MAXIMUM RELATIVE REPRESENTATION ERROR WHICH CAN BE DESCRIBED
-//           AS THE SMALLEST POSITIVE FLOATING-POINT NUMBER SUCH THAT
-//           1.0_dp + ETA &gt; 1.0.
-// INFINY    THE LARGEST FLOATING-POINT NUMBER
-// SMALNO    THE SMALLEST POSITIVE FLOATING-POINT NUMBER
-// BASE      THE BASE OF THE FLOATING-POINT NUMBER SYSTEM USED
-//
-static void mcon( double *eta, double *infiny, double *smalno, double *base )
-{
-	*base = 10;//DBL_RADIX;
-	*eta = DBL_EPSILON;
-	*infiny = DBL_MAX;
-	*smalno = DBL_MIN;
-}
Index: src/sas/models/c_extension/libigor/2Y_cpoly.h
===================================================================
--- src/sas/models/c_extension/libigor/2Y_cpoly.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,9 +1,0 @@
-/*
- *  cpoly.h
- *  TwoYukawa
- *
- *  Created by Marcus Hennig on 5/8/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-int cpoly( const double *opr, const double *opi, int degree, double *zeror, double *zeroi ); 
Index: src/sas/models/c_extension/libigor/2Y_utility.c
===================================================================
--- src/sas/models/c_extension/libigor/2Y_utility.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/*
- *  utility.c
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/13/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "2Y_utility.h"
-double chop( double x )
-{
-	if ( fabs(x) < 1E-6 )
-		return 0;
-	else 
-		return x;
-}
Index: src/sas/models/c_extension/libigor/2Y_utility.h
===================================================================
--- src/sas/models/c_extension/libigor/2Y_utility.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,11 +1,0 @@
-/*
- *  utility.h
- *  twoyukawa
- *
- *  Created by Marcus Hennig on 5/13/10.
- *  Copyright 2010 __MyCompanyName__. All rights reserved.
- *
- */
-#include <math.h>
-
-double chop( double x );
Index: src/sas/models/c_extension/libigor/GaussWeights.c
===================================================================
--- src/sas/models/c_extension/libigor/GaussWeights.c	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
+++ 	(revision )
@@ -1,520 +1,0 @@
-/*
- *  GaussWeights.c
- *  SASAnalysis
- *
- *  Created by Andrew Jackson on 4/23/07.
- *  Copyright 2007 __MyCompanyName__. All rights reserved.
- *
- */
-
-// Gaussians
-const double Gauss20Wt[20]={
-	.0176140071391521,
-	.0406014298003869,
-	.0626720483341091,
-	.0832767415767047,
-	.10193011981724,
-	.118194531961518,
-	.131688638449177,
-	.142096109318382,
-	.149172986472604,
-	.152753387130726,
-	.152753387130726,
-	.149172986472604,
-	.142096109318382,
-	.131688638449177,
-	.118194531961518,
-	.10193011981724,
-	.0832767415767047,
-	.0626720483341091,
-	.0406014298003869,
-	.0176140071391521
-};
-
-const double Gauss20Z[20]={
-	-.993128599185095,
-	-.963971927277914,
-	-.912234428251326,
-	-.839116971822219,
-	-.746331906460151,
-	-.636053680726515,
-	-.510867001950827,
-	-.37370608871542,
-	-.227785851141645,
-	-.076526521133497,
-	.0765265211334973,
-	.227785851141645,
-	.37370608871542,
-	.510867001950827,
-	.636053680726515,
-	.746331906460151,
-	.839116971822219,
-	.912234428251326,
-	.963971927277914,
-	.993128599185095
-};
-
-const double Gauss76Wt[76]={
-	.00126779163408536,		//0
-	.00294910295364247,
-	.00462793522803742,
-	.00629918049732845,
-	.00795984747723973,
-	.00960710541471375,
-	.0112381685696677,
-	.0128502838475101,
-	.0144407317482767,
-	.0160068299122486,
-	.0175459372914742,		//10
-	.0190554584671906,
-	.020532847967908,
-	.0219756145344162,
-	.0233813253070112,
-	.0247476099206597,
-	.026072164497986,
-	.0273527555318275,
-	.028587223650054,
-	.029773487255905,
-	.0309095460374916,		//20
-	.0319934843404216,
-	.0330234743977917,
-	.0339977794120564,
-	.0349147564835508,
-	.0357728593807139,
-	.0365706411473296,
-	.0373067565423816,
-	.0379799643084053,
-	.0385891292645067,
-	.0391332242205184,		//30
-	.0396113317090621,
-	.0400226455325968,
-	.040366472122844,
-	.0406422317102947,
-	.0408494593018285,
-	.040987805464794,
-	.0410570369162294,
-	.0410570369162294,
-	.040987805464794,
-	.0408494593018285,		//40
-	.0406422317102947,
-	.040366472122844,
-	.0400226455325968,
-	.0396113317090621,
-	.0391332242205184,
-	.0385891292645067,
-	.0379799643084053,
-	.0373067565423816,
-	.0365706411473296,
-	.0357728593807139,		//50
-	.0349147564835508,
-	.0339977794120564,
-	.0330234743977917,
-	.0319934843404216,
-	.0309095460374916,
-	.029773487255905,
-	.028587223650054,
-	.0273527555318275,
-	.026072164497986,
-	.0247476099206597,		//60
-	.0233813253070112,
-	.0219756145344162,
-	.020532847967908,
-	.0190554584671906,
-	.0175459372914742,
-	.0160068299122486,
-	.0144407317482767,
-	.0128502838475101,
-	.0112381685696677,
-	.00960710541471375,		//70
-	.00795984747723973,
-	.00629918049732845,
-	.00462793522803742,
-	.00294910295364247,
-	.00126779163408536		//75 (indexed from 0)
-};
-
-const double Gauss76Z[76]={
-	 .999505948362153*(-1.0),		//0
-	 .997397786355355*(-1.0),
-	 .993608772723527*(-1.0),
-	 .988144453359837*(-1.0),
-	 .981013938975656*(-1.0),
-	 .972229228520377*(-1.0),
-	 .961805126758768*(-1.0),
-	 .949759207710896*(-1.0),
-	 .936111781934811*(-1.0),
-	 .92088586125215*(-1.0),
-	 .904107119545567*(-1.0),		//10
-	 .885803849292083*(-1.0),
-	 .866006913771982*(-1.0),
-	 .844749694983342*(-1.0),
-	 .822068037328975*(-1.0),
-	 .7980001871612*(-1.0),
-	 .77258672828181*(-1.0),
-	 .74587051350361*(-1.0),
-	 .717896592387704*(-1.0),
-	 .688712135277641*(-1.0),
-	 .658366353758143*(-1.0),		//20
-	 .626910417672267*(-1.0),
-	 .594397368836793*(-1.0),
-	 .560882031601237*(-1.0),
-	 .526420920401243*(-1.0),
-	 .491072144462194*(-1.0),
-	 .454895309813726*(-1.0),
-	 .417951418780327*(-1.0),
-	 .380302767117504*(-1.0),
-	 .342012838966962*(-1.0),
-	 .303146199807908*(-1.0),		//30
-	 .263768387584994*(-1.0),
-	 .223945802196474*(-1.0),
-	 .183745593528914*(-1.0),
-	 .143235548227268*(-1.0),
-	 .102483975391227*(-1.0),
-	 .0615595913906112*(-1.0),
-	 .0205314039939986*(-1.0),
-	-.0205314039939986*(-1.0),
-	-.0615595913906112*(-1.0),
-	-.102483975391227*(-1.0),			//40
-	-.143235548227268*(-1.0),
-	-.183745593528914*(-1.0),
-	-.223945802196474*(-1.0),
-	-.263768387584994*(-1.0),
-	-.303146199807908*(-1.0),
-	-.342012838966962*(-1.0),
-	-.380302767117504*(-1.0),
-	-.417951418780327*(-1.0),
-	-.454895309813726*(-1.0),
-	-.491072144462194*(-1.0),		//50
-	-.526420920401243*(-1.0),
-	-.560882031601237*(-1.0),
-	-.594397368836793*(-1.0),
-	-.626910417672267*(-1.0),
-	-.658366353758143*(-1.0),
-	-.688712135277641*(-1.0),
-	-.717896592387704*(-1.0),
-	-.74587051350361*(-1.0),
-	-.77258672828181*(-1.0),
-	-.7980001871612*(-1.0),	//60
-	-.822068037328975*(-1.0),
-	-.844749694983342*(-1.0),
-	-.866006913771982*(-1.0),
-	-.885803849292083*(-1.0),
-	-.904107119545567*(-1.0),
-	-.92088586125215*(-1.0),
-	-.936111781934811*(-1.0),
-	-.949759207710896*(-1.0),
-	-.961805126758768*(-1.0),
-	-.972229228520377*(-1.0),		//70
-	-.981013938975656*(-1.0),
-	-.988144453359837*(-1.0),
-	-.993608772723527*(-1.0),
-	-.997397786355355*(-1.0),
-	-.999505948362153*(-1.0)		//75
-};
-
-const double Gauss150Z[150]={
-  	-0.9998723404457334,
-  	-0.9993274305065947,
-  	-0.9983473449340834,
-  	-0.9969322929775997,
-  	-0.9950828645255290,
-  	-0.9927998590434373,
-  	-0.9900842691660192,
-  	-0.9869372772712794,
-  	-0.9833602541697529,
-  	-0.9793547582425894,
-  	-0.9749225346595943,
-  	-0.9700655145738374,
-  	-0.9647858142586956,
-  	-0.9590857341746905,
-  	-0.9529677579610971,
-  	-0.9464345513503147,
-  	-0.9394889610042837,
-  	-0.9321340132728527,
-  	-0.9243729128743136,
-  	-0.9162090414984952,
-  	-0.9076459563329236,
-  	-0.8986873885126239,
-  	-0.8893372414942055,
-  	-0.8795995893549102,
-  	-0.8694786750173527,
-  	-0.8589789084007133,
-  	-0.8481048644991847,
-  	-0.8368612813885015,
-  	-0.8252530581614230,
-  	-0.8132852527930605,
-  	-0.8009630799369827,
-  	-0.7882919086530552,
-  	-0.7752772600680049,
-  	-0.7619248049697269,
-  	-0.7482403613363824,
-  	-0.7342298918013638,
-  	-0.7198995010552305,
-  	-0.7052554331857488,
-  	-0.6903040689571928,
-  	-0.6750519230300931,
-  	-0.6595056411226444,
-  	-0.6436719971150083,
-  	-0.6275578900977726,
-  	-0.6111703413658551,
-  	-0.5945164913591590,
-  	-0.5776035965513142,
-  	-0.5604390262878617,
-  	-0.5430302595752546,
-  	-0.5253848818220803,
-  	-0.5075105815339176,
-  	-0.4894151469632753,
-  	-0.4711064627160663,
-  	-0.4525925063160997,
-  	-0.4338813447290861,
-  	-0.4149811308476706,
-  	-0.3959000999390257,
-  	-0.3766465660565522,
-  	-0.3572289184172501,
-  	-0.3376556177463400,
-  	-0.3179351925907259,
-  	-0.2980762356029071,
-  	-0.2780873997969574,
-  	-0.2579773947782034,
-  	-0.2377549829482451,
-  	-0.2174289756869712,
-  	-0.1970082295132342,
-  	-0.1765016422258567,
-  	-0.1559181490266516,
-  	-0.1352667186271445,
-  	-0.1145563493406956,
-  	-0.0937960651617229,
-  	-0.0729949118337358,
-  	-0.0521619529078925,
-  	-0.0313062657937972,
-  	-0.0104369378042598,
-  	0.0104369378042598,
-  	0.0313062657937972,
-  	0.0521619529078925,
-  	0.0729949118337358,
-  	0.0937960651617229,
-  	0.1145563493406956,
-  	0.1352667186271445,
-  	0.1559181490266516,
-  	0.1765016422258567,
-  	0.1970082295132342,
-  	0.2174289756869712,
-  	0.2377549829482451,
-  	0.2579773947782034,
-  	0.2780873997969574,
-  	0.2980762356029071,
-  	0.3179351925907259,
-  	0.3376556177463400,
-  	0.3572289184172501,
-  	0.3766465660565522,
-  	0.3959000999390257,
-  	0.4149811308476706,
-  	0.4338813447290861,
-  	0.4525925063160997,
-  	0.4711064627160663,
-  	0.4894151469632753,
-  	0.5075105815339176,
-  	0.5253848818220803,
-  	0.5430302595752546,
-  	0.5604390262878617,
-  	0.5776035965513142,
-  	0.5945164913591590,
-  	0.6111703413658551,
-  	0.6275578900977726,
-  	0.6436719971150083,
-  	0.6595056411226444,
-  	0.6750519230300931,
-  	0.6903040689571928,
-  	0.7052554331857488,
-  	0.7198995010552305,
-  	0.7342298918013638,
-  	0.7482403613363824,
-  	0.7619248049697269,
-  	0.7752772600680049,
-  	0.7882919086530552,
-  	0.8009630799369827,
-  	0.8132852527930605,
-  	0.8252530581614230,
-  	0.8368612813885015,
-  	0.8481048644991847,
-  	0.8589789084007133,
-  	0.8694786750173527,
-  	0.8795995893549102,
-  	0.8893372414942055,
-  	0.8986873885126239,
-  	0.9076459563329236,
-  	0.9162090414984952,
-  	0.9243729128743136,
-  	0.9321340132728527,
-  	0.9394889610042837,
-  	0.9464345513503147,
-  	0.9529677579610971,
-  	0.9590857341746905,
-  	0.9647858142586956,
-  	0.9700655145738374,
-  	0.9749225346595943,
-  	0.9793547582425894,
-  	0.9833602541697529,
-  	0.9869372772712794,
-  	0.9900842691660192,
-  	0.9927998590434373,
-  	0.9950828645255290,
-  	0.9969322929775997,
-  	0.9983473449340834,
-  	0.9993274305065947,
-  	0.9998723404457334
-};
-
-const double Gauss150Wt[150]={
-  	0.0003276086705538,
-  	0.0007624720924706,
-  	0.0011976474864367,
-  	0.0016323569986067,
-  	0.0020663664924131,
-  	0.0024994789888943,
-  	0.0029315036836558,
-  	0.0033622516236779,
-  	0.0037915348363451,
-  	0.0042191661429919,
-  	0.0046449591497966,
-  	0.0050687282939456,
-  	0.0054902889094487,
-  	0.0059094573005900,
-  	0.0063260508184704,
-  	0.0067398879387430,
-  	0.0071507883396855,
-  	0.0075585729801782,
-  	0.0079630641773633,
-  	0.0083640856838475,
-  	0.0087614627643580,
-  	0.0091550222717888,
-  	0.0095445927225849,
-  	0.0099300043714212,
-  	0.0103110892851360,
-  	0.0106876814158841,
-  	0.0110596166734735,
-  	0.0114267329968529,
-  	0.0117888704247183,
-  	0.0121458711652067,
-  	0.0124975796646449,
-  	0.0128438426753249,
-  	0.0131845093222756,
-  	0.0135194311690004,
-  	0.0138484622795371,
-  	0.0141714592928592,
-  	0.0144882814685445,
-  	0.0147987907597169,
-  	0.0151028518701744,
-  	0.0154003323133401,
-  	0.0156911024699895,
-  	0.0159750356447283,
-  	0.0162520081211971,
-  	0.0165218992159766,
-  	0.0167845913311726,
-  	0.0170399700056559,
-  	0.0172879239649355,
-  	0.0175283451696437,
-  	0.0177611288626114,
-  	0.0179861736145128,
-  	0.0182033813680609,
-  	0.0184126574807331,
-  	0.0186139107660094,
-  	0.0188070535331042,
-  	0.0189920016251754,
-  	0.0191686744559934,
-  	0.0193369950450545,
-  	0.0194968900511231,
-  	0.0196482898041878,
-  	0.0197911283358190,
-  	0.0199253434079123,
-  	0.0200508765398072,
-  	0.0201676730337687,
-  	0.0202756819988200,
-  	0.0203748563729175,
-  	0.0204651529434560,
-  	0.0205465323660984,
-  	0.0206189591819181,
-  	0.0206824018328499,
-  	0.0207368326754401,
-  	0.0207822279928917,
-  	0.0208185680053983,
-  	0.0208458368787627,
-  	0.0208640227312962,
-  	0.0208731176389954,
-  	0.0208731176389954,
-  	0.0208640227312962,
-  	0.0208458368787627,
-  	0.0208185680053983,
-  	0.0207822279928917,
-  	0.0207368326754401,
-  	0.0206824018328499,
-  	0.0206189591819181,
-  	0.0205465323660984,
-  	0.0204651529434560,
-  	0.0203748563729175,
-  	0.0202756819988200,
-  	0.0201676730337687,
-  	0.0200508765398072,
-  	0.0199253434079123,
-  	0.0197911283358190,
-  	0.0196482898041878,
-  	0.0194968900511231,
-  	0.0193369950450545,
-  	0.0191686744559934,
-  	0.0189920016251754,
-  	0.0188070535331042,
-  	0.0186139107660094,
-  	0.0184126574807331,
-  	0.0182033813680609,
-  	0.0179861736145128,
-  	0.0177611288626114,
-  	0.0175283451696437,
-  	0.0172879239649355,
-  	0.0170399700056559,
-  	0.0167845913311726,
-  	0.0165218992159766,
-  	0.0162520081211971,
-  	0.0159750356447283,
-  	0.0156911024699895,
-  	0.0154003323133401,
-  	0.0151028518701744,
-  	0.0147987907597169,
-  	0.0144882814685445,
-  	0.0141714592928592,
-  	0.0138484622795371,
-  	0.0135194311690004,
-  	0.0131845093222756,
-  	0.0128438426753249,
-  	0.0124975796646449,
-  	0.0121458711652067,
-  	0.0117888704247183,
-  	0.0114267329968529,
-  	0.0110596166734735,
-  	0.0106876814158841,
-  	0.0103110892851360,
-  	0.0099300043714212,
-  	0.0095445927225849,
-  	0.0091550222717888,
-  	0.0087614627643580,
-  	0.0083640856838475,
-  	0.0079630641773633,
-  	0.0075585729801782,
-  	0.0071507883396855,
-  	0.0067398879387430,
-  	0.0063260508184704,
-  	0.0059094573005900,
-  	0.0054902889094487,
-  	0.0050687282939456,
-  	0.0046449591497966,
-  	0.0042191661429919,
-  	0.0037915348363451,
-  	0.0033622516236779,
-  	0.0029315036836558,
-  	0.0024994789888943,
-  	0.0020663664924131,
-  	0.0016323569986067,
-  	0.0011976474864367,
-  	0.0007624720924706,
-  	0.0003276086705538
-};
-
Index: src/sas/models/c_extension/libigor/GaussWeights.h
===================================================================
--- src/sas/models/c_extension/libigor/GaussWeights.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
+++ 	(revision )
@@ -1,24 +1,0 @@
-#ifndef GAUSSWEIGHTS_H
-#define GAUSSWEIGHTS_H
-/*
- *  GaussWeights.h
- *  SASAnalysis
- *
- *  Created by Andrew Jackson on 4/23/07.
- *  Copyright 2007 __MyCompanyName__. All rights reserved.
- *
- */
-
-// Gaussians
-extern const double Gauss20Wt[20];
-
-extern const double Gauss20Z[20];
-
-extern const double Gauss76Wt[76];
-
-extern const double Gauss76Z[76];
-
-extern const double Gauss150Z[150];
-
-extern const double Gauss150Wt[150];
-#endif
Index: src/sas/models/c_extension/libigor/libCylinder.c
===================================================================
--- src/sas/models/c_extension/libigor/libCylinder.c	(revision 8d302cdc162557c8a5f087402b860273c53602b7)
+++ 	(revision )
@@ -1,3616 +1,0 @@
-/*	CylinderFit.c
-
-A simplified project designed to act as a template for your curve fitting function.
-The fitting function is a Cylinder form factor. No resolution effects are included (yet)
-*/
-
-#include "StandardHeaders.h"			// Include ANSI headers, Mac headers
-#include "GaussWeights.h"
-#include "libCylinder.h"
-
-/////////functions for WRC implementation of flexible cylinders
-static double
-gammaln(double xx)
-{
-  double x,y,tmp,ser;
-  static double cof[6]={76.18009172947146,-86.50532032941677,
-    24.01409824083091,-1.231739572450155,
-    0.1208650973866179e-2,-0.5395239384953e-5};
-  int j;
-
-  y=x=xx;
-  tmp=x+5.5;
-  tmp -= (x+0.5)*log(tmp);
-  ser=1.000000000190015;
-  for (j=0;j<=5;j++) ser += cof[j]/++y;
-  return -tmp+log(2.5066282746310005*ser/x);
-}
-/////////functions for WRC implementation of flexible cylinders
-
-//
-static double
-AlphaSquare(double x)
-{
-    double yy;
-    yy = pow( (1.0 + (x/3.12)*(x/3.12) + (x/8.67)*(x/8.67)*(x/8.67)),(0.176/3.0) );
-
-    return (yy);
-}
-
-//
-static double
-Rgsquarezero(double q, double L, double b)
-{
-    double yy;
-    yy = (L*b/6.0) * (1.0 - 1.5*(b/L) + 1.5*pow((b/L),2) - 0.75*pow((b/L),3)*(1.0 - exp(-2.0*(L/b))));
-
-    return (yy);
-}
-
-//
-static double
-Rgsquareshort(double q, double L, double b)
-{
-    double yy;
-    yy = AlphaSquare(L/b) * Rgsquarezero(q,L,b);
-
-    return (yy);
-}
-
-//
-static double
-Rgsquare(double q, double L, double b)
-{
-    double yy;
-    yy = AlphaSquare(L/b)*L*b/6.0;
-
-    return (yy);
-}
-
-// ?? funciton is not used - but should the log actually be log10???
-/*
-static double
-miu(double x)
-{
-    double yy;
-    yy = (1.0/8.0)*(9.0*x - 2.0 + 2.0*log(1.0 + x)/x)*exp(1.0/2.565*(1.0/x + (1.0 - 1.0/(x*x))*log(1.0 + x)));
-
-    return (yy);
-}
-*/
-
-//WR named this w (too generic)
-static double
-w_WR(double x)
-{
-    double yy;
-    yy = 0.5*(1 + tanh((x - 1.523)/0.1477));
-
-    return (yy);
-}
-
-//
-static double
-u1(double q, double L, double b)
-{
-    double yy;
-
-    yy = Rgsquareshort(q,L,b)*q*q;
-
-    return (yy);
-}
-
-// was named u
-static double
-u_WR(double q, double L, double b)
-{
-    double yy;
-    yy = Rgsquare(q,L,b)*q*q;
-    return (yy);
-}
-
-
-//
-static double
-Sdebye1(double q, double L, double b)
-{
-    double yy;
-    yy = 2.0*(exp(-u1(q,L,b)) + u1(q,L,b) -1.0)/( pow((u1(q,L,b)),2.0) );
-
-    return (yy);
-}
-
-
-//
-static double
-Sdebye(double q, double L, double b)
-{
-    double yy;
-    yy = 2.0*(exp(-u_WR(q,L,b)) + u_WR(q,L,b) -1.0)/(pow((u_WR(q,L,b)),2));
-
-    return (yy);
-}
-
-//
-static double
-Sexv(double q, double L, double b)
-{
-    double yy,C1,C2,C3,miu,Rg2;
-    C1=1.22;
-    C2=0.4288;
-    C3=-1.651;
-    miu = 0.585;
-
-    Rg2 = Rgsquare(q,L,b);
-
-    yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) +  C2*pow((q*sqrt(Rg2)),(-2.0/miu)) +    C3*pow((q*sqrt(Rg2)),(-3.0/miu)));
-
-    return (yy);
-}
-
-// this must be WR modified version
-static double
-Sexvnew(double q, double L, double b)
-{
-    double yy,C1,C2,C3,miu;
-    double del=1.05,C_star2,Rg2;
-
-    C1=1.22;
-    C2=0.4288;
-    C3=-1.651;
-    miu = 0.585;
-
-    //calculating the derivative to decide on the corection (cutoff) term?
-    // I have modified this from WRs original code
-
-    if( (Sexv(q*del,L,b)-Sexv(q,L,b))/(q*del - q) >= 0.0 ) {
-        C_star2 = 0.0;
-    } else {
-        C_star2 = 1.0;
-    }
-
-    Rg2 = Rgsquare(q,L,b);
-
-  yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + C_star2*w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) + C2*pow((q*sqrt(Rg2)),(-2.0/miu)) + C3*pow((q*sqrt(Rg2)),(-3.0/miu)));
-
-    return (yy);
-}
-
-// these are the messy ones
-static double
-a2short(double q, double L, double b, double p1short, double p2short, double q0)
-{
-    double yy,Rg2_sh;
-    double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p;
-    double pi;
-
-    E = 2.718281828459045091;
-  pi = 4.0*atan(1.0);
-    Rg2_sh = Rgsquareshort(q,L,b);
-    Rg2_sh2 = Rg2_sh*Rg2_sh;
-    t1 = ((q0*q0*Rg2_sh)/(b*b));
-    Et1 = pow(E,t1);
-    Emt1 =pow(E,-t1);
-    q02 = q0*q0;
-    q0p = pow(q0,(-4.0 + p2short) );
-
-    //E is the number e
-    yy = ((-(1.0/(L*((p1short - p2short))*Rg2_sh2)*((b*Emt1*q0p*((8.0*b*b*b*L - 8.0*b*b*b*Et1*L - 2.0*b*b*b*L*p1short + 2.0*b*b*b*Et1*L*p1short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 2.0*b*Et1*L*p1short*q02*Rg2_sh - Et1*pi*q02*q0*Rg2_sh2 + Et1*p1short*pi*q02*q0*Rg2_sh2)))))));
-
-    return (yy);
-}
-
-//
-static double
-a1short(double q, double L, double b, double p1short, double p2short, double q0)
-{
-    double yy,Rg2_sh;
-    double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p,b3;
-  double pi;
-
-    E = 2.718281828459045091;
-  pi = 4.0*atan(1.0);
-    Rg2_sh = Rgsquareshort(q,L,b);
-    Rg2_sh2 = Rg2_sh*Rg2_sh;
-    b3 = b*b*b;
-    t1 = ((q0*q0*Rg2_sh)/(b*b));
-    Et1 = pow(E,t1);
-    Emt1 =pow(E,-t1);
-    q02 = q0*q0;
-    q0p = pow(q0,(-4.0 + p1short) );
-
-    yy = ((1.0/(L*((p1short - p2short))*Rg2_sh2)*((b*Emt1*q0p*((8.0*b3*L - 8.0*b3*Et1*L - 2.0*b3*L*p2short + 2.0*b3*Et1*L*p2short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 2.0*b*Et1*L*p2short*q02*Rg2_sh - Et1*pi*q02*q0*Rg2_sh2 + Et1*p2short*pi*q02*q0*Rg2_sh2))))));
-
-    return(yy);
-}
-
-
-//need to define this on my own
-static double
-sech_WR(double x)
-{
-  return(1/cosh(x));
-}
-
-// this one will be lots of trouble
-static double
-a2long(double q, double L, double b, double p1, double p2, double q0)
-{
-    double yy,C1,C2,C3,C4,C5,miu,C,Rg2;
-    double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,pi;
-    double E,b2,b3,b4,q02,q03,q04,q05,Rg22;
-
-    pi = 4.0*atan(1.0);
-    E = 2.718281828459045091;
-    if( L/b > 10.0) {
-        C = 3.06/pow((L/b),0.44);
-    } else {
-        C = 1.0;
-    }
-
-    C1 = 1.22;
-    C2 = 0.4288;
-    C3 = -1.651;
-    C4 = 1.523;
-    C5 = 0.1477;
-    miu = 0.585;
-
-    Rg2 = Rgsquare(q,L,b);
-    Rg22 = Rg2*Rg2;
-    b2 = b*b;
-    b3 = b*b*b;
-    b4 = b3*b;
-    q02 = q0*q0;
-    q03 = q0*q0*q0;
-    q04 = q03*q0;
-    q05 = q04*q0;
-
-    t1 = (1.0/(b* p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2)) ));
-
-    t2 = (b*C*(((-1.0*((14.0*b3)/(15.0*q03*Rg2))) + (14.0*b3*pow(E,(-((q02*Rg2)/b2))))/(15.0*q03*Rg2) + (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*((11.0/15.0 + (7*b2)/(15.0*q02*Rg2)))*Rg2)/b)))/L;
-
-    t3 = (sqrt(Rg2)*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2.0))/(2.0*C5);
-
-    t4 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2))/(C5*q04*Rg22);
-
-    t5 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22);
-
-    t6 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q05*Rg22);
-
-    t7 = (((-((3.0*C3*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 3.0/miu)))/miu)) - (2.0*C2*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 2.0/miu)))/miu - (C1*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 1.0/miu)))/miu));
-
-    t8 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));
-
-    t9 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15*q02*Rg2))) + (7.0*b2)/(15.0*q02*Rg2))))/L;
-
-    t10 = (2.0*b4*(((-1) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22);
-
-
-    yy = ((-1.0*(t1* ((-pow(q0,-p1)*(((b2*pi)/(L*q02) + t2 + t3 - t4 + t5 - t6 + 1.0/2.0*t7*t8)) - b*p1*pow(q0,((-1.0) - p1))*(((-((b*pi)/(L*q0))) + t9 + t10 + 1.0/2.0*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))))));
-
-    return (yy);
-}
-//
-static double
-a1long(double q, double L, double b, double p1, double p2, double q0)
-{
-    double yy,C,C1,C2,C3,C4,C5,miu,Rg2;
-    double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15;
-    double E,pi;
-    double b2,b3,b4,q02,q03,q04,q05,Rg22;
-
-    pi = 4.0*atan(1.0);
-    E = 2.718281828459045091;
-
-    if( L/b > 10.0) {
-        C = 3.06/pow((L/b),0.44);
-    } else {
-        C = 1.0;
-    }
-
-    C1 = 1.22;
-    C2 = 0.4288;
-    C3 = -1.651;
-    C4 = 1.523;
-    C5 = 0.1477;
-    miu = 0.585;
-
-    Rg2 = Rgsquare(q,L,b);
-    Rg22 = Rg2*Rg2;
-    b2 = b*b;
-    b3 = b*b*b;
-    b4 = b3*b;
-    q02 = q0*q0;
-    q03 = q0*q0*q0;
-    q04 = q03*q0;
-    q05 = q04*q0;
-
-    t1 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2))) + (7.0*b2)/(15.0*q02*Rg2))));
-
-    t2 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));
-
-    t3 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))));
-
-    t4 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));
-
-    t5 = (1.0/(b*p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2))));
-
-    t6 = (b*C*(((-((14.0*b3)/(15.0*q03*Rg2))) + (14.0*b3*pow(E,(-((q02*Rg2)/b2))))/(15.0*q03*Rg2) + (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2)))*Rg2)/b)));
-
-    t7 = (sqrt(Rg2)*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2));
-
-    t8 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2));
-
-    t9 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));
-
-    t10 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));
-
-    t11 = (((-((3.0*C3*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 3.0/miu)))/miu)) - (2.0*C2*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 2.0/miu)))/miu - (C1*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 1.0/miu)))/miu));
-
-    t12 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)));
-
-    t13 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02* Rg2))) + (7.0*b2)/(15.0*q02*Rg2))));
-
-    t14 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))));
-
-    t15 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))));
-
-
-    yy = (pow(q0,p1)*(((-((b*pi)/(L*q0))) +t1/L +t2/(q04*Rg22) + 1.0/2.0*t3*t4)) + (t5*((pow(q0,(p1 - p2))*(((-pow(q0,(-p1)))*(((b2*pi)/(L*q02) +t6/L +t7/(2.0*C5) -t8/(C5*q04*Rg22) +t9/(q04*Rg22) -t10/(q05*Rg22) + 1.0/2.0*t11*t12)) - b*p1*pow(q0,((-1.0) - p1))*(((-((b*pi)/(L*q0))) +t13/L +t14/(q04*Rg22) + 1.0/2.0*t15*((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))))))));
-
-    return (yy);
-}
-
-
-static double
-Sk_WR(double q, double L, double b)
-{
-  //
-  double p1,p2,p1short,p2short,q0;
-  double C,ans,q0short,Sexvmodify,pi;
-
-  pi = 4.0*atan(1.0);
-
-  p1 = 4.12;
-  p2 = 4.42;
-  p1short = 5.36;
-  p2short = 5.62;
-  q0 = 3.1;
-  //
-  q0short = fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0);
-
-  //
-  if(L/b > 10.0) {
-    C = 3.06/pow((L/b),0.44);
-  } else {
-    C = 1.0;
-  }
-  //
-
-  if( L > 4*b ) { // Longer Chains
-    if (q*b <= 3.1) {   //Modified by Yun on Oct. 15,
-      Sexvmodify = Sexvnew(q, L, b);
-      ans = Sexvmodify + C * (4.0/15.0 + 7.0/(15.0*u_WR(q,L,b)) - (11.0/15.0 + 7.0/(15.0*u_WR(q,L,b)))*exp(-u_WR(q,L,b)))*(b/L);
-    } else { //q(i)*b > 3.1
-      ans = a1long(q, L, b, p1, p2, q0)/(pow((q*b),p1)) + a2long(q, L, b, p1, p2, q0)/(pow((q*b),p2)) + pi/(q*L);
-    }
-  } else { //L <= 4*b Shorter Chains
-    if (q*b <= fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0) ) {
-      if (q*b<=0.01) {
-        ans = 1.0 - Rgsquareshort(q,L,b)*(q*q)/3.0;
-      } else {
-        ans = Sdebye1(q,L,b);
-      }
-    } else {  //q*b > max(1.9/sqrt(Rgsquareshort(q(i),L,b)),3)
-      ans = a1short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p1short)) + a2short(q,L,b,p1short,p2short,q0short)/(pow((q*b),p2short)) + pi/(q*L);
-    }
-  }
-
-  return(ans);
-  //return(a2long(q, L, b, p1, p2, q0));
-}
-
-/*	CylinderForm  :  calculates the form factor of a cylinder at the give x-value p->x
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-CylinderForm(double dp[], double q)
-{
-
-	int i;
-	double Pi;
-	double scale,radius,length,delrho,bkg,halfheight,sldCyl,sldSolv;		//local variables of coefficient wave
-	int nord=76;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,vcyl;			//running tally of integration
-	
-	Pi = 4.0*atan(1.0);
-	lolim = 0.0;
-	uplim = Pi/2.0;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	radius = dp[1];
-	length = dp[2];
-	sldCyl = dp[3];
-	sldSolv = dp[4];
-	bkg = dp[5];
-	
-	delrho = sldCyl-sldSolv;
-	halfheight = length/2.0;
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * CylKernel(q, radius, halfheight, zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by cylinder volume
-	//NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
-	vcyl=Pi*radius*radius*length;
-	answer *= vcyl;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	EllipCyl76X  :  calculates the form factor of a elliptical cylinder at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for both integrals
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-EllipCyl76(double dp[], double q)
-{
-	int i,j;
-	double Pi,slde,sld;
-	double scale,ra,nu,length,delrho,bkg;		//local variables of coefficient wave
-	int nord=76;			//order of integration
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer,vell;			//running tally of integration
-	double summj,vaj,vbj,zij,arg, si;			//for the inner integration
-
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//orintational average, outer integral
-	vaj=0.0;
-	vbj=Pi;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	ra = dp[1];
-	nu = dp[2];
-	length = dp[3];
-	slde = dp[4];
-	sld = dp[5];
-	delrho = slde - sld;
-	bkg = dp[6];
-	
-	for(i=0;i<nord;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "x" dummy
-		arg = ra*sqrt(1.0-zi*zi);
-		for(j=0;j<nord;j++) {
-			//76 gauss points for the inner integral as well
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "y" dummy
-			yyy = Gauss76Wt[j] * EllipCylKernel(q,arg,nu,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		//divide integral by Pi
-		answer /=Pi;
-		
-		//now calculate outer integral
-		arg = q*length*zi/2.0;
-		if (arg == 0.0){
-			si = 1.0;
-		}else{
-			si = sin(arg) * sin(arg) / arg / arg;
-		}
-		yyy = Gauss76Wt[i] * answer * si;
-		summ += yyy;
-	}
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by cylinder volume
-	//NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
-	vell = Pi*ra*(nu*ra)*length;
-	answer *= vell;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	EllipCyl20X  :  calculates the form factor of a elliptical cylinder at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for orientational integral
-Uses 20 pt quadrature for the inner integral over the elliptical cross-section
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-EllipCyl20(double dp[], double q)
-{
-	int i,j;
-	double Pi,slde,sld;
-	double scale,ra,nu,length,delrho,bkg;		//local variables of coefficient wave
-	int nordi=76;			//order of integration
-	int nordj=20;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer,vell;			//running tally of integration
-	double summj,vaj,vbj,zij,arg,si;			//for the inner integration
-
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//orintational average, outer integral
-	vaj=0.0;
-	vbj=Pi;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	ra = dp[1];
-	nu = dp[2];
-	length = dp[3];
-	slde = dp[4];
-	sld = dp[5];
-	delrho = slde - sld;
-	bkg = dp[6];
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "x" dummy
-		arg = ra*sqrt(1.0-zi*zi);
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss20Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "y" dummy
-			yyy = Gauss20Wt[j] * EllipCylKernel(q,arg,nu,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		//divide integral by Pi
-		answer /=Pi;
-		
-		//now calculate outer integral
-		arg = q*length*zi/2.0;
-		if (arg == 0.0){
-			si = 1.0;
-		}else{
-			si = sin(arg) * sin(arg) / arg / arg;
-		}
-		yyy = Gauss76Wt[i] * answer * si;
-		summ += yyy;
-	}
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by cylinder volume
-	//NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
-	vell = Pi*ra*(nu*ra)*length;
-	answer *= vell;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-
-	return answer;
-}
-
-/*	TriaxialEllipsoidX  :  calculates the form factor of a Triaxial Ellipsoid at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for both integrals
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-TriaxialEllipsoid(double dp[], double q)
-{
-	int i,j;
-	double Pi;
-	double scale,aa,bb,cc,delrho,bkg;		//local variables of coefficient wave
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij,slde,sld;			//for the inner integration
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = 1.0;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	aa = dp[1];
-	bb = dp[2];
-	cc = dp[3];
-	slde = dp[4];
-	sld = dp[5];
-	delrho = slde - sld;
-	bkg = dp[6];
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "x" dummy
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "y" dummy
-			yyy = Gauss76Wt[j] * TriaxialKernel(q,aa,bb,cc,zi,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		
-		//now calculate outer integral
-		yyy = Gauss76Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by ellipsoid volume
-	answer *= 4.0*Pi/3.0*aa*bb*cc;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	ParallelepipedX  :  calculates the form factor of a Parallelepiped (a rectangular solid)
-at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for both integrals
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-Parallelepiped(double dp[], double q)
-{
-	int i,j;
-	double scale,aa,bb,cc,delrho,bkg;		//local variables of coefficient wave
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj;			//for the inner integration
-	double mu,mudum,arg,sigma,uu,vol,sldp,sld;
-	
-	
-	//	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	aa = dp[1];
-	bb = dp[2];
-	cc = dp[3];
-	sldp = dp[4];
-	sld = dp[5];
-	delrho = sldp - sld;
-	bkg = dp[6];
-	
-	mu = q*bb;
-	vol = aa*bb*cc;
-	// normalize all WRT bb
-	aa = aa/bb;
-	cc = cc/bb;
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		sigma = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the outer dummy
-		
-		for(j=0;j<nordj;j++) {
-			//76 gauss points for the inner integral
-			uu = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the inner dummy
-			mudum = mu*sqrt(1.0-sigma*sigma);
-			yyy = Gauss76Wt[j] * PPKernel(aa,mudum,uu);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-
-		arg = mu*cc*sigma/2.0;
-		if ( arg == 0.0 ) {
-			answer *= 1.0;
-		} else {
-			answer *= sin(arg)*sin(arg)/arg/arg;
-		}
-		
-		//now sum up the outer integral
-		yyy = Gauss76Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by volume
-	answer *= vol;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	HollowCylinderX  :  calculates the form factor of a Hollow Cylinder
-at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for the single integral
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-HollowCylinder(double dp[], double q)
-{
-	int i;
-	double scale,rcore,rshell,length,delrho,bkg;		//local variables of coefficient wave
-	int nord=76;			//order of integration
-	double va,vb,zi;		//upper and lower integration limits
-	double summ,answer,pi,sldc,sld;			//running tally of integration
-	
-	pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//limits of numerical integral
-
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];		//make local copies in case memory moves
-	rcore = dp[1];
-	rshell = dp[2];
-	length = dp[3];
-	sldc = dp[4];
-	sld = dp[5];
-	delrho = sldc - sld;
-	bkg = dp[6];
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;
-		summ += Gauss76Wt[i] * HolCylKernel(q, rcore, rshell, length, zi);
-	}
- 	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by volume
-	answer *= pi*(rshell*rshell-rcore*rcore)*length;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	EllipsoidFormX  :  calculates the form factor of an ellipsoid of revolution with semiaxes a:a:nua
-at the given x-value p->x
-
-Uses 76 pt Gaussian quadrature for the single integral
-
-Warning:
-The call to WaveData() below returns a pointer to the middle
-of an unlocked Macintosh handle. In the unlikely event that your
-calculations could cause memory to move, you should copy the coefficient
-values to local variables or an array before such operations.
-*/
-double
-EllipsoidForm(double dp[], double q)
-{
-	int i;
-	double scale,a,nua,delrho,bkg;		//local variables of coefficient wave
-	int nord=76;			//order of integration
-	double va,vb,zi;		//upper and lower integration limits
-	double summ,answer,pi,slde,sld;			//running tally of integration
-	
-	pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//limits of numerical integral
-
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	nua = dp[1];
-	a = dp[2];
-	slde = dp[3];
-	sld = dp[4];
-	delrho = slde - sld;
-	bkg = dp[5];
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;
-		summ += Gauss76Wt[i] * EllipsoidKernel(q, a, nua, zi);
-	}
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= delrho*delrho;
-	//normalize by volume
-	answer *= 4.0*pi/3.0*a*a*nua;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-/*	Cyl_PolyRadiusX  :  calculates the form factor of a cylinder at the given x-value p->x
-the cylinder has a polydisperse cross section
-
-*/
-double
-Cyl_PolyRadius(double dp[], double q)
-{
-	int i;
-	double scale,radius,length,pd,delrho,bkg;		//local variables of coefficient wave
-	int nord=20;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,Vpoly;			//running tally of integration
-	double range,zz,Pi,sldc,sld;
-	
-	Pi = 4.0*atan(1.0);
-	range = 3.4;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	radius = dp[1];
-	length = dp[2];
-	pd = dp[3];
-	sldc = dp[4];
-	sld = dp[5];
-	delrho = sldc - sld;
-	bkg = dp[6];
-	
-	zz = (1.0/pd)*(1.0/pd) - 1.0;
-	
-	lolim = radius*(1.0-range*pd);		//set the upper/lower limits to cover the distribution
-	if(lolim<0.0) {
-		lolim = 0.0;
-	}
-	if(pd>0.3) {
-		range = 3.4 + (pd-0.3)*18.0;
-	}
-	uplim = radius*(1.0+range*pd);
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss20Wt[i] * Cyl_PolyRadKernel(q, radius, length, zz, delrho, zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	//normalize by average cylinder volume
-	//NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
-	Vpoly=Pi*radius*radius*length*(zz+2.0)/(zz+1.0);
-	answer /= Vpoly;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	Cyl_PolyLengthX  :  calculates the form factor of a cylinder at the given x-value p->x
-the cylinder has a polydisperse Length
-
-*/
-double
-Cyl_PolyLength(double dp[], double q)
-{
-	int i;
-	double scale,radius,length,pd,delrho,bkg;		//local variables of coefficient wave
-	int nord=20;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,Vpoly;			//running tally of integration
-	double range,zz,Pi,sldc,sld;
-	
-	
-	Pi = 4.0*atan(1.0);
-	range = 3.4;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	radius = dp[1];
-	length = dp[2];
-	pd = dp[3];
-	sldc = dp[4];
-	sld = dp[5];
-	delrho = sldc - sld;
-	bkg = dp[6];
-	
-	zz = (1.0/pd)*(1.0/pd) - 1.0;
-	
-	lolim = length*(1.0-range*pd);		//set the upper/lower limits to cover the distribution
-	if(lolim<0.0) {
-		lolim = 0.0;
-	}
-	if(pd>0.3) {
-		range = 3.4 + (pd-0.3)*18.0;
-	}
-	uplim = length*(1.0+range*pd);
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss20Wt[i] * Cyl_PolyLenKernel(q, radius, length, zz, delrho, zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	//normalize by average cylinder volume (first moment)
-	//NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
-	Vpoly=Pi*radius*radius*length;
-	answer /= Vpoly;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	CoreShellCylinderX  :  calculates the form factor of a cylinder at the given x-value p->x
-the cylinder has a core-shell structure
-
-*/
-double
-CoreShellCylinder(double dp[], double q)
-{
-	int i;
-	double scale,rcore,length,bkg;		//local variables of coefficient wave
-	double thick,rhoc,rhos,rhosolv;
-	int nord=76;			//order of integration
-	double uplim,lolim,halfheight;		//upper and lower integration limits
-	double summ,zi,yyy,answer,Vcyl;			//running tally of integration
-	double Pi;
-	
-	Pi = 4.0*atan(1.0);
-	
-	lolim = 0.0;
-	uplim = Pi/2.0;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];		//make local copies in case memory moves
-	rcore = dp[1];
-	thick = dp[2];
-	length = dp[3];
-	rhoc = dp[4];
-	rhos = dp[5];
-	rhosolv = dp[6];
-	bkg = dp[7];
-	
-	halfheight = length/2.0;
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * CoreShellCylKernel(q, rcore, thick, rhoc,rhos,rhosolv, halfheight, zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	// length is the total core length 
-	Vcyl=Pi*(rcore+thick)*(rcore+thick)*(length+2.0*thick);
-	answer /= Vcyl;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-/*	PolyCoShCylinderX  :  calculates the form factor of a core-shell cylinder at the given x-value p->x
-the cylinder has a polydisperse CORE radius
-
-*/
-double
-PolyCoShCylinder(double dp[], double q)
-{
-	int i;
-	double scale,radius,length,sigma,bkg;		//local variables of coefficient wave
-	double rad,radthick,facthick,rhoc,rhos,rhosolv;
-	int nord=20;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,yyy,answer,Vpoly;			//running tally of integration
-	double Pi,AR,Rsqrsumm,Rsqryyy,Rsqr;
-		
-	Pi = 4.0*atan(1.0);
-	
-	summ = 0.0;			//initialize intergral
-	Rsqrsumm = 0.0;
-	
-	scale = dp[0];
-	radius = dp[1];
-	sigma = dp[2];				//sigma is the standard mean deviation
-	length = dp[3];
-	radthick = dp[4];
-	facthick= dp[5];
-	rhoc = dp[6];
-	rhos = dp[7];
-	rhosolv = dp[8];
-	bkg = dp[9];
-	
-	lolim = exp(log(radius)-(4.*sigma));
-	if (lolim<0.0) {
-		lolim=0.0;		//to avoid numerical error when  va<0 (-ve r value)
-	}
-	uplim = exp(log(radius)+(4.*sigma));
-	
-	for(i=0;i<nord;i++) {
-		rad = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		AR=(1.0/(rad*sigma*sqrt(2.0*Pi)))*exp(-(0.5*((log(radius/rad))/sigma)*((log(radius/rad))/sigma)));
-		yyy = AR* Gauss20Wt[i] * CSCylIntegration(q,rad,radthick,facthick,rhoc,rhos,rhosolv,length);
-		Rsqryyy= Gauss20Wt[i] * AR * (rad+radthick)*(rad+radthick);		//SRK normalize to total dimensions
-		summ += yyy;
-		Rsqrsumm += Rsqryyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	Rsqr = (uplim-lolim)/2.0*Rsqrsumm;
-	//normalize by average cylinder volume
-	Vpoly = Pi*Rsqr*(length+2*facthick);
-	answer /= Vpoly;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	OblateFormX  :  calculates the form factor of a core-shell Oblate ellipsoid at the given x-value p->x
-the ellipsoid has a core-shell structure
-
-*/
-double
-OblateForm(double dp[], double q)
-{
-	int i;
-	double scale,crmaj,crmin,trmaj,trmin,delpc,delps,bkg;
-	int nord=76;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,oblatevol;			//running tally of integration
-	double Pi,sldc,slds,sld;
-	
-	Pi = 4.0*atan(1.0);
-	
-	lolim = 0.0;
-	uplim = 1.0;
-	
-	summ = 0.0;			//initialize intergral
-	
-	
-	scale = dp[0];		//make local copies in case memory moves
-	crmaj = dp[1];
-	crmin = dp[2];
-	trmaj = dp[3];
-	trmin = dp[4];
-	sldc = dp[5];
-	slds = dp[6];
-	sld = dp[7];
-	delpc = sldc - slds;	//core - shell
-	delps = slds - sld;		//shell - solvent
-	bkg = dp[8];
-
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * gfn4(zi,crmaj,crmin,trmaj,trmin,delpc,delps,q);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	// normalize by particle volume
-	oblatevol = 4.0*Pi/3.0*trmaj*trmaj*trmin;
-	answer /= oblatevol;
-	
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	ProlateFormX  :  calculates the form factor of a core-shell Prolate ellipsoid at the given x-value p->x
-the ellipsoid has a core-shell structure
-
-*/
-double
-ProlateForm(double dp[], double q)
-{
-	int i;
-	double scale,crmaj,crmin,trmaj,trmin,delpc,delps,bkg;
-	int nord=76;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,prolatevol;			//running tally of integration
-	double Pi,sldc,slds,sld;
-	
-	Pi = 4.0*atan(1.0);
-	
-	lolim = 0.0;
-	uplim = 1.0;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];		//make local copies in case memory moves
-	crmaj = dp[1];
-	crmin = dp[2];
-	trmaj = dp[3];
-	trmin = dp[4];
-	sldc = dp[5];
-	slds = dp[6];
-	sld = dp[7];
-	delpc = sldc - slds;		//core - shell
-	delps = slds - sld;		//shell  - sovent
-	bkg = dp[8];
-
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * gfn2(zi,crmaj,crmin,trmaj,trmin,delpc,delps,q);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	// normalize by particle volume
-	prolatevol = 4.0*Pi/3.0*trmaj*trmin*trmin;
-	answer /= prolatevol;
-	
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-/*	StackedDiscsX  :  calculates the form factor of a stacked "tactoid" of core shell disks
-like clay platelets that are not exfoliated
-
-*/
-double
-StackedDiscs(double dp[], double q)
-{
-	int i;
-	double scale,length,bkg,rcore,thick,rhoc,rhol,rhosolv,N,gsd;		//local variables of coefficient wave
-	double va,vb,vcyl,summ,yyy,zi,halfheight,d,answer;
-	int nord=76;			//order of integration
-	double Pi;
-	
-	
-	Pi = 4.0*atan(1.0);
-	
-	va = 0.0;
-	vb = Pi/2.0;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];
-	rcore = dp[1];
-	length = dp[2];
-	thick = dp[3];
-	rhoc = dp[4];
-	rhol = dp[5];
-	rhosolv = dp[6];
-	N = dp[7];
-	gsd = dp[8];
-	bkg = dp[9];
-	
-	d=2.0*thick+length;
-	halfheight = length/2.0;
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(vb-va) + vb + va )/2.0;
-		yyy = Gauss76Wt[i] * Stackdisc_kern(q, rcore, rhoc,rhol,rhosolv, halfheight,thick,zi,gsd,d,N);
-		summ += yyy;
-	}
-	
-	answer = (vb-va)/2.0*summ;
-	// length is the total core length 
-	vcyl=Pi*rcore*rcore*(2.0*thick+length)*N;
-	answer /= vcyl;
-	//Convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-/*	LamellarFFX  :  calculates the form factor of a lamellar structure - no S(q) effects included
-
-*/
-double
-LamellarFF(double dp[], double q)
-{
-	double scale,del,sig,contr,bkg;		//local variables of coefficient wave
-	double inten, qval,Pq;
-	double Pi,sldb,sld;
-	
-	
-	Pi = 4.0*atan(1.0);
-	scale = dp[0];
-	del = dp[1];
-	sig = dp[2]*del;
-	sldb = dp[3];
-	sld = dp[4];
-	contr = sldb - sld;
-	bkg = dp[5];
-	qval=q;
-	
-	Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)*exp(-0.5*qval*qval*sig*sig));
-	
-	inten = 2.0*Pi*scale*Pq/(qval*qval);		//this is now dimensionless...
-	
-	inten /= del;			//normalize by the thickness (in A)
-	
-	inten *= 1.0e8;		// 1/A to 1/cm
-	
-	return(inten+bkg);
-}
-
-/*	LamellarPSX  :  calculates the form factor of a lamellar structure - with S(q) effects included
---- now the proper resolution effects are used - the "default" resolution is turned off (= 0) and the
-model is smeared just like any other function
-*/
-double
-LamellarPS(double dp[], double q)
-{
-	double scale,dd,del,sig,contr,NN,Cp,bkg;		//local variables of coefficient wave
-	double inten,qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ;
-	double Pi,Euler,dQDefault,fii,sldb,sld;
-	int ii,NNint;
-//	char buf[256];
-
-	
-	Euler = 0.5772156649;		// Euler's constant
-//	dQDefault = 0.0025;		//[=] 1/A, q-resolution, default value
-	dQDefault = 0.0;
-	dQ = dQDefault;
-	
-	Pi = 4.0*atan(1.0);
-	qval = q;
-	
-	scale = dp[0];
-	dd = dp[1];
-	del = dp[2];
-	sig = dp[3]*del;
-	sldb = dp[4];
-	sld = dp[5];
-	contr = sldb - sld;
-	NN = trunc(dp[6]);		//be sure that NN is an integer
-	Cp = dp[7];
-	bkg = dp[8];
-	
-	Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)*exp(-0.5*qval*qval*sig*sig));
-	
-	NNint = (int)NN;		//cast to an integer for the loop
-	
-//	sprintf(buf, "qval = %g\r", qval);
-//	XOPNotice(buf);
-	
-	ii=0;
-	Sq = 0.0;
-	for(ii=1;ii<=(NNint-1);ii+=1) {
-        
-		fii = (double)ii;		//do I really need to do this?
-		
-		temp = 0.0;
-		alpha = Cp/4.0/Pi/Pi*(log(Pi*fii) + Euler);
-		t1 = 2.0*dQ*dQ*dd*dd*alpha;
-		t2 = 2.0*qval*qval*dd*dd*alpha;
-		t3 = dQ*dQ*dd*dd*fii*fii;
-		
-		temp = 1.0-fii/NN;
-		temp *= cos(dd*qval*fii/(1.0+t1));
-		temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
-		temp /= sqrt(1.0+t1);
-		
-		Sq += temp;
-	}
-	
-	Sq *= 2.0;
-	Sq += 1.0;
-	
-	inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval);
-	
-	inten *= 1.0e8;		// 1/A to 1/cm
-	
-    return(inten+bkg);
-}
-
-
-/*	LamellarPS_HGX  :  calculates the form factor of a lamellar structure - with S(q) effects included
---- now the proper resolution effects are used - the "default" resolution is turned off (= 0) and the
-model is smeared just like any other function
-*/
-double
-LamellarPS_HG(double dp[], double q)
-{
-	double scale,dd,delT,delH,SLD_T,SLD_H,SLD_S,NN,Cp,bkg;		//local variables of coefficient wave
-	double inten,qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ,drh,drt;
-	double Pi,Euler,dQDefault,fii;
-	int ii,NNint;
-	
-	
-	Euler = 0.5772156649;		// Euler's constant
-//	dQDefault = 0.0025;		//[=] 1/A, q-resolution, default value
-	dQDefault = 0.0;
-	dQ = dQDefault;
-	
-	Pi = 4.0*atan(1.0);
-	qval= q;
-	
-	scale = dp[0];
-	dd = dp[1];
-	delT = dp[2];
-	delH = dp[3];
-	SLD_T = dp[4];
-	SLD_H = dp[5];
-	SLD_S = dp[6];
-	NN = trunc(dp[7]);		//be sure that NN is an integer
-	Cp = dp[8];
-	bkg = dp[9];
-	
-	
-	drh = SLD_H - SLD_S;
-	drt = SLD_T - SLD_S;	//correction 13FEB06 by L.Porcar
-	
-	Pq = drh*(sin(qval*(delH+delT))-sin(qval*delT)) + drt*sin(qval*delT);
-	Pq *= Pq;
-	Pq *= 4.0/(qval*qval);
-	
-	NNint = (int)NN;		//cast to an integer for the loop
-	ii=0;
-	Sq = 0.0;
-	for(ii=1;ii<=(NNint-1);ii+=1) {
-        
-		fii = (double)ii;		//do I really need to do this?
-		
-		temp = 0.0;
-		alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler);
-		t1 = 2.0*dQ*dQ*dd*dd*alpha;
-		t2 = 2.0*qval*qval*dd*dd*alpha;
-		t3 = dQ*dQ*dd*dd*ii*ii;
-		
-		temp = 1.0-ii/NN;
-		temp *= cos(dd*qval*ii/(1.0+t1));
-		temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
-		temp /= sqrt(1.0+t1);
-		
-		Sq += temp;
-	}
-	
-	Sq *= 2.0;
-	Sq += 1.0;
-	
-	inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval);
-	
-	inten *= 1.0e8;		// 1/A to 1/cm
-	
-	return(inten+bkg);
-}
-
-/*	LamellarFF_HGX  :  calculates the form factor of a lamellar structure - no S(q) effects included
-but extra SLD for head groups is included
-
-*/
-double
-LamellarFF_HG(double dp[], double q)
-{
-	double scale,delT,delH,slds,sldh,sldt,bkg;		//local variables of coefficient wave
-	double inten, qval,Pq,drh,drt;
-	double Pi;
-	
-	
-	Pi = 4.0*atan(1.0);
-	qval= q;
-	scale = dp[0];
-	delT = dp[1];
-	delH = dp[2];
-	sldt = dp[3];
-	sldh = dp[4];
-	slds = dp[5];
-	bkg = dp[6];
-	
-	
-	drh = sldh - slds;
-	drt = sldt - slds;		//correction 13FEB06 by L.Porcar
-	
-	Pq = drh*(sin(qval*(delH+delT))-sin(qval*delT)) + drt*sin(qval*delT);
-	Pq *= Pq;
-	Pq *= 4.0/(qval*qval);
-	
-	inten = 2.0*Pi*scale*Pq/(qval*qval);		//dimensionless...
-	
-	inten /= 2.0*(delT+delH);			//normalize by the bilayer thickness
-	
-	inten *= 1.0e8;		// 1/A to 1/cm
-	
-	return(inten+bkg);
-}
-
-/*	FlexExclVolCylX  :  calculates the form factor of a flexible cylinder with a circular cross section
--- incorporates Wei-Ren Chen's fixes - 2006
-
-	*/
-double
-FlexExclVolCyl(double dp[], double q)
-{
-	double scale,L,B,bkg,rad,qr,cont,sldc,slds;
-	double Pi,flex,crossSect,answer;
-	
-	
-	Pi = 4.0*atan(1.0);
-	
-	scale = dp[0];		//make local copies in case memory moves
-	L = dp[1];
-	B = dp[2];
-	rad = dp[3];
-	sldc = dp[4];
-	slds = dp[5];
-	cont = sldc-slds;
-	bkg = dp[6];
-	
-    
-	qr = q*rad;
-	
-	flex = Sk_WR(q,L,B);
-	
-	crossSect = (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr);
-	flex *= crossSect;
-	flex *= Pi*rad*rad*L;
-	flex *= cont*cont;
-	flex *= 1.0e8;
-	answer = scale*flex + bkg;
-	
-	return answer;
-}
-
-/*	FlexCyl_EllipX  :  calculates the form factor of a flexible cylinder with an elliptical cross section
--- incorporates Wei-Ren Chen's fixes - 2006
-
-	*/
-double
-FlexCyl_Ellip(double dp[], double q)
-{
-	double scale,L,B,bkg,rad,qr,cont,ellRatio,slds,sldc;
-	double Pi,flex,crossSect,answer;
-	
-	
-	Pi = 4.0*atan(1.0);
-	scale = dp[0];		//make local copies in case memory moves
-	L = dp[1];
-	B = dp[2];
-	rad = dp[3];
-	ellRatio = dp[4];
-	sldc = dp[5];
-	slds = dp[6];
-	bkg = dp[7];
-	
-	cont = sldc - slds;
-	qr = q*rad;
-	
-	flex = Sk_WR(q,L,B);
-	
-	crossSect = EllipticalCross_fn(q,rad,(rad*ellRatio));
-	flex *= crossSect;
-	flex *= Pi*rad*rad*ellRatio*L;
-	flex *= cont*cont;
-	flex *= 1.0e8;
-	answer = scale*flex + bkg;
-	
-	return answer;
-}
-
-double
-EllipticalCross_fn(double qq, double a, double b)
-{
-    double uplim,lolim,Pi,summ,arg,zi,yyy,answer;
-    int i,nord=76;
-    
-    Pi = 4.0*atan(1.0);
-    lolim=0.0;
-    uplim=Pi/2.0;
-    summ=0.0;
-    
-    for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		arg = qq*sqrt(a*a*sin(zi)*sin(zi)+b*b*cos(zi)*cos(zi));
-		yyy = pow((2.0 * NR_BessJ1(arg) / arg),2);
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-    }
-    answer = (uplim-lolim)/2.0*summ;
-    answer *= 2.0/Pi;
-    return(answer);
-	
-}
-/*	FlexCyl_PolyLenX  :  calculates the form factor of a flecible cylinder at the given x-value p->x
-the cylinder has a polydisperse Length
-
-*/
-double
-FlexCyl_PolyLen(double dp[], double q)
-{
-	int i;
-	double scale,radius,length,pd,bkg,lb,delrho,sldc,slds;		//local variables of coefficient wave
-	int nord=20;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,Vpoly;			//running tally of integration
-	double range,zz,Pi;
-	
-	Pi = 4.0*atan(1.0);
-	range = 3.4;
-	
-	summ = 0.0;			//initialize intergral
-	scale = dp[0];			//make local copies in case memory moves
-	length = dp[1];			//radius
-	pd = dp[2];			// average length
-	lb = dp[3];
-	radius = dp[4];
-	sldc = dp[5];
-	slds = dp[6];
-	bkg = dp[7];
-	
-	delrho = sldc - slds;
-	zz = (1.0/pd)*(1.0/pd) - 1.0;
-	
-	lolim = length*(1.0-range*pd);		//set the upper/lower limits to cover the distribution
-	if(lolim<0.0) {
-		lolim = 0.0;
-	}
-	if(pd>0.3) {
-		range = 3.4 + (pd-0.3)*18.0;
-	}
-	uplim = length*(1.0+range*pd);
-	
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss20Wt[i] * FlePolyLen_kernel(q,radius,length,lb,zz,delrho,zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	//normalize by average cylinder volume (first moment), using the average length
-	Vpoly=Pi*radius*radius*length;
-	answer /= Vpoly;
-	
-	answer *=delrho*delrho;
-	
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-/*	FlexCyl_PolyLenX  :  calculates the form factor of a flexible cylinder at the given x-value p->x
-the cylinder has a polydisperse cross sectional radius
-
-*/
-double
-FlexCyl_PolyRad(double dp[], double q)
-{
-	int i;
-	double scale,radius,length,pd,delrho,bkg,lb,sldc,slds;		//local variables of coefficient wave
-	int nord=76;			//order of integration
-	double uplim,lolim;		//upper and lower integration limits
-	double summ,zi,yyy,answer,Vpoly;			//running tally of integration
-	double range,zz,Pi;
-	
-	
-	Pi = 4.0*atan(1.0);
-	range = 3.4;
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];			//make local copies in case memory moves
-	length = dp[1];			//radius
-	lb = dp[2];			// average length
-	radius = dp[3];
-	pd = dp[4];
-	sldc = dp[5];
-	slds = dp[6];
-	bkg = dp[7];
-	
-	delrho = sldc-slds;
-	zz = (1.0/pd)*(1.0/pd) - 1.0;
-	
-	lolim = radius*(1.0-range*pd);		//set the upper/lower limits to cover the distribution
-	if(lolim<0.0) {
-		lolim = 0.0;
-	}
-	if(pd>0.3) {
-		range = 3.4 + (pd-0.3)*18.0;
-	}
-	uplim = radius*(1.0+range*pd);
-	
-	for(i=0;i<nord;i++) {
-		//zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		//yyy = Gauss20Wt[i] * FlePolyRad_kernel(q,radius,length,lb,zz,delrho,zi);
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * FlePolyRad_kernel(q,radius,length,lb,zz,delrho,zi);
-		summ += yyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	//normalize by average cylinder volume (second moment), using the average radius
-	Vpoly = Pi*radius*radius*length*(zz+2.0)/(zz+1.0);
-	answer /= Vpoly;
-	
-	answer *=delrho*delrho;
-	
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-
-///////////////
-
-//
-//     FUNCTION gfn2:    CONTAINS F(Q,A,B,mu)**2  AS GIVEN
-//                       BY (53) AND (56,57) IN CHEN AND 
-//                       KOTLARCHYK REFERENCE
-//
-//     <PROLATE ELLIPSOIDS>
-//
-double
-gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq)
-{
-	// local variables
-	double aa,bb,u2,ut2,uq,ut,vc,vt,siq,sit,gfnc,gfnt,gfn2,pi43,gfn,Pi;
-
-	Pi = 4.0*atan(1.0);
-	
-	pi43=4.0/3.0*Pi;
-	aa = crmaj;
-	bb = crmin;
-	u2 = (aa*aa*xx*xx + bb*bb*(1.0-xx*xx));
-	ut2 = (trmaj*trmaj*xx*xx + trmin*trmin*(1.0-xx*xx));
-	uq = sqrt(u2)*qq;
-	ut= sqrt(ut2)*qq;
-	vc = pi43*aa*bb*bb;
-	vt = pi43*trmaj*trmin*trmin;
-   	if (uq == 0.0){
-   		siq = 1.0/3.0;
-   	}else{
-   		siq = (sin(uq)/uq/uq - cos(uq)/uq)/uq;
-   	}
-   	if (ut == 0.0){
-   		sit = 1.0/3.0;
-   	}else{
-   		sit = (sin(ut)/ut/ut - cos(ut)/ut)/ut;
-   	}
-	gfnc = 3.0*siq*vc*delpc;
-	gfnt = 3.0*sit*vt*delps;
-	gfn = gfnc+gfnt;
-	gfn2 = gfn*gfn;
-	
-	return (gfn2);
-}
-
-//
-//     FUNCTION gfn4:    CONTAINS F(Q,A,B,MU)**2  AS GIVEN
-//                       BY (53) & (58-59) IN CHEN AND
-//                       KOTLARCHYK REFERENCE
-//
-//       <OBLATE ELLIPSOID>
-// function gfn4 for oblate ellipsoids 
-double
-gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq)
-{
-	// local variables
-	double aa,bb,u2,ut2,uq,ut,vc,vt,siq,sit,gfnc,gfnt,tgfn,gfn4,pi43,Pi;
-
-	Pi = 4.0*atan(1.0);
-	pi43=4.0/3.0*Pi;
-  	aa = crmaj;
- 	bb = crmin;
- 	u2 = (bb*bb*xx*xx + aa*aa*(1.0-xx*xx));
- 	ut2 = (trmin*trmin*xx*xx + trmaj*trmaj*(1.0-xx*xx));
-   	uq = sqrt(u2)*qq;
- 	ut= sqrt(ut2)*qq;
-	vc = pi43*aa*aa*bb;
-   	vt = pi43*trmaj*trmaj*trmin;
-   	if (uq == 0.0){
-   		siq = 1.0/3.0;
-   	}else{
-   		siq = (sin(uq)/uq/uq - cos(uq)/uq)/uq;
-   	}
-   	if (ut == 0.0){
-   		sit = 1.0/3.0;
-   	}else{
-   		sit = (sin(ut)/ut/ut - cos(ut)/ut)/ut;
-   	}
-   	gfnc = 3.0*siq*vc*delpc;
-  	gfnt = 3.0*sit*vt*delps;
-  	tgfn = gfnc+gfnt;
-  	gfn4 = tgfn*tgfn;
-  	
-  	return (gfn4);
-}
-
-double
-FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi)
-{
-    double Pq,vcyl,dl;
-    double Pi,qr;
-    
-    Pi = 4.0*atan(1.0);
-    qr = q*radius;
-    
-    Pq = Sk_WR(q,zi,lb);		//does not have cross section term
-    if (qr !=0){
-    	Pq *= (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr);
-    } 
-    vcyl=Pi*radius*radius*zi;
-    Pq *= vcyl*vcyl;
-    
-    dl = SchulzPoint_cpr(zi,length,zz);
-    return (Pq*dl);	
-	
-}
-
-double
-FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi)
-{
-    double Pq,vcyl,dr;
-    double Pi,qr;
-    
-    Pi = 4.0*atan(1.0);
-    qr = q*zi;
-    
-    Pq = Sk_WR(q,Lc,Lb);		//does not have cross section term
-    if (qr !=0){
-    	Pq *= (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr);
-    }
-
-    vcyl=Pi*zi*zi*Lc;
-    Pq *= vcyl*vcyl;
-    
-    dr = SchulzPoint_cpr(zi,ravg,zz);
-    return (Pq*dr);	
-	
-}
-
-double
-CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length)
-{
-	double answer,halfheight,Pi;
-	double lolim,uplim,summ,yyy,zi;
-	int nord,i;
-	
-	// set up the integration end points 
-	Pi = 4.0*atan(1.0);
-	nord = 76;
-	lolim = 0.0;
-	uplim = Pi/2.0;
-	halfheight = length/2.0;
-	
-	summ = 0.0;				// initialize integral
-	i=0;
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * CScyl(qq, rad, radthick, facthick, rhoc,rhos,rhosolv, halfheight, zi);
-		summ += yyy;
-	}
-	
-	// calculate value of integral to return
-	answer = (uplim-lolim)/2.0*summ;
-	return (answer);
-}
-
-double
-CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum)
-{	
-	// qq is the q-value for the calculation (1/A)
-	// radius is the core radius of the cylinder (A)
-	//  radthick and facthick are the radial and face layer thicknesses
-	// rho(n) are the respective SLD's
-	// length is the *Half* CORE-LENGTH of the cylinder 
-	// dum is the dummy variable for the integration (theta)
-
-	double dr1,dr2,besarg1,besarg2,vol1,vol2,sinarg1,sinarg2,si1,si2,be1,be2,t1,t2,retval;
-	double Pi;
-	
-	Pi = 4.0*atan(1.0); 
-	
-	dr1 = rhoc-rhos;
-	dr2 = rhos-rhosolv;
-	vol1 = Pi*rad*rad*(2.0*length);
-	vol2 = Pi*(rad+radthick)*(rad+radthick)*(2.0*length+2.0*facthick);
-	
-	besarg1 = qq*rad*sin(dum);
-	besarg2 = qq*(rad+radthick)*sin(dum);
-	sinarg1 = qq*length*cos(dum);
-	sinarg2 = qq*(length+facthick)*cos(dum);
-	if (besarg1 == 0.0){
-		be1 = 0.5;
-	}else{
-		be1 = NR_BessJ1(besarg1)/besarg1;
-	}
-	if (besarg2 == 0.0){
-		be2 = 0.5;
-	}else{
-		be2 = NR_BessJ1(besarg2)/besarg2;
-	}
-	if (sinarg1 == 0.0){
-		si1 = 1.0;
-	}else{
-		si1 = sin(sinarg1)/sinarg1;
-	}
-	if (sinarg2 == 0.0){
-		si2 = 1.0;
-	}else{
-		si2 = sin(sinarg2)/sinarg2;
-	}
-
-	t1 = 2.0*vol1*dr1*si1*be1;
-	t2 = 2.0*vol2*dr2*si2*be2;
-
-	retval = ((t1+t2)*(t1+t2))*sin(dum);
-	return (retval);
-    
-}
-
-
-double
-CoreShellCylKernel(double qq, double rcore, double thick, double rhoc, double rhos, double rhosolv, double length, double dum)
-{
-
-    double dr1,dr2,besarg1,besarg2,vol1,vol2,sinarg1,sinarg2,si1,si2,be1,be2,t1,t2,retval;
-    double Pi;
-    
-    Pi = 4.0*atan(1.0);
-    
-    dr1 = rhoc-rhos;
-    dr2 = rhos-rhosolv;
-    vol1 = Pi*rcore*rcore*(2.0*length);
-    vol2 = Pi*(rcore+thick)*(rcore+thick)*(2.0*length+2.0*thick);
-    
-    besarg1 = qq*rcore*sin(dum);
-    besarg2 = qq*(rcore+thick)*sin(dum);
-    sinarg1 = qq*length*cos(dum);
-    sinarg2 = qq*(length+thick)*cos(dum);
-
-	if (besarg1 == 0.0){
-		be1 = 0.5;
-	}else{
-		be1 = NR_BessJ1(besarg1)/besarg1;
-	}
-	if (besarg2 == 0.0){
-		be2 = 0.5;
-	}else{
-		be2 = NR_BessJ1(besarg2)/besarg2;
-	}
-	if (sinarg1 == 0.0){
-		si1 = 1.0;
-	}else{
-		si1 = sin(sinarg1)/sinarg1;
-	}
-	if (sinarg2 == 0.0){
-		si2 = 1.0;
-	}else{
-		si2 = sin(sinarg2)/sinarg2;
-	}
-
-    t1 = 2.0*vol1*dr1*si1*be1;
-    t2 = 2.0*vol2*dr2*si2*be2;
-
-    retval = ((t1+t2)*(t1+t2))*sin(dum);
-	
-    return (retval);
-}
-
-double
-Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen)
-{
-	
-    double halfheight,uplim,lolim,zi,summ,yyy,Pi;
-    double answer,dr,Vcyl;
-    int i,nord;
-    
-    Pi = 4.0*atan(1.0);
-    lolim = 0.0;
-    uplim = Pi/2.0;
-    halfheight = dumLen/2.0;
-    nord=20;
-    summ = 0.0;
-    
-    //do the cylinder orientational average
-    for(i=0;i<nord;i++) {
-		zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss20Wt[i] * CylKernel(q, radius, halfheight, zi);
-		summ += yyy;
-    }
-    answer = (uplim-lolim)/2.0*summ;
-    // Multiply by contrast^2
-    answer *= delrho*delrho;
-    // don't do the normal scaling to volume here
-    // instead, multiply by VCyl^2 to get rid of the normalization for this radius of cylinder
-    Vcyl = Pi*radius*radius*dumLen;
-    answer *= Vcyl*Vcyl;
-    
-    dr = SchulzPoint_cpr(dumLen,len_avg,zz);
-    return(dr*answer);
-}
-
-
-double
-Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N)
-{         	
-	// qq is the q-value for the calculation (1/A)
-	// rcore is the core radius of the cylinder (A)
-	// rho(n) are the respective SLD's
-	// length is the *Half* CORE-LENGTH of the cylinder = L (A)
-	// dum is the dummy variable for the integration (x in Feigin's notation)
-
-	//Local variables
-	double totald,dr1,dr2,besarg1,besarg2,be1,be2,si1,si2,area,sinarg1,sinarg2,t1,t2,retval,sqq,dexpt;
-	double Pi;
-	int kk;
-	
-	Pi = 4.0*atan(1.0);
-	
-	dr1 = rhoc-rhosolv;
-	dr2 = rhol-rhosolv;
-	area = Pi*rcore*rcore;
-	totald=2.0*(thick+length);
-	
-	besarg1 = qq*rcore*sin(dum);
-	besarg2 = qq*rcore*sin(dum);
-	
-	sinarg1 = qq*length*cos(dum);
-	sinarg2 = qq*(length+thick)*cos(dum);
-
-	if (besarg1 == 0.0){
-		be1 = 0.5;
-	}else{
-		be1 = NR_BessJ1(besarg1)/besarg1;
-	}
-	if (besarg2 == 0.0){
-		be2 = 0.5;
-	}else{
-		be2 = NR_BessJ1(besarg2)/besarg2;
-	}
-	if (sinarg1 == 0.0){
-		si1 = 1.0;
-	}else{
-		si1 = sin(sinarg1)/sinarg1;
-	}
-	if (sinarg2 == 0.0){
-		si2 = 1.0;
-	}else{
-		si2 = sin(sinarg2)/sinarg2;
-	}
-
-	t1 = 2.0*area*(2.0*length)*dr1*(si1)*(be1);
-	t2 = 2.0*area*dr2*(totald*si2-2.0*length*si1)*(be2);
-
-	retval =((t1+t2)*(t1+t2))*sin(dum);
-	
-	// loop for the structure facture S(q)
-	sqq=0.0;
-	for(kk=1;kk<N;kk+=1) {
-		dexpt=qq*cos(dum)*qq*cos(dum)*d*d*gsd*gsd*kk/2.0;
-		sqq=sqq+(N-kk)*cos(qq*cos(dum)*d*kk)*exp(-1.*dexpt);
-	}			
-	
-	// end of loop for S(q)
-	sqq=1.0+2.0*sqq/N;
-	retval *= sqq;
-    
-	return(retval);
-}
-
-
-double
-Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad)
-{
-	
-    double halfheight,uplim,lolim,zi,summ,yyy,Pi;
-    double answer,dr,Vcyl;
-    int i,nord;
-    
-    Pi = 4.0*atan(1.0);
-    lolim = 0.0;
-    uplim = Pi/2.0;
-    halfheight = length/2.0;
-	//    nord=20;
-    nord=76;
-    summ = 0.0;
-    
-    //do the cylinder orientational average
-	//    for(i=0;i<nord;i++) {
-	//            zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-	//            yyy = Gauss20Wt[i] * CylKernel(q, dumRad, halfheight, zi);
-	//            summ += yyy;
-	//    }
-    for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * CylKernel(q, dumRad, halfheight, zi);
-		summ += yyy;
-    }
-    answer = (uplim-lolim)/2.0*summ;
-    // Multiply by contrast^2
-    answer *= delrho*delrho;
-    // don't do the normal scaling to volume here
-    // instead, multiply by VCyl^2 to get rid of the normalization for this radius of cylinder
-    Vcyl = Pi*dumRad*dumRad*length;
-    answer *= Vcyl*Vcyl;
-    
-    dr = SchulzPoint_cpr(dumRad,radius,zz);
-    return(dr*answer);
-}
-
-double
-SchulzPoint_cpr(double dumRad, double radius, double zz)
-{
-    double dr;
-    
-    dr = zz*log(dumRad) - gammaln(zz+1.0) + (zz+1.0)*log((zz+1.0)/radius)-(dumRad/radius*(zz+1.0));
-    return(exp(dr));
-}
-
-
-double
-EllipsoidKernel(double qq, double a, double nua, double dum)
-{
-    double arg,nu,retval;		//local variables
-	
-    nu = nua/a;
-    arg = qq*a*sqrt(1.0+dum*dum*(nu*nu-1.0));
-    if (arg == 0.0){
-    	retval =1.0/3.0;
-    }else{
-    	retval = (sin(arg)-arg*cos(arg))/(arg*arg*arg);
-    }
-    retval *= retval;
-    retval *= 9.0;
-
-    return(retval);
-}//Function EllipsoidKernel()
-
-double
-HolCylKernel(double qq, double rcore, double rshell, double length, double dum)
-{
-    double gamma,arg1,arg2,lam1,lam2,psi,sinarg,t2,retval;		//local variables
-    
-    gamma = rcore/rshell;
-    arg1 = qq*rshell*sqrt(1.0-dum*dum);		//1=shell (outer radius)
-    arg2 = qq*rcore*sqrt(1.0-dum*dum);			//2=core (inner radius)
-    if (arg1 == 0.0){
-    	lam1 = 1.0;
-    }else{
-    	lam1 = 2.0*NR_BessJ1(arg1)/arg1;
-    }
-    if (arg2 == 0.0){
-    	lam2 = 1.0;
-    }else{
-    	lam2 = 2.0*NR_BessJ1(arg2)/arg2;
-    }
-    //Todo: Need to check psi behavior as gamma goes to 1.
-    psi = 1.0/(1.0-gamma*gamma)*(lam1 -  gamma*gamma*lam2);		//SRK 10/19/00
-    sinarg = qq*length*dum/2.0;
-    if (sinarg == 0.0){
-    	t2 = 1.0;
-    }else{
-    	t2 = sin(sinarg)/sinarg;
-    }
-
-    retval = psi*psi*t2*t2;
-    
-    return(retval);
-}//Function HolCylKernel()
-
-double
-PPKernel(double aa, double mu, double uu)
-{
-    // mu passed in is really mu*sqrt(1-sig^2)
-    double arg1,arg2,Pi,tmp1,tmp2;			//local variables
-	
-    Pi = 4.0*atan(1.0);
-    
-    //handle arg=0 separately, as sin(t)/t -> 1 as t->0
-    arg1 = (mu/2.0)*cos(Pi*uu/2.0);
-    arg2 = (mu*aa/2.0)*sin(Pi*uu/2.0);
-    if(arg1==0.0) {
-		tmp1 = 1.0;
-	} else {
-		tmp1 = sin(arg1)*sin(arg1)/arg1/arg1;
-    }
-
-    if (arg2==0.0) {
-		tmp2 = 1.0;
-	} else {
-		tmp2 = sin(arg2)*sin(arg2)/arg2/arg2;
-    }
-	
-    return (tmp1*tmp2);
-	
-}//Function PPKernel()
-
-
-double
-TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy)
-{
-	
-    double arg,val,pi;			//local variables
-	
-    pi = 4.0*atan(1.0);
-    
-    arg = aa*aa*cos(pi*dx/2)*cos(pi*dx/2);
-    arg += bb*bb*sin(pi*dx/2)*sin(pi*dx/2)*(1-dy*dy);
-    arg += cc*cc*dy*dy;
-    arg = q*sqrt(arg);
-    if (arg == 0.0){
-    	val = 1.0; // as arg --> 0, val should go to 1.0
-    }else{
-    	val = 9.0 * ( (sin(arg) - arg*cos(arg))/(arg*arg*arg) ) * ( (sin(arg) - arg*cos(arg))/(arg*arg*arg) );
-    }
-    return (val);
-	
-}//Function TriaxialKernel()
-
-
-double
-CylKernel(double qq, double rr,double h, double theta)
-{
-	
-	// qq is the q-value for the calculation (1/A)
-	// rr is the radius of the cylinder (A)
-	// h is the HALF-LENGTH of the cylinder = L/2 (A)
-
-    double besarg,bj,retval,d1,t1,b1,t2,b2,siarg,be,si;		 //Local variables
-
-
-    besarg = qq*rr*sin(theta);
-    siarg = qq * h * cos(theta);
-    bj =NR_BessJ1(besarg);
-	
-	//* Computing 2nd power */
-    d1 = sin(siarg);
-    t1 = d1 * d1;
-	//* Computing 2nd power */
-    d1 = bj;
-    t2 = d1 * d1 * 4.0 * sin(theta);
-	//* Computing 2nd power */
-    d1 = siarg;
-    b1 = d1 * d1;
-	//* Computing 2nd power */
-    d1 = qq * rr * sin(theta);
-    b2 = d1 * d1;
-    if (besarg == 0.0){
-    	be = sin(theta);
-    }else{
-    	be = t2 / b2;
-    }
-    if (siarg == 0.0){
-    	si = 1.0;
-    }else{
-    	si = t1 / b1;
-    }
-    retval = be * si;
-
-    return (retval);
-	
-}//Function CylKernel()
-
-double
-EllipCylKernel(double qq, double ra,double nu, double theta)
-{
-	//this is the function LAMBDA1^2 in Feigin's notation	
-	// qq is the q-value for the calculation (1/A)
-	// ra is the transformed radius"a" in Feigin's notation
-	// nu is the ratio (major radius)/(minor radius) of the Ellipsoid [=] ---
-	// theta is the dummy variable of the integration
-	
-	double retval,arg;		 //Local variables 
-	
-	arg = qq*ra*sqrt((1.0+nu*nu)/2+(1.0-nu*nu)*cos(theta)/2);
-	if (arg == 0.0){
-		retval = 1.0;
-	}else{
-		retval = 2.0*NR_BessJ1(arg)/arg;
-	}
-
-	//square it
-	retval *= retval;
-	
-    return(retval);
-	
-}//Function EllipCylKernel()
-
-double NR_BessJ1(double x)
-{
-	double ax,z;
-	double xx,y,ans,ans1,ans2;
-	
-	if ((ax=fabs(x)) < 8.0) {
-		y=x*x;
-		ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1
-												  +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
-		ans2=144725228442.0+y*(2300535178.0+y*(18583304.74
-											   +y*(99447.43394+y*(376.9991397+y*1.0))));
-		ans=ans1/ans2;
-	} else {
-		z=8.0/ax;
-		y=z*z;
-		xx=ax-2.356194491;
-		ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4
-								   +y*(0.2457520174e-5+y*(-0.240337019e-6))));
-		ans2=0.04687499995+y*(-0.2002690873e-3
-							  +y*(0.8449199096e-5+y*(-0.88228987e-6
-													 +y*0.105787412e-6)));
-		ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
-		if (x < 0.0) ans = -ans;
-	}
-	
-	return(ans);
-}
-
-/*	Lamellar_ParaCrystal - Pedersen's model
-
-*/
-double
-Lamellar_ParaCrystal(double w[], double q)
-{
-//	 Input (fitting) variables are:
-	//[0] scale factor
-	//[1]	thickness
-	//[2]	number of layers
-	//[3]	spacing between layers
-	//[4]	polydispersity of spacing
-	//[5] SLD lamellar
-	//[6] SLD solvent
-	//[7] incoherent background
-//	give them nice names
-	double inten,qval,scale,th,nl,davg,pd,contr,bkg,xn;
-	double xi,ww,Pbil,Znq,Snq,an,sldLayer,sldSolvent,pi;
-	long n1,n2;
-	
-	pi = 4.0*atan(1.0);
-	scale = w[0];
-	th = w[1];
-	nl = w[2];
-	davg = w[3];
-	pd = w[4];
-	sldLayer = w[5];
-	sldSolvent = w[6];
-	bkg = w[7];
-	
-	contr = w[5] - w[6];
-	qval = q;
-		
-	//get the fractional part of nl, to determine the "mixing" of N's
-	
-	n1 = trunc(nl);		//rounds towards zero
-	n2 = n1 + 1;
-	xn = (double)n2 - nl;			//fractional contribution of n1
-	
-	ww = exp(-qval*qval*pd*pd*davg*davg/2.0);
-	
-	//calculate the n1 contribution
-	an = paraCryst_an(ww,qval,davg,n1);
-	Snq = paraCryst_sn(ww,qval,davg,n1,an);
-	
-	Znq = xn*Snq;
-	
-	//calculate the n2 contribution
-	an = paraCryst_an(ww,qval,davg,n2);
-	Snq = paraCryst_sn(ww,qval,davg,n2,an);
-	
-	Znq += (1.0-xn)*Snq;
-	
-	//and the independent contribution
-	Znq += (1.0-ww*ww)/(1.0+ww*ww-2.0*ww*cos(qval*davg));
-	
-	//the limit when NL approaches infinity
-//	Zq = (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg))
-	
-	xi = th/2.0;		//use 1/2 the bilayer thickness
-	Pbil = (sin(qval*xi)/(qval*xi))*(sin(qval*xi)/(qval*xi));
-	
-	inten = 2.0*pi*contr*contr*Pbil*Znq/(qval*qval);
-	inten *= 1.0e8;
-	
-	return(scale*inten+bkg);
-}
-
-// functions for the lamellar paracrystal model
-double
-paraCryst_sn(double ww, double qval, double davg, long nl, double an) {
-	
-	double Snq;
-	
-	Snq = an/( (double)nl*pow((1.0+ww*ww-2.0*ww*cos(qval*davg)),2) );
-	
-	return(Snq);
-}
-
-
-double
-paraCryst_an(double ww, double qval, double davg, long nl) {
-	
-	double an;
-	
-	an = 4.0*ww*ww - 2.0*(ww*ww*ww+ww)*cos(qval*davg);
-	an -= 4.0*pow(ww,(nl+2))*cos((double)nl*qval*davg);
-	an += 2.0*pow(ww,(nl+3))*cos((double)(nl-1)*qval*davg);
-	an += 2.0*pow(ww,(nl+1))*cos((double)(nl+1)*qval*davg);
-	
-	return(an);
-}
-
-
-/*	Spherocylinder  :
-
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-Spherocylinder(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,contr,bkg,sldc,slds;
-	double len,rad,hDist,endRad;
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	double SphCyl_tmp[7],arg1,arg2,inner,be;
-	
-	
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	sldc = w[3];
-	slds = w[4];
-	bkg = w[5];
-	
-	SphCyl_tmp[0] = w[0];
-	SphCyl_tmp[1] = w[1];
-	SphCyl_tmp[2] = w[2];
-	SphCyl_tmp[3] = w[1];		//end radius is same as cylinder radius
-	SphCyl_tmp[4] = w[3];
-	SphCyl_tmp[5] = w[4];
-	SphCyl_tmp[6] = w[5];
-	
-	hDist = 0;		//by definition for this model
-	endRad = rad;
-	
-	contr = sldc-slds;
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = -1.0*hDist/endRad;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "theta" dummy
-		
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "t" dummy
-			yyy = Gauss76Wt[j] * SphCyl_kernel(SphCyl_tmp,x,zij,zi);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		inner = (vbj-vaj)/2.0*summj;
-		inner *= 4.0*Pi*endRad*endRad*endRad;
-		
-		//now calculate outer integrand
-		arg1 = x*len/2.0*cos(zi);
-		arg2 = x*rad*sin(zi);
-		yyy = inner;
-
-		if(arg2 == 0) {
-			be = 0.5;
-		} else {
-			be = NR_BessJ1(arg2)/arg2;
-		}
-		
-		if(arg1 == 0.0) {		//limiting value of sinc(0) is 1; sinc is not defined in math.h
-			yyy += Pi*rad*rad*len*2.0*be;
-		} else {
-			yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be;
-		}
-		yyy *= yyy;
-		yyy *= sin(zi);		// = |A(q)|^2*sin(theta)
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	answer /= Pi*rad*rad*len + Pi*4.0*endRad*endRad*endRad/3.0;		//divide by volume
-	answer *= 1.0e8;		//convert to cm^-1
-	answer *= contr*contr;
-	answer *= scale;
-	answer += bkg;
-		
-	return answer;
-}
-
-
-// inner integral of the sphereocylinder model, special case of hDist = 0
-//
-double
-SphCyl_kernel(double w[], double x, double tt, double theta) {
-
-	double val,arg1,arg2;
-	double scale,bkg,sldc,slds;
-	double len,rad,hDist,endRad,be;
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	endRad = w[3];
-	sldc = w[4];
-	slds = w[5];
-	bkg = w[6];
-	
-	hDist = 0.0;
-		
-	arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0);
-	arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt);
-	
-	if(arg2 == 0) {
-		be = 0.5;
-	} else {
-		be = NR_BessJ1(arg2)/arg2;
-	}
-	val = cos(arg1)*(1.0-tt*tt)*be;
-	
-	return(val);
-}
-
-
-/*	Convex Lens  : special case where L ~ 0 and hDist < 0
-
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-ConvexLens(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,contr,bkg,sldc,slds;
-	double len,rad,hDist,endRad;
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	double CLens_tmp[7],arg1,arg2,inner,hh,be;
-	
-	
-	scale = w[0];
-	rad = w[1];
-//	len = w[2]
-	endRad = w[2];
-	sldc = w[3];
-	slds = w[4];
-	bkg = w[5];
-	
-	len = 0.01;
-	
-	CLens_tmp[0] = w[0];
-	CLens_tmp[1] = w[1];
-	CLens_tmp[2] = len;			//length is some small number, essentially zero
-	CLens_tmp[3] = w[2];
-	CLens_tmp[4] = w[3];
-	CLens_tmp[5] = w[4];
-	CLens_tmp[6] = w[5];
-		
-	hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));		//by definition for this model
-	
-	contr = sldc-slds;
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = -1.0*hDist/endRad;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "theta" dummy
-		
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "t" dummy
-			yyy = Gauss76Wt[j] * ConvLens_kernel(CLens_tmp,x,zij,zi);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		inner = (vbj-vaj)/2.0*summj;
-		inner *= 4.0*Pi*endRad*endRad*endRad;
-		
-		//now calculate outer integrand
-		arg1 = x*len/2.0*cos(zi);
-		arg2 = x*rad*sin(zi);
-		yyy = inner;
-		
-		if(arg2 == 0) {
-			be = 0.5;
-		} else {
-			be = NR_BessJ1(arg2)/arg2;
-		}
-		
-		if(arg1 == 0.0) {		//limiting value of sinc(0) is 1; sinc is not defined in math.h
-			yyy += Pi*rad*rad*len*2.0*be;
-		} else {
-			yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be;
-		}
-		yyy *= yyy;
-		yyy *= sin(zi);		// = |A(q)|^2*sin(theta)
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	hh = fabs(hDist);		//need positive value for spherical cap volume
-	answer /= 2.0*(1.0/3.0*Pi*(endRad-hh)*(endRad-hh)*(2.0*endRad+hh));		//divide by volume
-	answer *= 1.0e8;		//convert to cm^-1
-	answer *= contr*contr;
-	answer *= scale;
-	answer += bkg;
-		
-	return answer;
-}
-
-/*	Capped Cylinder  : special case where L is nonzero and hDist < 0
-
- -- uses the same Kernel as the Convex Lens
- 
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-CappedCylinder(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,contr,bkg,sldc,slds;
-	double len,rad,hDist,endRad;
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	double arg1,arg2,inner,hh,be;
-	
-	
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	endRad = w[3];
-	sldc = w[4];
-	slds = w[5];
-	bkg = w[6];
-		
-	hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));		//by definition for this model
-	
-	contr = sldc-slds;
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = -1.0*hDist/endRad;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "theta" dummy
-		
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "t" dummy
-			yyy = Gauss76Wt[j] * ConvLens_kernel(w,x,zij,zi);		//uses the same kernel as ConvexLens, except here L != 0
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		inner = (vbj-vaj)/2.0*summj;
-		inner *= 4.0*Pi*endRad*endRad*endRad;
-		
-		//now calculate outer integrand
-		arg1 = x*len/2.0*cos(zi);
-		arg2 = x*rad*sin(zi);
-		yyy = inner;
-		
-		if(arg2 == 0) {
-			be = 0.5;
-		} else {
-			be = NR_BessJ1(arg2)/arg2;
-		}
-		
-		if(arg1 == 0.0) {		//limiting value of sinc(0) is 1; sinc is not defined in math.h
-			yyy += Pi*rad*rad*len*2.0*be;
-		} else {
-			yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be;
-		}
-		
-		
-		
-		yyy *= yyy;
-		yyy *= sin(zi);		// = |A(q)|^2*sin(theta)
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	hh = fabs(hDist);		//need positive value for spherical cap volume
-	answer /= Pi*rad*rad*len + 2.0*(1.0/3.0*Pi*(endRad-hh)*(endRad-hh)*(2.0*endRad+hh));		//divide by volume
-	answer *= 1.0e8;		//convert to cm^-1
-	answer *= contr*contr;
-	answer *= scale;
-	answer += bkg;
-		
-	return answer;
-}
-
-
-
-// inner integral of the ConvexLens model, special case where L ~ 0 and hDist < 0
-//
-double
-ConvLens_kernel(double w[], double x, double tt, double theta) {
-
-	double val,arg1,arg2;
-	double scale,bkg,sldc,slds;
-	double len,rad,hDist,endRad,be;
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	endRad = w[3];
-	sldc = w[4];
-	slds = w[5];
-	bkg = w[6];
-	
-	hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));
-		
-	arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0);
-	arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt);
-	
-	if(arg2 == 0) {
-		be = 0.5;
-	} else {
-		be = NR_BessJ1(arg2)/arg2;
-	}
-	
-	val = cos(arg1)*(1.0-tt*tt)*be;
-	
-	return(val);
-}
-
-
-/*	Dumbbell  : special case where L ~ 0 and hDist > 0
-
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-Dumbbell(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,contr,bkg,sldc,slds;
-	double len,rad,hDist,endRad;
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	double Dumb_tmp[7],arg1,arg2,inner,be;
-	
-	
-	scale = w[0];
-	rad = w[1];
-//	len = w[2]
-	endRad = w[2];
-	sldc = w[3];
-	slds = w[4];
-	bkg = w[5];
-	
-	len = 0.01;
-	
-	Dumb_tmp[0] = w[0];
-	Dumb_tmp[1] = w[1];
-	Dumb_tmp[2] = len;		//length is some small number, essentially zero
-	Dumb_tmp[3] = w[2];
-	Dumb_tmp[4] = w[3];
-	Dumb_tmp[5] = w[4];
-	Dumb_tmp[6] = w[5];
-			
-	hDist = sqrt(fabs(endRad*endRad-rad*rad));		//by definition for this model
-	
-	contr = sldc-slds;
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = -1.0*hDist/endRad;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "theta" dummy
-		
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "t" dummy
-			yyy = Gauss76Wt[j] * Dumb_kernel(Dumb_tmp,x,zij,zi);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		inner = (vbj-vaj)/2.0*summj;
-		inner *= 4.0*Pi*endRad*endRad*endRad;
-		
-		//now calculate outer integrand
-		arg1 = x*len/2.0*cos(zi);
-		arg2 = x*rad*sin(zi);
-		yyy = inner;
-		
-		if(arg2 == 0) {
-			be = 0.5;
-		} else {
-			be = NR_BessJ1(arg2)/arg2;
-		}
-		
-		if(arg1 == 0.0) {		//limiting value of sinc(0) is 1; sinc is not defined in math.h
-			yyy += Pi*rad*rad*len*2.0*be;
-		} else {
-			yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be;
-		}
-		yyy *= yyy;
-		yyy *= sin(zi);		// = |A(q)|^2*sin(theta)
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	answer /= 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0);		//divide by volume
-	answer *= 1.0e8;		//convert to cm^-1
-	answer *= contr*contr;
-	answer *= scale;
-	answer += bkg;
-		
-	return answer;
-}
-
-
-/*	Barbell  : "normal" case where L is nonzero 0 and hDist > 0
-
--- uses the same kernel as the Dumbbell case
-
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-Barbell(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,contr,bkg,sldc,slds;
-	double len,rad,hDist,endRad;
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	double arg1,arg2,inner,be;
-	
-	
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	endRad = w[3];
-	sldc = w[4];
-	slds = w[5];
-	bkg = w[6];
-			
-	hDist = sqrt(fabs(endRad*endRad-rad*rad));		//by definition for this model
-	
-	contr = sldc-slds;
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = -1.0*hDist/endRad;
-	vbj = 1.0;		//endpoints of inner integral
-
-	summ = 0.0;			//initialize intergral
-
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the "theta" dummy
-		
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the "t" dummy
-			yyy = Gauss76Wt[j] * Dumb_kernel(w,x,zij,zi);		//uses the same Kernel as the Dumbbell, here L>0
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		inner = (vbj-vaj)/2.0*summj;
-		inner *= 4.0*Pi*endRad*endRad*endRad;
-		
-		//now calculate outer integrand
-		arg1 = x*len/2.0*cos(zi);
-		arg2 = x*rad*sin(zi);
-		yyy = inner;
-		
-		if(arg2 == 0) {
-			be = 0.5;
-		} else {
-			be = NR_BessJ1(arg2)/arg2;
-		}
-		
-		if(arg1 == 0.0) {		//limiting value of sinc(0) is 1; sinc is not defined in math.h
-			yyy += Pi*rad*rad*len*2.0*be;
-		} else {
-			yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be;
-		}
-		yyy *= yyy;
-		yyy *= sin(zi);		// = |A(q)|^2*sin(theta)
-		yyy *= Gauss76Wt[i];
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0);		//divide by volume
-	answer *= 1.0e8;		//convert to cm^-1
-	answer *= contr*contr;
-	answer *= scale;
-	answer += bkg;
-		
-	return answer;
-}
-
-
-
-// inner integral of the Dumbbell model, special case where L ~ 0 and hDist > 0
-//
-// inner integral of the Barbell model if L is nonzero
-//
-double
-Dumb_kernel(double w[], double x, double tt, double theta) {
-
-	double val,arg1,arg2;
-	double scale,bkg,sldc,slds;
-	double len,rad,hDist,endRad,be;
-	scale = w[0];
-	rad = w[1];
-	len = w[2];
-	endRad = w[3];
-	sldc = w[4];
-	slds = w[5];
-	bkg = w[6];
-	
-	hDist = sqrt(fabs(endRad*endRad-rad*rad));
-		
-	arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0);
-	arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt);
-	
-	if(arg2 == 0) {
-		be = 0.5;
-	} else {
-		be = NR_BessJ1(arg2)/arg2;
-	}
-	val = cos(arg1)*(1.0-tt*tt)*be;
-	
-	return(val);
-}
-
-double PolyCoreBicelle(double dp[], double q)
-{
-	int i;
-	int nord = 20;
-	double scale, length, sigma, bkg, radius, radthick, facthick;
-	double rhoc, rhoh, rhor, rhosolv;
-	double answer, Vpoly;
-	double Pi,lolim,uplim,summ,yyy,rad,AR,Rsqr,Rsqrsumm,Rsqryyy;
-	
-	scale = dp[0];
-	radius = dp[1];
-	sigma = dp[2];				//sigma is the standard mean deviation
-	length = dp[3];
-	radthick = dp[4];
-	facthick= dp[5];
-	rhoc = dp[6];
-	rhoh = dp[7];
-	rhor=dp[8];
-	rhosolv = dp[9];
-	bkg = dp[10];
-	
-	Pi = 4.0*atan(1.0);
-	
-	lolim = exp(log(radius)-(4.*sigma));
-	if (lolim<0.0) {
-		lolim=0.0;		//to avoid numerical error when  va<0 (-ve r value)
-	}
-	uplim = exp(log(radius)+(4.*sigma));
-	
-	summ = 0.0;
-	Rsqrsumm = 0.0;
-	
-	for(i=0;i<nord;i++) {
-		rad = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		AR=(1.0/(rad*sigma*sqrt(2.0*Pi)))*exp(-(0.5*((log(radius/rad))/sigma)*((log(radius/rad))/sigma)));
-		yyy = AR* Gauss20Wt[i] * BicelleIntegration(q,rad,radthick,facthick,rhoc,rhoh,rhor,rhosolv,length);
-		Rsqryyy= Gauss20Wt[i] * AR * (rad+radthick)*(rad+radthick);		//SRK normalize to total dimensions
-		summ += yyy;
-		Rsqrsumm += Rsqryyy;
-	}
-	
-	answer = (uplim-lolim)/2.0*summ;
-	Rsqr = (uplim-lolim)/2.0*Rsqrsumm;
-	//normalize by average cylinder volume
-	Vpoly = Pi*Rsqr*(length+2*facthick);
-	answer /= Vpoly;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-		
-	return answer;
-	
-}
-
-double
-BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length){
-
-	double answer,halfheight,Pi;
-	double lolim,uplim,summ,yyy,zi;
-	int nord,i;
-	
-	// set up the integration end points 
-	Pi = 4.0*atan(1.0);
-	nord = 76;
-	lolim = 0.0;
-	uplim = Pi/2;
-	halfheight = length/2.0;
-	
-	summ = 0.0;				// initialize integral
-	i=0;
-	for(i=0;i<nord;i++) {
-		zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
-		yyy = Gauss76Wt[i] * BicelleKernel(qq, rad, radthick, facthick, rhoc, rhoh, rhor,rhosolv, halfheight, zi);
-		summ += yyy;
-	}
-	
-	// calculate value of integral to return
-	answer = (uplim-lolim)/2.0*summ;
-	return(answer);	
-}
-
-double
-BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum)
-{
-	double dr1,dr2,dr3;
-	double besarg1,besarg2;
-	double vol1,vol2,vol3;
-	double sinarg1,sinarg2;
-	double t1,t2,t3;
-	double retval,si1,si2,be1,be2;
-	
-	double Pi = 4.0*atan(1.0);
-	
-	dr1 = rhoc-rhoh;
-	dr2 = rhor-rhosolv;
-	dr3=  rhoh-rhor;
-	vol1 = Pi*rad*rad*(2.0*length);
-	vol2 = Pi*(rad+radthick)*(rad+radthick)*(2.0*length+2.0*facthick);
-	vol3= Pi*(rad)*(rad)*(2.0*length+2.0*facthick);
-	besarg1 = qq*rad*sin(dum);
-	besarg2 = qq*(rad+radthick)*sin(dum);
-	sinarg1 = qq*length*cos(dum);
-	sinarg2 = qq*(length+facthick)*cos(dum);
-	
-	if(besarg1 == 0) {
-		be1 = 0.5;
-	} else {
-		be1 = NR_BessJ1(besarg1)/besarg1;
-	}
-	if(besarg2 == 0) {
-		be2 = 0.5;
-	} else {
-		be2 = NR_BessJ1(besarg2)/besarg2;
-	}	
-	if(sinarg1 == 0) {
-		si1 = 1.0;
-	} else {
-		si1 = sin(sinarg1)/sinarg1;
-	}
-	if(sinarg2 == 0) {
-		si2 = 1.0;
-	} else {
-		si2 = sin(sinarg2)/sinarg2;
-	}
-	t1 = 2.0*vol1*dr1*si1*be1;
-	t2 = 2.0*vol2*dr2*si2*be2;
-	t3 = 2.0*vol3*dr3*si2*be1;
-	
-	retval = ((t1+t2+t3)*(t1+t2+t3))*sin(dum);
-	return(retval);
-	
-}
-
-
-double
-CSPPKernel(double dp[], double mu, double uu)
-{	
-	double aa,bb,cc, ta,tb,tc; 
-	double Vin,Vot,V1,V2;
-	double rhoA,rhoB,rhoC, rhoP, rhosolv;
-	double dr0, drA,drB, drC;
-	double arg1,arg2,arg3,arg4,t1,t2, t3, t4;
-	double Pi,retVal;
-
-	aa = dp[1];
-	bb = dp[2];
-	cc = dp[3];
-	ta = dp[4];
-	tb = dp[5];
-	tc = dp[6];
-	rhoA=dp[7];
-	rhoB=dp[8];
-	rhoC=dp[9];
-	rhoP=dp[10];
-	rhosolv=dp[11];
-	dr0=rhoP-rhosolv;
-	drA=rhoA-rhosolv;
-	drB=rhoB-rhosolv;
-	drC=rhoC-rhosolv; 
-	Vin=(aa*bb*cc);
-	Vot=(aa*bb*cc+2.0*ta*bb*cc+2.0*aa*tb*cc+2.0*aa*bb*tc);
-	V1=(2.0*ta*bb*cc);   //  incorrect V1 (aa*bb*cc+2*ta*bb*cc)
-	V2=(2.0*aa*tb*cc);  // incorrect V2(aa*bb*cc+2*aa*tb*cc)
-	aa = aa/bb;
-	ta=(aa+2.0*ta)/bb;
-	tb=(aa+2.0*tb)/bb;
-	
-	Pi = 4.0*atan(1.0);
-	
-	arg1 = (mu*aa/2.0)*sin(Pi*uu/2.0);
-	arg2 = (mu/2.0)*cos(Pi*uu/2.0);
-	arg3=  (mu*ta/2.0)*sin(Pi*uu/2.0);
-	arg4=  (mu*tb/2.0)*cos(Pi*uu/2.0);
-			 
-	if(arg1==0.0){
-		t1 = 1.0;
-	} else {
-		t1 = (sin(arg1)/arg1);                //defn for CSPP model sin(arg1)/arg1    test:  (sin(arg1)/arg1)*(sin(arg1)/arg1)   
-	}
-	if(arg2==0.0){
-		t2 = 1.0;
-	} else {
-		t2 = (sin(arg2)/arg2);           //defn for CSPP model sin(arg2)/arg2   test: (sin(arg2)/arg2)*(sin(arg2)/arg2)    
-	}	
-	if(arg3==0.0){
-		t3 = 1.0;
-	} else {
-		t3 = sin(arg3)/arg3;
-	}
-	if(arg4==0.0){
-		t4 = 1.0;
-	} else {
-		t4 = sin(arg4)/arg4;
-	}
-	retVal =( dr0*t1*t2*Vin + drA*(t3-t1)*t2*V1+ drB*t1*(t4-t2)*V2 )*( dr0*t1*t2*Vin + drA*(t3-t1)*t2*V1+ drB*t1*(t4-t2)*V2 );   //  correct FF : square of sum of phase factors
-	return(retVal); 
-
-}
-
-/*	CSParallelepiped  :  calculates the form factor of a Parallelepiped with a core-shell structure
- -- different SLDs can be used for the face and rim
-
-Uses 76 pt Gaussian quadrature for both integrals
-*/
-double
-CSParallelepiped(double dp[], double q)
-{
-	int i,j;
-	double scale,aa,bb,cc,ta,tb,tc,rhoA,rhoB,rhoC,rhoP,rhosolv,bkg;		//local variables of coefficient wave
-	int nordi=76;			//order of integration
-	int nordj=76;
-	double va,vb;		//upper and lower integration limits
-	double summ,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj;			//for the inner integration
-	double mu,mudum,arg,sigma,uu,vol;
-	
-	
-	//	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 1.0;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = 1.0;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = dp[0];
-	aa = dp[1];
-	bb = dp[2];
-	cc = dp[3];
-	ta  = dp[4];
-	tb  = dp[5];
-	tc  = dp[6];   // is 0 at the moment  
-	rhoA=dp[7];   //rim A SLD
-	rhoB=dp[8];   //rim B SLD
-	rhoC=dp[9];    //rim C SLD
-	rhoP = dp[10];   //Parallelpiped core SLD
-	rhosolv=dp[11];  // Solvent SLD
-	bkg = dp[12];
-	
-	mu = q*bb;
-	vol = aa*bb*cc+2.0*ta*bb*cc+2.0*aa*tb*cc+2.0*aa*bb*tc;		//calculate volume before rescaling
-	
-	// do the rescaling here, not in the kernel
-	// normalize all WRT bb
-	aa = aa/bb;
-	cc = cc/bb;
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		sigma = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;		//the outer dummy
-		
-		for(j=0;j<nordj;j++) {
-			//76 gauss points for the inner integral
-			uu = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the inner dummy
-			mudum = mu*sqrt(1.0-sigma*sigma);
-			yyy = Gauss76Wt[j] * CSPPKernel(dp,mudum,uu);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		
-		//finish the outer integral cc already scaled
-		arg = mu*cc*sigma/2.0;
-		if ( arg == 0.0 ) {
-			answer *= 1.0;
-		} else {
-			answer *= sin(arg)*sin(arg)/arg/arg;
-		}
-		
-		//now sum up the outer integral
-		yyy = Gauss76Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-
-	//normalize by volume
-	answer /= vol;
-	//convert to [cm-1]
-	answer *= 1.0e8;
-	//Scale
-	answer *= scale;
-	// add in the background
-	answer += bkg;
-	
-	return answer;
-}
-
-
-/*
- * Massive rectangular prism (a <= b <=c) 
- * using eqns. (12)+(16) from Nayuk & Huber, Z. Phys. Chem. 226, 837 (2012).
- * It is totally equivalent to the Parallelepiped model in this library,
- * but instead of using as input the a, b, and c sides of the prism,
- * it uses a and the ratios (b/a) and (c/a).
- * This allows to keep the shape when using the polydispersity.
- */
-
-double
-RectangularPrism(double dp[], double q)
-{
-    int i, j;
-    double scale, aa, bb, cc, delrho, bkg;		
-    int nordi=76;			        //order of integration
-    int nordj=76;
-    double Pi;
-    double sumi, sumj;
-    double v1a, v1b, v2a, v2b;		// upper and lower integration limits
-    double answer;
-    double theta, phi, arg, termA, termB, termC, AP, ahalf, bhalf, chalf;
-    double vol, sldp, sld;
-
-    Pi = 4.0*atan(1.0);
-
-    scale = dp[0];	
-    aa = dp[1];          // parameter short_side
-    bb = aa * dp[2];     // parameter b/a ratio
-    cc = aa * dp[3];     // parameter c/a ratio
-    sldp = dp[4];        // scattering length density of the object
-    sld = dp[5];         // scattering length density of the solvent
-    delrho = sldp - sld;
-    bkg = dp[6];
-
-    vol = aa*bb*cc;
-    ahalf = 0.5 * aa;
-    bhalf = 0.5 * bb;
-    chalf = 0.5 * cc;
-
-   //Integration limits to use in Gaussian quadrature
-    v1a = 0.;
-    v1b = Pi/2.;  //theta integration limits
-    v2a = 0.;
-    v2b = Pi/2.;  //phi integration limits
-
-    sumi = 0.0;
-    for(i=0;i<nordi;i++) {
-
-	    theta = ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b )/2.0;	//z values for gaussian quadrature
-
-	    arg = q*chalf*cos(theta);
-	    if (fabs(arg) > 1.e-16) {termC = sin(arg) / arg;} else {termC = 1.0;}  
-
-	    sumj = 0.0;
-	    for(j=0;j<nordj;j++) {
-
-                phi = ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b )/2.0; //z values for gaussian quadrature
-
-	        // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0
-
-	        arg = q*ahalf*sin(theta)*sin(phi); 
-	        if (fabs(arg) > 1.e-16) {termA = sin(arg) / arg;} else {termA = 1.0;}
-	       
-	        arg = q*bhalf*sin(theta)*cos(phi); 
-	        if (fabs(arg) > 1.e-16) {termB = sin(arg) / arg;} else {termB = 1.0;}	  
-               
-	        AP = termA * termB * termC;  
-
-	        sumj += Gauss76Wt[j] * (AP*AP);
-
-	    }
-
-	    sumj = (v2b-v2a) * sumj / 2.0;
-	    sumi += Gauss76Wt[i] * sumj * sin(theta);
-
-    }
-
-    answer = (v1b-v1a)/2.0*sumi;
-
-    // Normalize by Pi (Eqn. 16). 
-    // The term (ABC)^2 does not appear because it was introduced before from the defs of termA, termB, termC
-    // The factor 2 appears because the theta integral has been defined between 0 and pi/2, instead of 0 to pi
-    answer = 2.0 * answer / Pi; //Form factor P(q)
-
-    // Multiply by contrast^2
-    answer *= delrho*delrho;
-
-    //normalize by volume
-    answer *= vol;
-	
-    //convert to [cm-1]
-    answer *= 1.0e8;
-
-    //Scale
-    answer *= scale;
-
-    // add in the background
-    answer += bkg;
-
-    return answer;
-}
-
-
-/*
- * Hollow rectangular prism (a <= b <=c) with infinitely thin walls
- * using eqn. (7-11) from Nayuk & Huber, Z. Phys. Chem. 226, 837 (2012)
- */
-
-double
-RectangularHollowPrismInfThinWalls(double dp[], double q)
-{
-    int i,j;
-    double scale,aa,bb,cc,delrho,bkg;
-    int nordi=76;
-    int nordj=76;
-    double Pi;
-    double sumi, sumj;
-    double v1a, v1b, v2a, v2b;		//upper and lower integration limits
-    double answer;
-    double theta, phi, termAL_theta, termAT_theta, AL, AT, ahalf, bhalf, chalf, vol;
-    double sldp, sld ;
-
-    Pi = 4.0*atan(1.0);
-
-    scale = dp[0];		  //make local copies in case memory moves
-    aa = dp[1];
-    bb = aa * dp[2];
-    cc = aa * dp[3];
-    sldp = dp[4];        // scattering length density of the object
-    sld = dp[5];         // scattering length density of the solvent
-    delrho = sldp - sld;
-    bkg = dp[6];
-
-    ahalf = 0.5 * aa;
-    bhalf = 0.5 * bb;
-    chalf = 0.5 * cc;
-
-    //Integration limits to use in Gaussian quadrature
-    v1a = 0.;
-    v1b = Pi/2;   //theta integration limits
-    v2a = 0.;
-    v2b = Pi/2.;  //phi integration limits
-
-    sumi = 0.0;
-    for(i=0;i<nordi;i++) {
-
-        theta = ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b )/2.0;	//z values for gaussian quadrature
-
-        // To check potential problems if denominator goes to zero here !!!
-        termAL_theta = 8.0*cos(q*chalf*cos(theta)) / (q*q*sin(theta)*sin(theta));
-        termAT_theta = 8.0*sin(q*chalf*cos(theta)) / (q*q*sin(theta)*cos(theta));
-
-        sumj = 0.0;
-        for(j=0;j<nordj;j++) {
-
-            phi = ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b )/2.0;	//z values for gaussian quadrature
-
-            // Amplitude AL from eqn. (7c)
-            AL = termAL_theta * sin(q*ahalf*sin(theta)*sin(phi)) * sin(q*bhalf*sin(theta)*cos(phi)) / (sin(phi)*cos(phi));
-
-            // Amplitude AT from eqn. (9)
-            AT = termAT_theta * (  (cos(q*ahalf*sin(theta)*sin(phi))*sin(q*bhalf*sin(theta)*cos(phi))/cos(phi)) + (cos(q*bhalf*sin(theta)*cos(phi))*sin(q*ahalf*sin(theta)*sin(phi))/sin(phi)) );
-
-            sumj += Gauss76Wt[j] * (AL+AT)*(AL+AT);
-
-        }
-
-        sumj = (v2b-v2a) * sumj / 2.0;
-        sumi += Gauss76Wt[i] * sumj * sin(theta);
-
-    }
-
-    answer = (v1b-v1a)/2.0*sumi;
-
-    // Normalize as in Eqn. (11). The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
-    vol = 2.0*aa*bb+2.0*aa*cc+2.0*bb*cc;
-    answer = 2.0 * answer / Pi / vol / vol;
-
-    // Multiply by contrast^2
-    answer *= delrho*delrho;
-
-    //normalize by volume
-    answer *= vol;
-
-    //convert to [cm-1]
-    answer *= 1.0e8;
-
-    //Scale
-    answer *= scale;
-
-    // add in the background
-    answer += bkg;
-
-    return answer;
-}
-
-
-/*
- * Hollow rectangular prism (a <= b <=c)
- * using eqn. (13-15) from Nayuk & Huber, Z. Phys. Chem. 226, 837 (2012)
- */
- 
-double
-RectangularHollowPrism(double dp[], double q)
-{
-    int i, j;
-    double scale, aa, bb, cc, thickness, delrho, bkg;
-    int nordi=76;
-    int nordj=76;
-    double Pi;
-    double sumi, sumj;
-    double v1a, v1b, v2a, v2b;		//upper and lower integration limits
-    double answer;
-    double theta, phi, arg, termA1, termB1, termC1, termA2, termB2, termC2, AP1, AP2, AP, ahalf, bhalf, chalf, vol;
-    double sldp, sld ;
-
-    Pi = 4.0*atan(1.0);
-
-    scale = dp[0];
-    aa = dp[1];
-    bb = aa * dp[2];
-    cc = aa * dp[3];
-    thickness = dp[4];
-    sldp = dp[5];        // scattering length density of the object
-    sld = dp[6];         // scattering length density of the solvent
-    delrho = sldp - sld;
-    bkg = dp[7];
-
-    ahalf = 0.5 * aa;
-    bhalf = 0.5 * bb;
-    chalf = 0.5 * cc;
-
-    //Integration limits to use in Gaussian quadrature
-    v1a = 0.;
-    v1b = Pi/2;    //theta integration limits
-    v2a = 0.;
-    v2b = Pi/2.;   //phi integration limits
-
-    sumi = 0.0;
-    for(i=0;i<nordi;i++) {
-
-        theta = ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b )/2.0;	//z values for gaussian quadrature
-
-	    arg = q*chalf*cos(theta);
-	    if (fabs(arg) > 1.e-16) {termC1 = sin(arg) / arg;} else {termC1 = 1.0;}
-	    arg = q*(chalf-thickness)*cos(theta);
-	    if (fabs(arg) > 1.e-16) {termC2 = sin(arg) / arg;} else {termC2 = 1.0;}
-
-	    sumj = 0.0;
-	    for(j=0;j<nordj;j++) {
-
-            phi = ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b )/2.0;	//z values for gaussian quadrature
-
-            // Amplitude AP from eqn. (13), rewritten to avoid round-off effects when arg=0
-
-	        arg = q*ahalf*sin(theta)*sin(phi);
-	        if (fabs(arg) > 1.e-16) {termA1 = sin(arg) / arg;} else {termA1 = 1.0;}
-	        arg = q*(ahalf-thickness)*sin(theta)*sin(phi);
-	        if (fabs(arg) > 1.e-16) {termA2 = sin(arg) / arg;} else {termA2 = 1.0;}
-
-	        arg = q*bhalf*sin(theta)*cos(phi);
-	        if (fabs(arg) > 1.e-16) {termB1 = sin(arg) / arg;} else {termB1 = 1.0;}
-	        arg = q*(bhalf-thickness)*sin(theta)*cos(phi);
-	        if (fabs(arg) > 1.e-16) {termB2 = sin(arg) / arg;} else {termB2 = 1.0;}
-
-            AP1 = (aa*bb*cc) * termA1 * termB1 * termC1;
-            AP2 = 8 * (ahalf-thickness) * (bhalf-thickness) * (chalf-thickness) * termA2 * termB2 * termC2;
-            AP = AP1 - AP2;
-
-            sumj += Gauss76Wt[j] * (AP*AP);
-
-	    }
-
-	    sumj = (v2b-v2a) * sumj / 2.0;
-	    sumi += Gauss76Wt[i] * sumj * sin(theta);
-
-    }
-
-    answer = (v1b-v1a)/2.0*sumi;
-
-    // Normalize as in Eqn. (15).
-    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
-    vol = (aa*bb*cc-((aa-2*thickness)*(bb-2*thickness)*(cc-2*thickness)));
-    answer = 2.0 * answer / Pi / vol / vol;
-
-    // Multiply by contrast^2
-    answer *= delrho*delrho;
-
-    //normalize by volume
-    answer *= vol;
-
-    //convert to [cm-1]
-    answer *= 1.0e8;
-
-    //Scale
-    answer *= scale;
-
-    // add in the background
-    answer += bkg;
-
-    return answer;
-}
-
-
Index: src/sas/models/c_extension/libigor/libCylinder.h
===================================================================
--- src/sas/models/c_extension/libigor/libCylinder.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,73 +1,0 @@
-/*
-	libCylinderFit.h -- equates for CylinderFit XOP
-*/
-#if defined(_MSC_VER)
-#include "winFuncs.h"
-#endif
-
-/* Prototypes */
-/* IGOR Fit Functions */
-double CylinderForm(double dp[], double q);
-double EllipCyl76(double dp[], double q);
-double EllipCyl20(double dp[], double q);
-double TriaxialEllipsoid(double dp[], double q);
-double Parallelepiped(double dp[], double q);
-double HollowCylinder(double dp[], double q);
-double EllipsoidForm(double dp[], double q);
-double Cyl_PolyRadius(double dp[], double q);
-double Cyl_PolyLength(double dp[], double q);
-double CoreShellCylinder(double dp[], double q);
-double OblateForm(double dp[], double q);
-double ProlateForm(double dp[], double q);
-double FlexExclVolCyl(double dp[], double q);
-double FlexCyl_PolyLen(double dp[], double q);
-double FlexCyl_PolyRad(double dp[], double q);
-double FlexCyl_Ellip(double dp[], double q);
-double PolyCoShCylinder(double dp[], double q);
-double StackedDiscs(double dp[], double q);
-double LamellarFF(double dp[], double q);
-double LamellarFF_HG(double dp[], double q);
-double LamellarPS(double dp[], double q);
-double LamellarPS_HG(double dp[], double q);
-double Lamellar_ParaCrystal(double dp[], double q);
-double Spherocylinder(double dp[], double q);
-double ConvexLens(double dp[], double q);
-double Dumbbell(double dp[], double q);
-double CappedCylinder(double dp[], double q);
-double Barbell(double dp[], double q);
-double PolyCoreBicelle(double dp[], double q);
-double CSParallelepiped(double dp[], double q);
-double RectangularPrism(double dp[], double q);
-double RectangularHollowPrismInfThinWalls(double dp[], double q);
-double RectangularHollowPrism(double dp[], double q);
-
-/* internal functions */
-double CylKernel(double qq, double rr,double h, double theta);
-double NR_BessJ1(double x);
-double EllipCylKernel(double qq, double ra,double nu, double theta);
-double TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy);
-double PPKernel(double aa, double mu, double uu);
-double HolCylKernel(double qq, double rcore, double rshell, double length, double dum);
-double EllipsoidKernel(double qq, double a, double va, double dum);
-double Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad);
-double SchulzPoint_cpr(double dumRad, double radius, double zz);
-double Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen);
-double CoreShellCylKernel(double qq, double rcore, double thick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi);
-double FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi);
-double EllipticalCross_fn(double qq, double a, double b);
-double CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length);
-double Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N);
-double paraCryst_sn(double ww, double qval, double davg, long nl, double an);
-double paraCryst_an(double ww, double qval, double davg, long nl);
-double SphCyl_kernel(double w[], double x, double tt, double Theta);
-double ConvLens_kernel(double w[], double x, double tt, double theta);
-double Dumb_kernel(double w[], double x, double tt, double theta);
-double BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum);
-double BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length);
-double CSPPKernel(double dp[], double mu, double uu);
-
-
Index: src/sas/models/c_extension/libigor/libSASAnalysis.h
===================================================================
--- src/sas/models/c_extension/libigor/libSASAnalysis.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/*
- *  libSASAnalysis.h
- *  SASAnalysis
- *
- *  Created by Andrew Jackson on 4/24/07.
- *  Copyright 2007 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "libCylinder.h"
-#include "libSphere.h"
-#include "libStructureFactor.h"
-#include "libTwoPhase.h"
-
-/*This should not be necessary AJJ May 09*/
-/* IGOR Fit Functions */
-/*
-double CylinderForm(double dp[], double q);
-double EllipCyl76(double dp[], double q);
-double EllipCyl20(double dp[], double q);
-double TriaxialEllipsoid(double dp[], double q);
-double Parallelepiped(double dp[], double q);
-double HollowCylinder(double dp[], double q);
-double EllipsoidForm(double dp[], double q);
-double Cyl_PolyRadius(double dp[], double q);
-double Cyl_PolyLength(double dp[], double q);
-double CoreShellCylinder(double dp[], double q);
-double OblateForm(double dp[], double q);
-double ProlateForm(double dp[], double q);
-double FlexExclVolCyl(double dp[], double q);
-double FlexCyl_PolyLen(double dp[], double q);
-double FlexCyl_PolyRad(double dp[], double q);
-double FlexCyl_Ellip(double dp[], double q);
-double PolyCoShCylinder(double dp[], double q);
-double StackedDiscs(double dp[], double q);
-double LamellarFF(double dp[], double q);
-double LamellarFF_HG(double dp[], double q);
-double LamellarPS(double dp[], double q);
-double LamellarPS_HG(double dp[], double q);
-//
-double Lamellar_ParaCrystal(double dp[], double q);
-double Spherocylinder(double dp[], double q);
-double ConvexLens(double dp[], double q);
-double Dumbbell(double dp[], double q);
-double CappedCylinder(double dp[], double q);
-double Barbell(double dp[], double q);
-double PolyCoreBicelle(double dp[], double q);
-*/
-
-/* internal functions */
-/*
-double CylKernel(double qq, double rr,double h, double theta);
-double NR_BessJ1(double x);
-double EllipCylKernel(double qq, double ra,double nu, double theta);
-double TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy);
-double PPKernel(double aa, double mu, double uu);
-double HolCylKernel(double qq, double rcore, double rshell, double length, double dum);
-double EllipsoidKernel(double qq, double a, double va, double dum);
-double Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad);
-double SchulzPoint_cpr(double dumRad, double radius, double zz);
-double Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen);
-double CoreShellCylKernel(double qq, double rcore, double thick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi);
-double FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi);
-double EllipticalCross_fn(double qq, double a, double b);
-double CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length);
-double Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N);
-double BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum);
-double BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length);
-*/
-
-
-//
-/* IGOR Fit Functions */
-/*
-double MultiShell(double dp[], double q);
-double PolyMultiShell(double dp[], double q);
-double SphereForm(double dp[], double q);
-double CoreShellForm(double dp[], double q);
-double PolyCoreForm(double dp[], double q);
-double PolyCoreShellRatio(double dp[], double q);
-double VesicleForm(double dp[], double q);
-double SchulzSpheres(double dp[], double q);
-double PolyRectSpheres(double dp[], double q);
-double PolyHardSphereIntensity(double dp[], double q);
-double BimodalSchulzSpheres(double dp[], double q);
-double GaussPolySphere(double dp[], double q);
-double LogNormalPolySphere(double dp[], double q);
-double BinaryHS(double dp[], double q);
-double BinaryHS_PSF11(double dp[], double q);
-double BinaryHS_PSF12(double dp[], double q);
-double BinaryHS_PSF22(double dp[], double q);
-//
-double OneShell(double dp[], double q);
-double TwoShell(double dp[], double q);
-double ThreeShell(double dp[], double q);
-double FourShell(double dp[], double q);
-double PolyOneShell(double dp[], double q);
-double PolyTwoShell(double dp[], double q);
-double PolyThreeShell(double dp[], double q);
-double PolyFourShell(double dp[], double q);
-double BCC_ParaCrystal(double dp[], double q);
-double FCC_ParaCrystal(double dp[], double q);
-double SC_ParaCrystal(double dp[], double q);
-
-//function prototypes
-double F_func(double qr);
-double MultiShellGuts(double q,double rcore,double ts,double tw,double rhocore,double rhoshel,int num);
-double fnt2(double yy, double zz);
-double fnt3(double yy, double pp, double zz);
-double SchulzSphere_Fn(double scale, double ravg, double pd, double rho, double rhos, double x);
-int ashcroft(double qval, double r2, double nf2, double aa, double phi, double *s11, double *s22, double *s12);
-
-
-////
-double HardSphereStruct(double dp[], double q);
-double SquareWellStruct(double dp[], double q);
-double StickyHS_Struct(double dp[], double q);
-double HayterPenfoldMSA(double dp[], double q);
-double DiamCyl(double a, double b);
-double DiamEllip(double a, double b);
-double sqhcal(double qq);
-int sqfun(int ix, int ir);
-int sqcoef(int ir);
-*/
-////
-/* IGOR Fit Functions */
-/*
-double TeubnerStreyModel(double dp[], double q);
-double Power_Law_Model(double dp[], double q);
-double Peak_Lorentz_Model(double dp[], double q);
-double Peak_Gauss_Model(double dp[], double q);
-double Lorentz_Model(double dp[], double q);
-double Fractal(double dp[], double q);
-double DAB_Model(double dp[], double q);
-double OneLevel(double dp[], double q);
-double TwoLevel(double dp[], double q);
-double ThreeLevel(double dp[], double q);
-double FourLevel(double dp[], double q);
-//
-double BroadPeak(double dp[], double q);
-double CorrLength(double dp[], double q);
-double TwoLorentzian(double dp[], double q);
-double TwoPowerLaw(double dp[], double q);
-double PolyGaussCoil(double dp[], double q);
-double GaussLorentzGel(double dp[], double q);
-double GaussianShell(double dp[], double q);
-*/
-
-// since the XOP and the library are separate chunks of compiled code
-// it is imperative to set ALL the structure alignments to be two-byte
-// rather than leave it to the whim of the compiler
-/* SRK08
-#include "XOPStructureAlignmentTwoByte.h"
-
-typedef struct {
-    double scale;
-    double radius;
-    double length;
-    double contrast;
-	double background;    
-    double cyl_theta;
-    double cyl_phi;    
-} CylinderParameters;
-
-typedef struct {
-    double scale;
-    double radius;
-    double length;
-    double contrast;
-	double background;
-    double cyl_theta;
-    double cyl_phi; 
-    double sigma_theta;
-    double sigma_phi;
-    double sigma_radius;
-} SmearCylinderParameters;
-
-#include "XOPStructureAlignmentReset.h"
-
-/// 1D scattering function
-double cylinder_analytical_1D(CylinderParameters *pars, double q);
-/// 2D scattering function
-double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi);
-/// 1D scattering function
-double smeared_cylinder_analytical_1D(SmearCylinderParameters *pars, double q);
-/// 2D scattering function
-double dist_cylinder_2D(double pars[], double q, double phi);
-double smeared_cylinder_analytical_2D(SmearCylinderParameters *pars, double q, double phi);
-double smeared_cylinder_dist( double x, double mean, double sigma );
-*/
Index: src/sas/models/c_extension/libigor/libSphere.c
===================================================================
--- src/sas/models/c_extension/libigor/libSphere.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,2412 +1,0 @@
-/*	SimpleFit.c
-
-A simplified project designed to act as a template for your curve fitting function.
-The fitting function is a simple polynomial. It works but is of no practical use.
-*/
-
-#include "StandardHeaders.h"			// Include ANSI headers, Mac headers
-#include "GaussWeights.h"
-#include "libSphere.h"
-
-
-static double
-gammln(double xx) {
-    double x,y,tmp,ser;
-    static double cof[6]={76.18009172947146,-86.50532032941677,
-    24.01409824083091,-1.231739572450155,
-    0.1208650973866179e-2,-0.5395239384953e-5};
-    int j;
-
-    y=x=xx;
-    tmp=x+5.5;
-    tmp -= (x+0.5)*log(tmp);
-    ser=1.000000000190015;
-    for (j=0;j<=5;j++) ser += cof[j]/++y;
-    return -tmp+log(2.5066282746310005*ser/x);
-}
-
-static double
-LogNormal_distr(double sig, double mu, double pt)
-{
-  double retval,pi;
-
-  pi = 4.0*atan(1.0);
-  retval = (1.0/ (sig*pt*sqrt(2.0*pi)) )*exp( -0.5*(log(pt) - mu)*(log(pt) - mu)/sig/sig );
-  return(retval);
-}
-
-static double
-Gauss_distr(double sig, double avg, double pt)
-{
-  double retval,Pi;
-
-  Pi = 4.0*atan(1.0);
-  retval = (1.0/ (sig*sqrt(2.0*Pi)) )*exp(-(avg-pt)*(avg-pt)/sig/sig/2.0);
-  return(retval);
-}
-
-static double SchulzPoint(double x, double avg, double zz) {
-    double dr;
-    dr = zz*log(x) - gammln(zz+1.0)+(zz+1.0)*log((zz+1.0)/avg)-(x/avg*(zz+1.0));
-    return (exp(dr));
-};
-
-
-// scattering from a sphere - hardly needs to be an XOP...
-double
-SphereForm(double dp[], double q)
-{
-	double scale,radius,delrho,bkg,sldSph,sldSolv;		//my local names
-	double bes,f,vol,f2,pi,qr;
-
-	pi = 4.0*atan(1.0);
-	scale = dp[0];
-	radius = dp[1];
-	sldSph = dp[2];
-	sldSolv = dp[3];
-	bkg = dp[4];
-	
-	delrho = sldSph - sldSolv;
-	//handle qr==0 separately
-	qr = q*radius;
-	if(qr == 0.0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	
-	vol = 4.0*pi/3.0*radius*radius*radius;
-	f = vol*bes*delrho;		// [=] A-1
-							// normalize to single particle volume, convert to 1/cm
-	f2 = f * f / vol * 1.0e8;		// [=] 1/cm
-	
-	return(scale*f2+bkg);	//scale, and add in the background
-}
-
-// scattering from a monodisperse core-shell sphere - hardly needs to be an XOP...
-double
-CoreShellForm(double dp[], double q)
-{
-	double x,pi;
-	double scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	thick = dp[2];
-	rhocore = dp[3];
-	rhoshel = dp[4];
-	rhosolv = dp[5];
-	bkg = dp[6];
-	// core first, then add in shell
-	qr=x*rcore;
-	contr = rhocore-rhoshel;
-	if(qr == 0.0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell
-	qr=x*(rcore+thick);
-	contr = rhoshel-rhosolv;
-	if(qr == 0.0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*pow((rcore+thick),3);
-	f += vol*bes*contr;
-
-	// normalize to particle volume and rescale from [A-1] to [cm-1]
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-// scattering from a unilamellar vesicle - hardly needs to be an XOP...
-// same functional form as the core-shell sphere, but more intuitive for a vesicle
-double
-VesicleForm(double dp[], double q)
-{
-	double x,pi;
-	double scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	thick = dp[2];
-	rhocore = dp[3];
-	rhosolv = rhocore;
-	rhoshel = dp[4];
-	bkg = dp[5];
-	// core first, then add in shell
-	qr=x*rcore;
-	contr = rhocore-rhoshel;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell
-	qr=x*(rcore+thick);
-	contr = rhoshel-rhosolv;
-	if(qr == 0.0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*pow((rcore+thick),3);
-	f += vol*bes*contr;
-
-	// normalize to the particle volume and rescale from [A-1] to [cm-1]
-	//note that for the vesicle model, the volume is ONLY the shell volume
-	vol = 4.0*pi/3.0*(pow((rcore+thick),3)-pow(rcore,3));
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-
-// scattering from a core shell sphere with a (Schulz) polydisperse core and constant shell thickness
-//
-double
-PolyCoreForm(double dp[], double q)
-{
-	double pi;
-	double scale,corrad,sig,zz,del,drho1,drho2,form,bkg;		//my local names
-	double d, g ,h;
-	double qq, x, y, c1, c2, c3, c4, c5, c6, c7, c8, c9, t1, t2, t3;
-	double t4, t5, tb, cy, sy, tb1, tb2, tb3, c2y, zp1, zp2;
-	double zp3,vpoly;
-	double s2y, arg1, arg2, arg3, drh1, drh2;
-	
-	pi = 4.0*atan(1.0);
-	qq= q;
-	scale = dp[0];
-	corrad = dp[1];
-	sig = dp[2];
-	del = dp[3];
-	drho1 = dp[4]-dp[5];		//core-shell
-	drho2 = dp[5]-dp[6];		//shell-solvent
-	bkg = dp[7];
-	
-	zz = (1.0/sig)*(1.0/sig) - 1.0;   
-	
-	h=qq;
-	
-	drh1 = drho1;
-	drh2 = drho2;
-	g = drh2 * -1. / drh1;
-	zp1 = zz + 1.;
-	zp2 = zz + 2.;
-	zp3 = zz + 3.;
-	vpoly = 4*pi/3*zp3*zp2/zp1/zp1*pow((corrad+del),3);
-	
-	
-	// remember that h is the passed in value of q for the calculation
-	y = h *del;
-	x = h *corrad;
-	d = atan(x * 2. / zp1);
-	arg1 = zp1 * d;
-	arg2 = zp2 * d;
-	arg3 = zp3 * d;
-	sy = sin(y);
-	cy = cos(y);
-	s2y = sin(y * 2.);
-	c2y = cos(y * 2.);
-	c1 = .5 - g * (cy + y * sy) + g * g * .5 * (y * y + 1.);
-	c2 = g * y * (g - cy);
-	c3 = (g * g + 1.) * .5 - g * cy;
-	c4 = g * g * (y * cy - sy) * (y * cy - sy) - c1;
-	c5 = g * 2. * sy * (1. - g * (y * sy + cy)) + c2;
-	c6 = c3 - g * g * sy * sy;
-	c7 = g * sy - g * .5 * g * (y * y + 1.) * s2y - c5;
-	c8 = c4 - .5 + g * cy - g * .5 * g * (y * y + 1.) * c2y;
-	c9 = g * sy * (1. - g * cy);
-	
-	tb = log(zp1 * zp1 / (zp1 * zp1 + x * 4. * x));
-	tb1 = exp(zp1 * .5 * tb);
-	tb2 = exp(zp2 * .5 * tb);
-	tb3 = exp(zp3 * .5 * tb);
-	
-	t1 = c1 + c2 * x + c3 * x * x * zp2 / zp1;
-	t2 = tb1 * (c4 * cos(arg1) + c7 * sin(arg1));
-	t3 = x * tb2 * (c5 * cos(arg2) + c8 * sin(arg2));
-	t4 = zp2 / zp1 * x * x * tb3 * (c6 * cos(arg3) + c9 * sin(arg3));
-	t5 = t1 + t2 + t3 + t4;
-	form = t5 * 16. * pi * pi * drh1 * drh1 / pow(qq,6);
-	//	normalize by the average volume !!! corrected for polydispersity
-	// and convert to cm-1
-	form /= vpoly;
-	form *= 1.0e8;
-	//Scale
-	form *= scale;
-	// then add in the background
-	form += bkg;
-	
-	return(form);
-}
-
-// scattering from a uniform sphere with a (Schulz) size distribution
-// structure factor effects are explicitly and correctly included.
-//
-double
-PolyHardSphereIntensity(double dp[], double q)
-{
-	double pi;
-	double rad,z2,phi,cont,bkg,sigma;		//my local names
-	double mu,mu1,d1,d2,d3,d4,d5,d6,capd,rho;
-	double ll,l1,bb,cc,chi,chi1,chi2,ee,t1,t2,t3,pp;
-	double ka,zz,v1,v2,p1,p2;
-	double h1,h2,h3,h4,e1,yy,y1,s1,s2,s3,hint1,hint2;
-	double capl,capl1,capmu,capmu1,r3,pq;
-	double ka2,r1,heff;
-	double hh,k,slds,sld;
-	
-	pi = 4.0*atan(1.0);
-	k= q;
-	
-	rad = dp[0];		// radius (A)
-	z2 = dp[1];		//polydispersity (0<z2<1)
-	phi = dp[2];		// volume fraction (0<phi<1)
-	slds = dp[3];
-	sld = dp[4];
-	cont = (slds - sld)*1.0e4;		// contrast (odd units)
-	bkg = dp[5];
-	sigma = 2*rad;
-	
-	zz=1.0/(z2*z2)-1.0;
-	bb = sigma/(zz+1.0);
-	cc = zz+1.0;
-	
-	//*c   Compute the number density by <r-cubed>, not <r> cubed*/
-	r1 = sigma/2.0;
-	r3 = r1*r1*r1;
-	r3 *= (zz+2.0)*(zz+3.0)/((zz+1.0)*(zz+1.0));
-	rho=phi/(1.3333333333*pi*r3);
-	t1 = rho*bb*cc;
-	t2 = rho*bb*bb*cc*(cc+1.0);
-	t3 = rho*bb*bb*bb*cc*(cc+1.0)*(cc+2.0);
-	capd = 1.0-pi*t3/6.0;
-	//************
-	v1=1.0/(1.0+bb*bb*k*k);
-	v2=1.0/(4.0+bb*bb*k*k);
-	pp=pow(v1,(cc/2.0))*sin(cc*atan(bb*k));
-	p1=bb*cc*pow(v1,((cc+1.0)/2.0))*sin((cc+1.0)*atan(bb*k));
-	p2=cc*(cc+1.0)*bb*bb*pow(v1,((cc+2.0)/2.0))*sin((cc+2.0)*atan(bb*k));
-	mu=pow(2,cc)*pow(v2,(cc/2.0))*sin(cc*atan(bb*k/2.0));
-	mu1=pow(2,(cc+1.0))*bb*cc*pow(v2,((cc+1.0)/2.0))*sin((cc+1.0)*atan(k*bb/2.0));
-	s1=bb*cc;
-	s2=cc*(cc+1.0)*bb*bb;
-	s3=cc*(cc+1.0)*(cc+2.0)*bb*bb*bb;
-	chi=pow(v1,(cc/2.0))*cos(cc*atan(bb*k));
-	chi1=bb*cc*pow(v1,((cc+1.0)/2.0))*cos((cc+1.0)*atan(bb*k));
-	chi2=cc*(cc+1.0)*bb*bb*pow(v1,((cc+2.0)/2.0))*cos((cc+2.0)*atan(bb*k));
-	ll=pow(2,cc)*pow(v2,(cc/2.0))*cos(cc*atan(bb*k/2.0));
-	l1=pow(2,(cc+1.0))*bb*cc*pow(v2,((cc+1.0)/2.0))*cos((cc+1.0)*atan(k*bb/2.0));
-	d1=(pi/capd)*(2.0+(pi/capd)*(t3-(rho/k)*(k*s3-p2)));
-	d2=pow((pi/capd),2)*(rho/k)*(k*s2-p1);
-	d3=(-1.0)*pow((pi/capd),2)*(rho/k)*(k*s1-pp);
-	d4=(pi/capd)*(k-(pi/capd)*(rho/k)*(chi1-s1));
-	d5=pow((pi/capd),2)*((rho/k)*(chi-1.0)+0.5*k*t2);
-	d6=pow((pi/capd),2)*(rho/k)*(chi2-s2);
-	
-	e1=pow((pi/capd),2)*pow((rho/k/k),2)*((chi-1.0)*(chi2-s2)-(chi1-s1)*(chi1-s1)-(k*s1-pp)*(k*s3-p2)+pow((k*s2-p1),2));
-	ee=1.0-(2.0*pi/capd)*(1.0+0.5*pi*t3/capd)*(rho/k/k/k)*(k*s1-pp)-(2.0*pi/capd)*rho/k/k*((chi1-s1)+(0.25*pi*t2/capd)*(chi2-s2))-e1;
-	y1=pow((pi/capd),2)*pow((rho/k/k),2)*((k*s1-pp)*(chi2-s2)-2.0*(k*s2-p1)*(chi1-s1)+(k*s3-p2)*(chi-1.0));
-	yy = (2.0*pi/capd)*(1.0+0.5*pi*t3/capd)*(rho/k/k/k)*(chi+0.5*k*k*s2-1.0)-(2.0*pi*rho/capd/k/k)*(k*s2-p1+(0.25*pi*t2/capd)*(k*s3-p2))-y1;    
-	
-	capl=2.0*pi*cont*rho/k/k/k*(pp-0.5*k*(s1+chi1));
-	capl1=2.0*pi*cont*rho/k/k/k*(p1-0.5*k*(s2+chi2));
-	capmu=2.0*pi*cont*rho/k/k/k*(1.0-chi-0.5*k*p1);
-	capmu1=2.0*pi*cont*rho/k/k/k*(s1-chi1-0.5*k*p2);
-	
-	h1=capl*(capl*(yy*d1-ee*d6)+capl1*(yy*d2-ee*d4)+capmu*(ee*d1+yy*d6)+capmu1*(ee*d2+yy*d4));
-	h2=capl1*(capl*(yy*d2-ee*d4)+capl1*(yy*d3-ee*d5)+capmu*(ee*d2+yy*d4)+capmu1*(ee*d3+yy*d5));
-	h3=capmu*(capl*(ee*d1+yy*d6)+capl1*(ee*d2+yy*d4)+capmu*(ee*d6-yy*d1)+capmu1*(ee*d4-yy*d2));
-	h4=capmu1*(capl*(ee*d2+yy*d4)+capl1*(ee*d3+yy*d5)+capmu*(ee*d4-yy*d2)+capmu1*(ee*d5-yy*d3));
-	
-	//*  This part computes the second integral in equation (1) of the paper.*/
-	
-	hint1 = -2.0*(h1+h2+h3+h4)/(k*k*k*(ee*ee+yy*yy));
-	
-	//*  This part computes the first integral in equation (1).  It also
-	// generates the KC approximated effective structure factor.*/
-	
-	pq=4.0*pi*cont*(sin(k*sigma/2.0)-0.5*k*sigma*cos(k*sigma/2.0));
-	hint2=8.0*pi*pi*rho*cont*cont/(k*k*k*k*k*k)*(1.0-chi-k*p1+0.25*k*k*(s2+chi2));
-	
-	ka=k*(sigma/2.0);
-	//
-	hh=hint1+hint2;		// this is the model intensity
-						//
-	heff=1.0+hint1/hint2;
-	ka2=ka*ka;
-	//*
-	//  heff is PY analytical solution for intensity divided by the 
-	//   form factor.  happ is the KC approximated effective S(q)
-	 
-	 //*******************
-	 //  add in the background then return the intensity value
-	 
-	 return(hh+bkg);	//scale, and add in the background
-}
-
-// scattering from a uniform sphere with a (Schulz) size distribution, bimodal population
-// NO CROSS TERM IS ACCOUNTED FOR == DILUTE SOLUTION!!
-//
-double
-BimodalSchulzSpheres(double dp[], double q)
-{
-	double x,pq;
-	double scale,ravg,pd,bkg,rho,rhos;		//my local names
-	double scale2,ravg2,pd2,rho2;		//my local names
-	
-	x= q;
-	
-	scale = dp[0];
-	ravg = dp[1];
-	pd = dp[2];
-	rho = dp[3];
-	scale2 = dp[4];
-	ravg2 = dp[5];
-	pd2 = dp[6];
-	rho2 = dp[7];
-	rhos = dp[8];
-	bkg = dp[9];
-	
-	pq = SchulzSphere_Fn( scale,  ravg,  pd,  rho,  rhos, x);
-	pq += SchulzSphere_Fn( scale2,  ravg2,  pd2,  rho2,  rhos, x);
-	// add in the background
-	pq += bkg;
-	
-	return (pq);
-}
-
-// scattering from a uniform sphere with a (Schulz) size distribution
-//
-double
-SchulzSpheres(double dp[], double q)
-{
-	double x,pq;
-	double scale,ravg,pd,bkg,rho,rhos;		//my local names
-	
-	x= q;
-	
-	scale = dp[0];
-	ravg = dp[1];
-	pd = dp[2];
-	rho = dp[3];
-	rhos = dp[4];
-	bkg = dp[5];
-	pq = SchulzSphere_Fn( scale,  ravg,  pd,  rho,  rhos, x);
-	// add in the background
-	pq += bkg;
-	
-	return(pq);
-}
-
-// calculates everything but the background
-double
-SchulzSphere_Fn(double scale, double ravg, double pd, double rho, double rhos, double x)
-{
-	double zp1,zp2,zp3,zp4,zp5,zp6,zp7,vpoly;
-	double aa,at1,at2,rt1,rt2,rt3,t1,t2,t3;
-	double v1,v2,v3,g1,pq,pi,delrho,zz;
-	double i_zero,Rg2,zp8;
-	
-	pi = 4.0*atan(1.0);
-	delrho = rho-rhos;
-	zz = (1.0/pd)*(1.0/pd) - 1.0;   
-	
-	zp1 = zz + 1.0;
-	zp2 = zz + 2.0;
-	zp3 = zz + 3.0;
-	zp4 = zz + 4.0;
-	zp5 = zz + 5.0;
-	zp6 = zz + 6.0;
-	zp7 = zz + 7.0;
-	//
-	
-	//small QR limit - use Guinier approx
-	zp8 = zz+8.0;
-	if(x*ravg < 0.1) {
-		i_zero = scale*delrho*delrho*1.e8*4.*pi/3.*pow(ravg,3);
-		i_zero *= zp6*zp5*zp4/zp1/zp1/zp1;		//6th moment / 3rd moment
-		Rg2 = 3.*zp8*zp7/5./(zp1*zp1)*ravg*ravg;
-		pq = i_zero*exp(-x*x*Rg2/3.);
-		//pq += bkg;		//unlike the Igor code, the backgorund is added in the wrapper (above)
-		return(pq);
-	}
-	//
-
-	aa = (zz+1.0)/x/ravg;
-	
-	at1 = atan(1.0/aa);
-	at2 = atan(2.0/aa);
-	//
-	//  calculations are performed to avoid  large # errors
-	// - trick is to propogate the a^(z+7) term through the g1
-	// 
-	t1 = zp7*log10(aa) - zp1/2.0*log10(aa*aa+4.0);
-	t2 = zp7*log10(aa) - zp3/2.0*log10(aa*aa+4.0);
-	t3 = zp7*log10(aa) - zp2/2.0*log10(aa*aa+4.0);
-	//	print t1,t2,t3
-	rt1 = pow(10,t1);
-	rt2 = pow(10,t2);
-	rt3 = pow(10,t3);
-	v1 = pow(aa,6) - rt1*cos(zp1*at2);
-	v2 = zp1*zp2*( pow(aa,4) + rt2*cos(zp3*at2) );
-	v3 = -2.0*zp1*rt3*sin(zp2*at2);
-	g1 = (v1+v2+v3);
-	
-	pq = log10(g1) - 6.0*log10(zp1) + 6.0*log10(ravg);
-	pq = pow(10,pq)*8.0*pi*pi*delrho*delrho;
-	
-	//
-	// beta factor is not used here, but could be for the 
-	// decoupling approximation
-	// 
-	//	g11 = g1
-	//	gd = -zp7*log(aa)
-	//	g1 = log(g11) + gd
-	//                       
-	//	t1 = zp1*at1
-	//	t2 = zp2*at1
-	//	g2 = sin( t1 ) - zp1/sqrt(aa*aa+1)*cos( t2 )
-	//	g22 = g2*g2
-	//	beta = zp1*log(aa) - zp1*log(aa*aa+1) - g1 + log(g22) 
-	//	beta = 2*alog(beta)
-	
-	//re-normalize by the average volume
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*ravg*ravg*ravg;
-	pq /= vpoly;
-	//scale, convert to cm^-1
-	pq *= scale * 1.0e8;
-    
-    return(pq);
-}
-
-// scattering from a uniform sphere with a rectangular size distribution
-//
-double
-PolyRectSpheres(double dp[], double q)
-{
-	double pi,x;
-	double scale,rad,pd,cont,bkg;		//my local names
-	double inten,h1,qw,qr,width,sig,averad3,Rg2,slds,sld;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale = dp[0];
-	rad = dp[1];		// radius (A)
-	pd = dp[2];		//polydispersity of rectangular distribution
-	slds = dp[3];
-	sld = dp[4];
-	cont = slds - sld;		// contrast (A^-2)
-	bkg = dp[5];
-	
-	// as usual, poly = sig/ravg
-	// for the rectangular distribution, sig = width/sqrt(3)
-	// width is the HALF- WIDTH of the rectangular distrubution
-	
-	sig = pd*rad;
-	width = sqrt(3.0)*sig;
-	
-	//x is the q-value
-	qw = x*width;
-	qr = x*rad;
-	
-	// as for the numerical inatabilities at low QR, the function is calculating the sines and cosines
-	// just fine - the problem seems to be that the 
-	// leading terms nearly cancel with the last term (the -6*qr... term), to within machine
-	// precision - the difference is on the order of 10^-20
-	// so just use the limiting Guiner value
-	if(qr<0.1) {
-		h1 = scale*cont*cont*1.e8*4.*pi/3.0*pow(rad,3);
-		h1 *= 	(1. + 15.*pow(pd,2) + 27.*pow(pd,4) +27./7.*pow(pd,6) );				//6th moment
-		h1 /= (1.+3.*pd*pd);	//3rd moment
-		Rg2 = 3.0/5.0*rad*rad*( 1.+28.*pow(pd,2)+126.*pow(pd,4)+108.*pow(pd,6)+27.*pow(pd,8) );
-		Rg2 /= (1.+15.*pow(pd,2)+27.*pow(pd,4)+27./7.*pow(pd,6));
-		h1 *= exp(-1./3.*Rg2*x*x);
-		h1 += bkg;
-		return(h1);
-	}
-	
-	// normal calculation
-	h1 = -0.5*qw + qr*qr*qw + (qw*qw*qw)/3.0;
-	h1 -= 5.0/2.0*cos(2.0*qr)*sin(qw)*cos(qw);
-	h1 += 0.5*qr*qr*cos(2.0*qr)*sin(2.0*qw);
-	h1 += 0.5*qw*qw*cos(2.0*qr)*sin(2.0*qw);
-	h1 += qw*qr*sin(2.0*qr)*cos(2.0*qw);
-	h1 += 3.0*qw*(cos(qr)*cos(qw))*(cos(qr)*cos(qw));
-	h1+= 3.0*qw*(sin(qr)*sin(qw))*(sin(qr)*sin(qw));
-	h1 -= 6.0*qr*cos(qr)*sin(qr)*cos(qw)*sin(qw);
-	
-	// calculate P(q) = <f^2>
-	inten = 8.0*pi*pi*cont*cont/width/pow(x,7)*h1;
-	
-	// beta(q) would be calculated as 2/width/x/h1*h2*h2
-	// with 
-	// h2 = 2*sin(x*rad)*sin(x*width)-x*rad*cos(x*rad)*sin(x*width)-x*width*sin(x*rad)*cos(x*width)
-	
-	// normalize to the average volume
-	// <R^3> = ravg^3*(1+3*pd^2)
-	// or... "zf"  = (1 + 3*p^2), which will be greater than one
-	
-	averad3 =  rad*rad*rad*(1.0+3.0*pd*pd);
-	inten /= 4.0*pi/3.0*averad3;
-	//resacle to 1/cm
-	inten *= 1.0e8;
-	//scale the result
-	inten *= scale;
-	// then add in the background
-	inten += bkg;
-	
-	return(inten);
-}
-
-
-// scattering from a uniform sphere with a Gaussian size distribution
-//
-double
-GaussPolySphere(double dp[], double q)
-{
-	double pi,x;
-	double scale,rad,pd,sig,rho,rhos,bkg,delrho;		//my local names
-	double va,vb,zi,yy,summ,inten;
-	int nord=20,ii;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale=dp[0];
-	rad=dp[1];
-	pd=dp[2];
-	sig=pd*rad;
-	rho=dp[3];
-	rhos=dp[4];
-	delrho=rho-rhos;
-	bkg=dp[5];
-	
-	va = -4.0*sig + rad;
-	if (va<0.0) {
-		va=0.0;		//to avoid numerical error when  va<0 (-ve q-value)
-	}
-	vb = 4.0*sig +rad;
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss20Z[ii]*(vb-va) + vb + va )/2.0;
-		// calculate sphere scattering
-		//return(3*(sin(qr) - qr*cos(qr))/(qr*qr*qr)); pass qr
-		yy = F_func(x*zi)*(4.0*pi/3.0*zi*zi*zi)*delrho;
-		yy *= yy;
-		yy *= Gauss20Wt[ii] *  Gauss_distr(sig,rad,zi);
-		
-		summ += yy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	inten = (vb-va)/2.0*summ;
-	
-	//re-normalize by polydisperse sphere volume
-	inten /= (4.0*pi/3.0*rad*rad*rad)*(1.0+3.0*pd*pd);
-	
-	inten *= 1.0e8;
-	inten *= scale;
-	inten += bkg;
-	
-    return(inten);	//scale, and add in the background
-}
-
-// scattering from a uniform sphere with a LogNormal size distribution
-//
-double
-LogNormalPolySphere(double dp[], double q)
-{
-	double pi,x;
-	double scale,rad,sig,rho,rhos,bkg,delrho,mu,r3;		//my local names
-	double va,vb,zi,yy,summ,inten;
-	int nord=76,ii;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale=dp[0];
-	rad=dp[1];		//rad is the median radius
-	mu = log(dp[1]);
-	sig=dp[2];
-	rho=dp[3];
-	rhos=dp[4];
-	delrho=rho-rhos;
-	bkg=dp[5];
-	
-	va = -3.5*sig + mu;
-	va = exp(va);
-	if (va<0.0) {
-		va=0.0;		//to avoid numerical error when  va<0 (-ve q-value)
-	}
-	vb = 3.5*sig*(1.0+sig) +mu;
-	vb = exp(vb);
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss76Z[ii]*(vb-va) + vb + va )/2.0;
-		// calculate sphere scattering
-		//return(3*(sin(qr) - qr*cos(qr))/(qr*qr*qr)); pass qr
-		yy = F_func(x*zi)*(4.0*pi/3.0*zi*zi*zi)*delrho;
-		yy *= yy;
-		yy *= Gauss76Wt[ii] *  LogNormal_distr(sig,mu,zi);
-		
-		summ += yy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	inten = (vb-va)/2.0*summ;
-	
-	//re-normalize by polydisperse sphere volume
-	r3 = exp(3.0*mu + 9.0/2.0*sig*sig);		// <R^3> directly
-	inten /= (4.0*pi/3.0*r3);		//polydisperse volume
-	
-	inten *= 1.0e8;
-	inten *= scale;
-	inten += bkg;
-	
-	return(inten);
-}
-
-/*
-static double
-LogNormal_distr(double sig, double mu, double pt)
-{	
-	double retval,pi;
-	
-	pi = 4.0*atan(1.0);
-	retval = (1.0/ (sig*pt*sqrt(2.0*pi)) )*exp( -0.5*(log(pt) - mu)*(log(pt) - mu)/sig/sig );
-	return(retval);
-}
-
-static double
-Gauss_distr(double sig, double avg, double pt)
-{	
-	double retval,Pi;
-	
-	Pi = 4.0*atan(1.0);
-	retval = (1.0/ (sig*sqrt(2.0*Pi)) )*exp(-(avg-pt)*(avg-pt)/sig/sig/2.0);
-	return(retval);
-}
-*/
-
-// scattering from a core shell sphere with a (Schulz) polydisperse core and constant ratio (shell thickness)/(core radius)
-// - the polydispersity is of the WHOLE sphere
-//
-double
-PolyCoreShellRatio(double dp[], double q)
-{
-	double pi,x;
-	double scale,corrad,thick,shlrad,pp,drho1,drho2,sig,zz,bkg;		//my local names
-	double sld1,sld2,sld3,zp1,zp2,zp3,vpoly;
-	double pi43,c1,c2,form,volume,arg1,arg2;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale = dp[0];
-	corrad = dp[1];
-	thick = dp[2];
-	sig = dp[3];
-	sld1 = dp[4];
-	sld2 = dp[5];
-	sld3 = dp[6];
-	bkg = dp[7];
-	
-	zz = (1.0/sig)*(1.0/sig) - 1.0;   
-	shlrad = corrad + thick;
-	drho1 = sld1-sld2;		//core-shell
-	drho2 = sld2-sld3;		//shell-solvent
-	zp1 = zz + 1.;
-	zp2 = zz + 2.;
-	zp3 = zz + 3.;
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*pow((corrad+thick),3);
-	
-	// the beta factor is not calculated
- 	// the calculated form factor <f^2> has units [length^2]
- 	// and must be multiplied by number density [l^-3] and the correct unit
- 	// conversion to get to absolute scale
-	
-	pi43=4.0/3.0*pi;
- 	pp=corrad/shlrad;
- 	volume=pi43*shlrad*shlrad*shlrad;
- 	c1=drho1*volume;
- 	c2=drho2*volume;
-	
-	arg1 = x*shlrad*pp;
-	arg2 = x*shlrad;
-	
-	form=pow(pp,6)*c1*c1*fnt2(arg1,zz);
-	form += c2*c2*fnt2(arg2,zz);
-	form += 2.0*c1*c2*fnt3(arg2,pp,zz);
-	
-	//convert the result to [cm^-1]
-	
-	//scale the result
-	// - divide by the polydisperse volume, mult by 10^8
-	form  /= vpoly;
-	form *= 1.0e8;
-	form *= scale;
-	
-	//add in the background
-	form += bkg;
-	
-	return(form);
-}
-
-//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-//c
-//c      function fnt2(y,z)
-//c
-double
-fnt2(double yy, double zz)
-{
-	double z1,z2,z3,u,ww,term1,term2,term3,ans;
-	
-	z1=zz+1.0;
-	z2=zz+2.0;
-	z3=zz+3.0;
-	u=yy/z1;
-	ww=atan(2.0*u);
-	term1=cos(z1*ww)/pow((1.0+4.0*u*u),(z1/2.0));
-	term2=2.0*yy*sin(z2*ww)/pow((1.0+4.0*u*u),(z2/2.0));
-	term3=1.0+cos(z3*ww)/pow((1.0+4.0*u*u),(z3/2.0));
-	ans=(4.50/z1/pow(yy,6))*(z1*(1.0-term1-term2)+yy*yy*z2*term3);
-	
-	return(ans);
-}
-
-//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
-//c
-//c      function fnt3(y,p,z)
-//c
-double
-fnt3(double yy, double pp, double zz)
-{     	
-	double z1,z2,z3,yp,yn,up,un,vp,vn,term1,term2,term3,term4,term5,term6,ans;
-	
-	z1=zz+1.0;
-	z2=zz+2.0;
-	z3=zz+3.0;
-	yp=(1.0+pp)*yy;
-	yn=(1.0-pp)*yy;
-	up=yp/z1;
-	un=yn/z1;
-	vp=atan(up);
-	vn=atan(un);
-	term1=cos(z1*vn)/pow((1.0+un*un),(z1/2.0));
-	term2=cos(z1*vp)/pow((1.0+up*up),(z1/2.0));
-	term3=cos(z3*vn)/pow((1.0+un*un),(z3/2.0));
-	term4=cos(z3*vp)/pow((1.0+up*up),(z3/2.0));
-	term5=yn*sin(z2*vn)/pow((1.0+un*un),(z2/2.0));
-	term6=yp*sin(z2*vp)/pow((1.0+up*up),(z2/2.0));
-	ans=4.5/z1/pow(yy,6);
-	ans *=(z1*(term1-term2)+yy*yy*pp*z2*(term3+term4)+z1*(term5-term6));
-	
-	return(ans);
-}
-
-// scattering from a a binary population of hard spheres, 3 partial structure factors
-// are properly accounted for...
-//	 Input (fitting) variables are:
-//	larger sphere radius(angstroms) = guess[0]
-// 	smaller sphere radius (A) = w[1]
-//	number fraction of larger spheres = guess[2]
-//	total volume fraction of spheres = guess[3]
-//	size ratio, alpha(0<a<1) = derived
-//	SLD(A-2) of larger particle = guess[4]
-//	SLD(A-2) of smaller particle = guess[5]
-//	SLD(A-2) of the solvent = guess[6]
-//	background = guess[7]
-double
-BinaryHS(double dp[], double q)
-{
-	double x,pi;
-	double r2,r1,nf2,phi,aa,rho2,rho1,rhos,inten,bgd;		//my local names
-	double psf11,psf12,psf22;
-	double phi1,phi2,phr,a3;
-	double v1,v2,n1,n2,qr1,qr2,b1,b2,sc1,sc2;
-	int err;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	r2 = dp[0];
-	r1 = dp[1];
-	phi2 = dp[2];
-	phi1 = dp[3];
-	rho2 = dp[4];
-	rho1 = dp[5];
-	rhos = dp[6];
-	bgd = dp[7];
-	
-	
-	phi = phi1 + phi2;
-	aa = r1/r2;
-	//calculate the number fraction of larger spheres (eqn 2 in reference)
-	a3=aa*aa*aa;
-	phr=phi2/phi;
-	nf2 = phr*a3/(1.0-phr+phr*a3);
-	// calculate the PSF's here
-	err = ashcroft(x,r2,nf2,aa,phi,&psf11,&psf22,&psf12);
-	
-	// /* do form factor calculations  */
-	
-	v1 = 4.0*pi/3.0*r1*r1*r1;
-	v2 = 4.0*pi/3.0*r2*r2*r2;
-	
-	n1 = phi1/v1;
-	n2 = phi2/v2;
-	
-	qr1 = r1*x;
-	qr2 = r2*x;
-
-	if (qr1 == 0){
-		sc1 = 1.0/3.0;
-	}else{
-		sc1 = (sin(qr1)-qr1*cos(qr1))/qr1/qr1/qr1;
-	}
-	if (qr2 == 0){
-		sc2 = 1.0/3.0;
-	}else{
-		sc2 = (sin(qr2)-qr2*cos(qr2))/qr2/qr2/qr2;
-	}
-	b1 = r1*r1*r1*(rho1-rhos)*4.0*pi*sc1;
-	b2 = r2*r2*r2*(rho2-rhos)*4.0*pi*sc2;
-	inten = n1*b1*b1*psf11;
-	inten += sqrt(n1*n2)*2.0*b1*b2*psf12;
-	inten += n2*b2*b2*psf22;
-	///* convert I(1/A) to (1/cm)  */
-	inten *= 1.0e8;
-	
-	inten += bgd;
-	
-	return(inten);
-}
-
-double
-BinaryHS_PSF11(double dp[], double q)
-{
-	double x,pi;
-	double r2,r1,nf2,phi,aa,rho2,rho1,rhos,bgd;		//my local names
-	double psf11,psf12,psf22;
-	double phi1,phi2,phr,a3;
-	int err;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	r2 = dp[0];
-	r1 = dp[1];
-	phi2 = dp[2];
-	phi1 = dp[3];
-	rho2 = dp[4];
-	rho1 = dp[5];
-	rhos = dp[6];
-	bgd = dp[7];
-	phi = phi1 + phi2;
-	aa = r1/r2;
-	//calculate the number fraction of larger spheres (eqn 2 in reference)
-	a3=aa*aa*aa;
-	phr=phi2/phi;
-	nf2 = phr*a3/(1.0-phr+phr*a3);
-	// calculate the PSF's here
-	err = ashcroft(x,r2,nf2,aa,phi,&psf11,&psf22,&psf12);
-	
-    return(psf11);	//scale, and add in the background
-}
-
-double
-BinaryHS_PSF12(double dp[], double q)
-{
-	double x,pi;
-	double r2,r1,nf2,phi,aa,rho2,rho1,rhos,bgd;		//my local names
-	double psf11,psf12,psf22;
-	double phi1,phi2,phr,a3;
-	int err;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	r2 = dp[0];
-	r1 = dp[1];
-	phi2 = dp[2];
-	phi1 = dp[3];
-	rho2 = dp[4];
-	rho1 = dp[5];
-	rhos = dp[6];
-	bgd = dp[7];
-	phi = phi1 + phi2;
-	aa = r1/r2;
-	//calculate the number fraction of larger spheres (eqn 2 in reference)
-	a3=aa*aa*aa;
-	phr=phi2/phi;
-	nf2 = phr*a3/(1.0-phr+phr*a3);
-	// calculate the PSF's here
-	err = ashcroft(x,r2,nf2,aa,phi,&psf11,&psf22,&psf12);
-	
-    return(psf12);	//scale, and add in the background
-}
-
-double
-BinaryHS_PSF22(double dp[], double q)
-{
-	double x,pi;
-	double r2,r1,nf2,phi,aa,rho2,rho1,rhos,bgd;		//my local names
-	double psf11,psf12,psf22;
-	double phi1,phi2,phr,a3;
-	int err;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	r2 = dp[0];
-	r1 = dp[1];
-	phi2 = dp[2];
-	phi1 = dp[3];
-	rho2 = dp[4];
-	rho1 = dp[5];
-	rhos = dp[6];
-	bgd = dp[7];
-	phi = phi1 + phi2;
-	aa = r1/r2;
-	//calculate the number fraction of larger spheres (eqn 2 in reference)
-	a3=aa*aa*aa;
-	phr=phi2/phi;
-	nf2 = phr*a3/(1.0-phr+phr*a3);
-	// calculate the PSF's here
-	err = ashcroft(x,r2,nf2,aa,phi,&psf11,&psf22,&psf12);
-	
-    return(psf22);	//scale, and add in the background
-}
-
-int
-ashcroft(double qval, double r2, double nf2, double aa, double phi, double *s11, double *s22, double *s12)
-{
-	//	variable qval,r2,nf2,aa,phi,&s11,&s22,&s12
-	
-	//   calculate constant terms
-	double s1,s2,v,a3,v1,v2,g11,g12,g22,wmv,wmv3,wmv4;
-	double a1,a2i,a2,b1,b2,b12,gm1,gm12;
-	double err=0.0,yy,ay,ay2,ay3,t1,t2,t3,f11,y2,y3,tt1,tt2,tt3;
-	double c11,c22,c12,f12,f22,ttt1,ttt2,ttt3,ttt4,yl,y13;
-	double t21,t22,t23,t31,t32,t33,t41,t42,yl3,wma3,y1;
-	
-	s2 = 2.0*r2;
-	s1 = aa*s2;
-	v = phi;
-	a3 = aa*aa*aa;
-	v1=((1.-nf2)*a3/(nf2+(1.-nf2)*a3))*v;
-	v2=(nf2/(nf2+(1.-nf2)*a3))*v;
-	g11=((1.+.5*v)+1.5*v2*(aa-1.))/(1.-v)/(1.-v);
-	g22=((1.+.5*v)+1.5*v1*(1./aa-1.))/(1.-v)/(1.-v);
-	g12=((1.+.5*v)+1.5*(1.-aa)*(v1-v2)/(1.+aa))/(1.-v)/(1.-v);
-	wmv = 1/(1.-v);
-	wmv3 = wmv*wmv*wmv;
-	wmv4 = wmv*wmv3;
-	a1=3.*wmv4*((v1+a3*v2)*(1.+v+v*v)-3.*v1*v2*(1.-aa)*(1.-aa)*(1.+v1+aa*(1.+v2))) + ((v1+a3*v2)*(1.+2.*v)+(1.+v+v*v)-3.*v1*v2*(1.-aa)*(1.-aa)-3.*v2*(1.-aa)*(1.-aa)*(1.+v1+aa*(1.+v2)))*wmv3;
-	a2i=((v1+a3*v2)*(1.+v+v*v)-3.*v1*v2*(1.-aa)*(1.-aa)*(1.+v1+aa*(1.+v2)))*3*wmv4 + ((v1+a3*v2)*(1.+2.*v)+a3*(1.+v+v*v)-3.*v1*v2*(1.-aa)*(1.-aa)*aa-3.*v1*(1.-aa)*(1.-aa)*(1.+v1+aa*(1.+v2)))*wmv3;
-	a2=a2i/a3;
-	b1=-6.*(v1*g11*g11+.25*v2*(1.+aa)*(1.+aa)*aa*g12*g12);
-	b2=-6.*(v2*g22*g22+.25*v1/a3*(1.+aa)*(1.+aa)*g12*g12);
-	b12=-3.*aa*(1.+aa)*(v1*g11/aa/aa+v2*g22)*g12;
-	gm1=(v1*a1+a3*v2*a2)*.5;
-	gm12=2.*gm1*(1.-aa)/aa;
-	//c  
-	//c   calculate the direct correlation functions and print results
-	//c
-	//	do 20 j=1,npts
-	
-	yy=qval*s2;
-	//c   calculate direct correlation functions
-	//c   ----c11
-	ay=aa*yy;
-	ay2 = ay*ay;
-	ay3 = ay*ay*ay;
-	t1=a1*(sin(ay)-ay*cos(ay));
-	t2=b1*(2.*ay*sin(ay)-(ay2-2.)*cos(ay)-2.)/ay;
-	t3=gm1*((4.*ay*ay2-24.*ay)*sin(ay)-(ay2*ay2-12.*ay2+24.)*cos(ay)+24.)/ay3;
-	f11=24.*v1*(t1+t2+t3)/ay3;
-	
-	//c ------c22
-	y2=yy*yy;
-	y3=yy*y2;
-	tt1=a2*(sin(yy)-yy*cos(yy));
-	tt2=b2*(2.*yy*sin(yy)-(y2-2.)*cos(yy)-2.)/yy;
-	tt3=gm1*((4.*y3-24.*yy)*sin(yy)-(y2*y2-12.*y2+24.)*cos(yy)+24.)/ay3;
-	f22=24.*v2*(tt1+tt2+tt3)/y3;
-	
-	//c   -----c12
-	yl=.5*yy*(1.-aa);
-	yl3=yl*yl*yl;
-	wma3 = (1.-aa)*(1.-aa)*(1.-aa);
-	y1=aa*yy;
-	y13 = y1*y1*y1;
-	ttt1=3.*wma3*v*sqrt(nf2)*sqrt(1.-nf2)*a1*(sin(yl)-yl*cos(yl))/((nf2+(1.-nf2)*a3)*yl3);
-	t21=b12*(2.*y1*cos(y1)+(y1*y1-2.)*sin(y1));
-	t22=gm12*((3.*y1*y1-6.)*cos(y1)+(y1*y1*y1-6.*y1)*sin(y1)+6.)/y1;
-	t23=gm1*((4.*y13-24.*y1)*cos(y1)+(y13*y1-12.*y1*y1+24.)*sin(y1))/(y1*y1);
-	t31=b12*(2.*y1*sin(y1)-(y1*y1-2.)*cos(y1)-2.);
-	t32=gm12*((3.*y1*y1-6.)*sin(y1)-(y1*y1*y1-6.*y1)*cos(y1))/y1;
-  	t33=gm1*((4.*y13-24.*y1)*sin(y1)-(y13*y1-12.*y1*y1+24.)*cos(y1)+24.)/(y1*y1);
-	t41=cos(yl)*((sin(y1)-y1*cos(y1))/(y1*y1) + (1.-aa)/(2.*aa)*(1.-cos(y1))/y1);
-	t42=sin(yl)*((cos(y1)+y1*sin(y1)-1.)/(y1*y1) + (1.-aa)/(2.*aa)*sin(y1)/y1);
-	ttt2=sin(yl)*(t21+t22+t23)/(y13*y1);
-	ttt3=cos(yl)*(t31+t32+t33)/(y13*y1);
-	ttt4=a1*(t41+t42)/y1;
-	f12=ttt1+24.*v*sqrt(nf2)*sqrt(1.-nf2)*a3*(ttt2+ttt3+ttt4)/(nf2+(1.-nf2)*a3);
-	
-	c11=f11;
-	c22=f22;
-	c12=f12;
-	*s11=1./(1.+c11-(c12)*c12/(1.+c22));
-	*s22=1./(1.+c22-(c12)*c12/(1.+c11)); 
-	*s12=-c12/((1.+c11)*(1.+c22)-(c12)*(c12));   
-	
-	return(err);
-}
-
-
-
-/*
- // calculates the scattering from a spherical particle made up of a core (aqueous) surrounded
- // by N spherical layers, each of which is a PAIR of shells, solvent + surfactant since there
- //must always be a surfactant layer on the outside
- //
- // bragg peaks arise naturally from the periodicity of the sample
- // resolution smeared version gives he most appropriate view of the model
- 
-	Warning:
- The call to WaveData() below returns a pointer to the middle
- of an unlocked Macintosh handle. In the unlikely event that your
- calculations could cause memory to move, you should copy the coefficient
- values to local variables or an array before such operations.
- */
-double
-MultiShell(double dp[], double q)
-{
-	double x;
-	double scale,rcore,tw,ts,rhocore,rhoshel,num,bkg;		//my local names
-	int ii;
-	double fval,voli,ri,sldi;
-	double pi;
-	
-	pi = 4.0*atan(1.0);
-	
-	x= q;
-	scale = dp[0];
-	rcore = dp[1];
-	ts = dp[2];
-	tw = dp[3];
-	rhocore = dp[4];
-	rhoshel = dp[5];
-	num = dp[6];
-	bkg = dp[7];
-	
-	//calculate with a loop, two shells at a time
-	
-	ii=0;
-	fval=0.0;
-	
-	do {
-		ri = rcore + (double)ii*ts + (double)ii*tw;
-		voli = 4.0*pi/3.0*ri*ri*ri;
-		sldi = rhocore-rhoshel;
-		fval += voli*sldi*F_func(ri*x);
-		ri += ts;
-		voli = 4.0*pi/3.0*ri*ri*ri;
-		sldi = rhoshel-rhocore;
-		fval += voli*sldi*F_func(ri*x);
-		ii+=1;		//do 2 layers at a time
-	} while(ii<=num-1);  //change to make 0 < num < 2 correspond to unilamellar vesicles (C. Glinka, 11/24/03)
-	
-	fval *= fval;		//square it
-	fval /= voli;		//normalize by the overall volume
-	fval *= scale*1.0e8;
-	fval += bkg;
-	
-	return(fval);
-}
-
-/*
- // calculates the scattering from a POLYDISPERSE spherical particle made up of a core (aqueous) surrounded
- // by N spherical layers, each of which is a PAIR of shells, solvent + surfactant since there
- //must always be a surfactant layer on the outside
- //
- // bragg peaks arise naturally from the periodicity of the sample
- // resolution smeared version gives he most appropriate view of the model
- //
- // Polydispersity is of the total (outer) radius. This is converted into a distribution of MLV's
- // with integer numbers of layers, with a minimum of one layer... a vesicle... depending
- // on the parameters, the "distribution" of MLV's that is used may be truncated
- //
-	Warning:
- The call to WaveData() below returns a pointer to the middle
- of an unlocked Macintosh handle. In the unlikely event that your
- calculations could cause memory to move, you should copy the coefficient
- values to local variables or an array before such operations.
- */
-double
-PolyMultiShell(double dp[], double q)
-{
-	double x;
-	double scale,rcore,tw,ts,rhocore,rhoshel,bkg;		//my local names
-	int ii,minPairs,maxPairs,first;
-	double fval,ri,pi;
-	double avg,pd,zz,lo,hi,r1,r2,d1,d2,distr;
-	
-	pi = 4.0*atan(1.0);	
-	x= q;
-	
-	scale = dp[0];
-	avg = dp[1];		// average (total) outer radius
-	pd = dp[2];
-	rcore = dp[3];
-	ts = dp[4];
-	tw = dp[5];
-	rhocore = dp[6];
-	rhoshel = dp[7];
-	bkg = dp[8];
-	
-	zz = (1.0/pd)*(1.0/pd)-1.0;
-	
-	//max radius set to be 5 std deviations past mean
-	hi = avg + pd*avg*5.0;
-	lo = avg - pd*avg*5.0;
-	
-	maxPairs = trunc( (hi-rcore+tw)/(ts+tw) );
-	minPairs = trunc( (lo-rcore+tw)/(ts+tw) );
-	minPairs = (minPairs < 1) ? 1 : minPairs;	// need a minimum of one
-	
-	ii=minPairs;
-	fval=0.0;
-	d1 = 0.0;
-	d2 = 0.0;
-	r1 = 0.0;
-	r2 = 0.0;
-	distr = 0.0;
-	first = 1.0;
-	do {
-		//make the current values old
-		r1 = r2;
-		d1 = d2;
-		
-		ri = (double)ii*(ts+tw) - tw + rcore;
-		fval += SchulzPoint(ri,avg,zz) * MultiShellGuts(x, rcore, ts, tw, rhocore, rhoshel, ii) * (4*pi/3*ri*ri*ri);
-		// get a running integration of the fraction of the distribution used, but not the first time
-		r2 = ri;
-		d2 = SchulzPoint(ri,avg,zz);
-		if( !first ) {
-			distr += 0.5*(d1+d2)*(r2-r1);		//cheap trapezoidal integration
-		}
-		ii+=1;
-		first = 0;
-	} while(ii<=maxPairs);
-	
-	fval /= 4.0*pi/3.0*avg*avg*avg;		//normalize by the overall volume
-	fval /= distr;
-	fval *= scale;
-	fval += bkg;
-	
-	return(fval);
-}
-
-double
-MultiShellGuts(double x,double rcore,double ts,double tw,double rhocore,double rhoshel,int num) {
-	
-    double ri,sldi,fval,voli,pi;
-    int ii;
-    
-	pi = 4.0*atan(1.0);
-    ii=0;
-    fval=0.0;
-    
-    do {
-        ri = rcore + (double)ii*ts + (double)ii*tw;
-        voli = 4.0*pi/3.0*ri*ri*ri;
-        sldi = rhocore-rhoshel;
-        fval += voli*sldi*F_func(ri*x);
-        ri += ts;
-        voli = 4.0*pi/3.0*ri*ri*ri;
-        sldi = rhoshel-rhocore;
-        fval += voli*sldi*F_func(ri*x);
-        ii+=1;		//do 2 layers at a time
-    } while(ii<=num-1);  //change to make 0 < num < 2 correspond to unilamellar vesicles (C. Glinka, 11/24/03)
-    
-    fval *= fval;
-    fval /= voli;
-    fval *= 1.0e8;
-    
-    return(fval);	// this result still needs to be multiplied by scale and have background added
-}
-
-/*
-static double
-SchulzPoint(double x, double avg, double zz) {
-	
-    double dr;
-    
-    dr = zz*log(x) - gammln(zz+1.0)+(zz+1.0)*log((zz+1.0)/avg)-(x/avg*(zz+1.0));
-    return (exp(dr));
-}
-
-static double
-gammln(double xx) {
-	
-    double x,y,tmp,ser;
-    static double cof[6]={76.18009172947146,-86.50532032941677,
-		24.01409824083091,-1.231739572450155,
-		0.1208650973866179e-2,-0.5395239384953e-5};
-    int j;
-	
-    y=x=xx;
-    tmp=x+5.5;
-    tmp -= (x+0.5)*log(tmp);
-    ser=1.000000000190015;
-    for (j=0;j<=5;j++) ser += cof[j]/++y;
-    return -tmp+log(2.5066282746310005*ser/x);
-}
-*/
-
-double
-F_func(double qr) {
-	double sc;
-	if (qr == 0.0){
-		sc = 1.0;
-	}else{
-		sc=(3.0*(sin(qr) - qr*cos(qr))/(qr*qr*qr));
-	}
-	return sc;
-}
-
-double
-OneShell(double dp[], double q)
-{
-	// variables are:
-	//[0] scale factor
-	//[1] radius of core [ï¿œ]
-	//[2] SLD of the core	[ï¿œ-2]
-	//[3] thickness of the shell	[ï¿œ]
-	//[4] SLD of the shell
-	//[5] SLD of the solvent
-	//[6] background	[cm-1]
-	
-	double x,pi;
-	double scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	rhocore = dp[2];
-	thick = dp[3];
-	rhoshel = dp[4];
-	rhosolv = dp[5];
-	bkg = dp[6];
-	
-	// core first, then add in shell
-	qr=x*rcore;
-	contr = rhocore-rhoshel;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell
-	qr=x*(rcore+thick);
-	contr = rhoshel-rhosolv;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*pow((rcore+thick),3);
-	f += vol*bes*contr;
-	
-	// normalize to particle volume and rescale from [ï¿œ-1] to [cm-1]
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-double
-TwoShell(double dp[], double q)
-{
-	// variables are:
-	//[0] scale factor
-	//[1] radius of core [ï¿œ]
-	//[2] SLD of the core	[ï¿œ-2]
-	//[3] thickness of shell 1 [ï¿œ]
-	//[4] SLD of shell 1
-	//[5] thickness of shell 2 [ï¿œ]
-	//[6] SLD of shell 2
-	//[7] SLD of the solvent
-	//[8] background	[cm-1]
-	
-	double x,pi;
-	double scale,rcore,thick1,rhocore,rhoshel1,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	double rhoshel2,thick2;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	rhocore = dp[2];
-	thick1 = dp[3];
-	rhoshel1 = dp[4];
-	thick2 = dp[5];
-	rhoshel2 = dp[6];	
-	rhosolv = dp[7];
-	bkg = dp[8];
-		// core first, then add in shells
-	qr=x*rcore;
-	contr = rhocore-rhoshel1;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell (1)
-	qr=x*(rcore+thick1);
-	contr = rhoshel1-rhoshel2;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1)*(rcore+thick1)*(rcore+thick1);
-	f += vol*bes*contr;
-	//now the shell (2)
-	qr=x*(rcore+thick1+thick2);
-	contr = rhoshel2-rhosolv;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2)*(rcore+thick1+thick2)*(rcore+thick1+thick2);
-	f += vol*bes*contr;
-	
-		
-	// normalize to particle volume and rescale from [ï¿œ-1] to [cm-1]
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-double
-ThreeShell(double dp[], double q)
-{
-	// variables are:
-	//[0] scale factor
-	//[1] radius of core [ï¿œ]
-	//[2] SLD of the core	[ï¿œ-2]
-	//[3] thickness of shell 1 [ï¿œ]
-	//[4] SLD of shell 1
-	//[5] thickness of shell 2 [ï¿œ]
-	//[6] SLD of shell 2
-	//[7] thickness of shell 3
-	//[8] SLD of shell 3
-	//[9] SLD of solvent
-	//[10] background	[cm-1]
-	
-	double x,pi;
-	double scale,rcore,thick1,rhocore,rhoshel1,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	double rhoshel2,thick2,rhoshel3,thick3;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	rhocore = dp[2];
-	thick1 = dp[3];
-	rhoshel1 = dp[4];
-	thick2 = dp[5];
-	rhoshel2 = dp[6];	
-	thick3 = dp[7];
-	rhoshel3 = dp[8];	
-	rhosolv = dp[9];
-	bkg = dp[10];
-	
-		// core first, then add in shells
-	qr=x*rcore;
-	contr = rhocore-rhoshel1;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell (1)
-	qr=x*(rcore+thick1);
-	contr = rhoshel1-rhoshel2;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1)*(rcore+thick1)*(rcore+thick1);
-	f += vol*bes*contr;
-	//now the shell (2)
-	qr=x*(rcore+thick1+thick2);
-	contr = rhoshel2-rhoshel3;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2)*(rcore+thick1+thick2)*(rcore+thick1+thick2);
-	f += vol*bes*contr;
-	//now the shell (3)
-	qr=x*(rcore+thick1+thick2+thick3);
-	contr = rhoshel3-rhosolv;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2+thick3)*(rcore+thick1+thick2+thick3)*(rcore+thick1+thick2+thick3);
-	f += vol*bes*contr;
-		
-	// normalize to particle volume and rescale from [ï¿œ-1] to [cm-1]
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-double
-FourShell(double dp[], double q)
-{
-	// variables are:
-	//[0] scale factor
-	//[1] radius of core [ï¿œ]
-	//[2] SLD of the core	[ï¿œ-2]
-	//[3] thickness of shell 1 [ï¿œ]
-	//[4] SLD of shell 1
-	//[5] thickness of shell 2 [ï¿œ]
-	//[6] SLD of shell 2
-	//[7] thickness of shell 3
-	//[8] SLD of shell 3
-	//[9] thickness of shell 3
-	//[10] SLD of shell 3
-	//[11] SLD of solvent
-	//[12] background	[cm-1]
-	
-	double x,pi;
-	double scale,rcore,thick1,rhocore,rhoshel1,rhosolv,bkg;		//my local names
-	double bes,f,vol,qr,contr,f2;
-	double rhoshel2,thick2,rhoshel3,thick3,rhoshel4,thick4;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	rhocore = dp[2];
-	thick1 = dp[3];
-	rhoshel1 = dp[4];
-	thick2 = dp[5];
-	rhoshel2 = dp[6];	
-	thick3 = dp[7];
-	rhoshel3 = dp[8];
-	thick4 = dp[9];
-	rhoshel4 = dp[10];	
-	rhosolv = dp[11];
-	bkg = dp[12];
-	
-		// core first, then add in shells
-	qr=x*rcore;
-	contr = rhocore-rhoshel1;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*rcore*rcore*rcore;
-	f = vol*bes*contr;
-	//now the shell (1)
-	qr=x*(rcore+thick1);
-	contr = rhoshel1-rhoshel2;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1)*(rcore+thick1)*(rcore+thick1);
-	f += vol*bes*contr;
-	//now the shell (2)
-	qr=x*(rcore+thick1+thick2);
-	contr = rhoshel2-rhoshel3;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2)*(rcore+thick1+thick2)*(rcore+thick1+thick2);
-	f += vol*bes*contr;
-	//now the shell (3)
-	qr=x*(rcore+thick1+thick2+thick3);
-	contr = rhoshel3-rhoshel4;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2+thick3)*(rcore+thick1+thick2+thick3)*(rcore+thick1+thick2+thick3);
-	f += vol*bes*contr;
-	//now the shell (4)
-	qr=x*(rcore+thick1+thick2+thick3+thick4);
-	contr = rhoshel4-rhosolv;
-	if(qr == 0){
-		bes = 1.0;
-	}else{
-		bes = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);
-	}
-	vol = 4.0*pi/3.0*(rcore+thick1+thick2+thick3+thick4)*(rcore+thick1+thick2+thick3+thick4)*(rcore+thick1+thick2+thick3+thick4);
-	f += vol*bes*contr;
-	
-		
-	// normalize to particle volume and rescale from [ï¿œ-1] to [cm-1]
-	f2 = f*f/vol*1.0e8;
-	
-	//scale if desired
-	f2 *= scale;
-	// then add in the background
-	f2 += bkg;
-	
-	return(f2);
-}
-
-double
-PolyOneShell(double dp[], double x)
-{
-	double scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg,pd,zz;		//my local names
-	double va,vb,summ,yyy,zi;
-	double answer,zp1,zp2,zp3,vpoly,range,temp_1sf[7],pi;
-	int nord=76,ii;
-	
-	pi = 4.0*atan(1.0);
-	
-	scale = dp[0];
-	rcore = dp[1];
-	pd = dp[2];
-	rhocore = dp[3];
-	thick = dp[4];
-	rhoshel = dp[5];
-	rhosolv = dp[6];
-	bkg = dp[7];
-		
-	zz = (1.0/pd)*(1.0/pd)-1.0;		//polydispersity of the core only
-	
-	range = 8.0;			//std deviations for the integration
-	va = rcore*(1.0-range*pd);
-	if (va<0.0) {
-		va=0.0;		//otherwise numerical error when pd >= 0.3, making a<0
-	}
-	if (pd>0.3) {
-		range = range + (pd-0.3)*18.0;		//stretch upper range to account for skewed tail
-	}
-	vb = rcore*(1.0+range*pd);		// is this far enough past avg radius?
-	
-	//temp set scale=1 and bkg=0 for quadrature calc
-	temp_1sf[0] = 1.0;
-	temp_1sf[1] = dp[1];	//the core radius will be changed in the loop
-	temp_1sf[2] = dp[3];
-	temp_1sf[3] = dp[4];
-	temp_1sf[4] = dp[5];
-	temp_1sf[5] = dp[6];
-	temp_1sf[6] = 0.0;
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss76Z[ii]*(vb-va) + vb + va )/2.0;
-		temp_1sf[1] = zi;
-		yyy = Gauss76Wt[ii] * SchulzPoint(zi,rcore,zz) * OneShell(temp_1sf,x);
-		//un-normalize by volume
-		yyy *= 4.0*pi/3.0*pow((zi+thick),3);
-		summ += yyy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	answer = (vb-va)/2.0*summ;
-   	
-	//re-normalize by the average volume
-	zp1 = zz + 1.0;
-	zp2 = zz + 2.0;
-	zp3 = zz + 3.0;
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*pow((rcore+thick),3);
-	answer /= vpoly;
-//scale
-	answer *= scale;
-// add in the background
-	answer += bkg;
-		
-    return(answer);
-}
-
-double
-PolyTwoShell(double dp[], double x)
-{
-	double scale,rcore,rhocore,rhosolv,bkg,pd,zz;		//my local names
-	double va,vb,summ,yyy,zi;
-	double answer,zp1,zp2,zp3,vpoly,range,temp_2sf[9],pi;
-	int nord=76,ii;
-	double thick1,thick2;
-	double rhoshel1,rhoshel2;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	pd = dp[2];
-	rhocore = dp[3];
-	thick1 = dp[4];
-	rhoshel1 = dp[5];
-	thick2 = dp[6];
-	rhoshel2 = dp[7];
-	rhosolv = dp[8];
-	bkg = dp[9];
-	
-	pi = 4.0*atan(1.0);
-		
-	zz = (1.0/pd)*(1.0/pd)-1.0;		//polydispersity of the core only
-	
-	range = 8.0;			//std deviations for the integration
-	va = rcore*(1.0-range*pd);
-	if (va<0.0) {
-		va=0.0;		//otherwise numerical error when pd >= 0.3, making a<0
-	}
-	if (pd>0.3) {
-		range = range + (pd-0.3)*18.0;		//stretch upper range to account for skewed tail
-	}
-	vb = rcore*(1.0+range*pd);		// is this far enough past avg radius?
-	
-	//temp set scale=1 and bkg=0 for quadrature calc
-	temp_2sf[0] = 1.0;
-	temp_2sf[1] = dp[1];		//the core radius will be changed in the loop
-	temp_2sf[2] = dp[3];
-	temp_2sf[3] = dp[4];
-	temp_2sf[4] = dp[5];
-	temp_2sf[5] = dp[6];
-	temp_2sf[6] = dp[7];
-	temp_2sf[7] = dp[8];
-	temp_2sf[8] = 0.0;
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss76Z[ii]*(vb-va) + vb + va )/2.0;
-		temp_2sf[1] = zi;
-		yyy = Gauss76Wt[ii] * SchulzPoint(zi,rcore,zz) * TwoShell(temp_2sf,x);
-		//un-normalize by volume
-		yyy *= 4.0*pi/3.0*pow((zi+thick1+thick2),3);
-		summ += yyy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	answer = (vb-va)/2.0*summ;
-   	
-	//re-normalize by the average volume
-	zp1 = zz + 1.0;
-	zp2 = zz + 2.0;
-	zp3 = zz + 3.0;
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*pow((rcore+thick1+thick2),3);
-	answer /= vpoly;
-//scale
-	answer *= scale;
-// add in the background
-	answer += bkg;
-		
-    return(answer);
-}
-
-double
-PolyThreeShell(double dp[], double x)
-{
-	double scale,rcore,rhocore,rhosolv,bkg,pd,zz;		//my local names
-	double va,vb,summ,yyy,zi;
-	double answer,zp1,zp2,zp3,vpoly,range,temp_3sf[11],pi;
-	int nord=76,ii;
-	double thick1,thick2,thick3;
-	double rhoshel1,rhoshel2,rhoshel3;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	pd = dp[2];
-	rhocore = dp[3];
-	thick1 = dp[4];
-	rhoshel1 = dp[5];
-	thick2 = dp[6];
-	rhoshel2 = dp[7];
-	thick3 = dp[8];
-	rhoshel3 = dp[9];
-	rhosolv = dp[10];
-	bkg = dp[11];
-	
-	pi = 4.0*atan(1.0);
-		
-	zz = (1.0/pd)*(1.0/pd)-1.0;		//polydispersity of the core only
-	
-	range = 8.0;			//std deviations for the integration
-	va = rcore*(1.0-range*pd);
-	if (va<0) {
-		va=0;		//otherwise numerical error when pd >= 0.3, making a<0
-	}
-	if (pd>0.3) {
-		range = range + (pd-0.3)*18.0;		//stretch upper range to account for skewed tail
-	}
-	vb = rcore*(1.0+range*pd);		// is this far enough past avg radius?
-	
-	//temp set scale=1 and bkg=0 for quadrature calc
-	temp_3sf[0] = 1.0;
-	temp_3sf[1] = dp[1];		//the core radius will be changed in the loop
-	temp_3sf[2] = dp[3];
-	temp_3sf[3] = dp[4];
-	temp_3sf[4] = dp[5];
-	temp_3sf[5] = dp[6];
-	temp_3sf[6] = dp[7];
-	temp_3sf[7] = dp[8];
-	temp_3sf[8] = dp[9];
-	temp_3sf[9] = dp[10];
-	temp_3sf[10] = 0.0;
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss76Z[ii]*(vb-va) + vb + va )/2.0;
-		temp_3sf[1] = zi;
-		yyy = Gauss76Wt[ii] * SchulzPoint(zi,rcore,zz) * ThreeShell(temp_3sf,x);
-		//un-normalize by volume
-		yyy *= 4.0*pi/3.0*pow((zi+thick1+thick2+thick3),3);
-		summ += yyy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	answer = (vb-va)/2.0*summ;
-   	
-	//re-normalize by the average volume
-	zp1 = zz + 1.0;
-	zp2 = zz + 2.0;
-	zp3 = zz + 3.0;
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*pow((rcore+thick1+thick2+thick3),3);
-	answer /= vpoly;
-//scale
-	answer *= scale;
-// add in the background
-	answer += bkg;
-		
-    return(answer);
-}
-
-double
-PolyFourShell(double dp[], double x)
-{
-	double scale,rcore,rhocore,rhosolv,bkg,pd,zz;		//my local names
-	double va,vb,summ,yyy,zi;
-	double answer,zp1,zp2,zp3,vpoly,range,temp_4sf[13],pi;
-	int nord=76,ii;
-	double thick1,thick2,thick3,thick4;
-	double rhoshel1,rhoshel2,rhoshel3,rhoshel4;
-	
-	scale = dp[0];
-	rcore = dp[1];
-	pd = dp[2];
-	rhocore = dp[3];
-	thick1 = dp[4];
-	rhoshel1 = dp[5];
-	thick2 = dp[6];
-	rhoshel2 = dp[7];
-	thick3 = dp[8];
-	rhoshel3 = dp[9];
-	thick4 = dp[10];
-	rhoshel4 = dp[11];
-	rhosolv = dp[12];
-	bkg = dp[13];
-	
-	pi = 4.0*atan(1.0);
-		
-	zz = (1.0/pd)*(1.0/pd)-1.0;		//polydispersity of the core only
-	
-	range = 8.0;			//std deviations for the integration
-	va = rcore*(1.0-range*pd);
-	if (va<0) {
-		va=0;		//otherwise numerical error when pd >= 0.3, making a<0
-	}
-	if (pd>0.3) {
-		range = range + (pd-0.3)*18.0;		//stretch upper range to account for skewed tail
-	}
-	vb = rcore*(1.0+range*pd);		// is this far enough past avg radius?
-	
-	//temp set scale=1 and bkg=0 for quadrature calc
-	temp_4sf[0] = 1.0;
-	temp_4sf[1] = dp[1];		//the core radius will be changed in the loop
-	temp_4sf[2] = dp[3];
-	temp_4sf[3] = dp[4];
-	temp_4sf[4] = dp[5];
-	temp_4sf[5] = dp[6];
-	temp_4sf[6] = dp[7];
-	temp_4sf[7] = dp[8];
-	temp_4sf[8] = dp[9];
-	temp_4sf[9] = dp[10];
-	temp_4sf[10] = dp[11];
-	temp_4sf[11] = dp[12];
-	temp_4sf[12] = 0.0;
-		
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss76Z[ii]*(vb-va) + vb + va )/2.0;
-		temp_4sf[1] = zi;
-		yyy = Gauss76Wt[ii] * SchulzPoint(zi,rcore,zz) * FourShell(temp_4sf,x);
-		//un-normalize by volume
-		yyy *= 4.0*pi/3.0*pow((zi+thick1+thick2+thick3+thick4),3);
-		summ += yyy;		//add to the running total of the quadrature
-   	}
-	// calculate value of integral to return
-	answer = (vb-va)/2.0*summ;
-   	
-	//re-normalize by the average volume
-	zp1 = zz + 1.0;
-	zp2 = zz + 2.0;
-	zp3 = zz + 3.0;
-	vpoly = 4.0*pi/3.0*zp3*zp2/zp1/zp1*pow((rcore+thick1+thick2+thick3+thick4),3);
-	answer /= vpoly;
-//scale
-	answer *= scale;
-// add in the background
-	answer += bkg;
-		
-    return(answer);
-}
-
-
-/*	BCC_ParaCrystal  :  calculates the form factor of a Triaxial Ellipsoid at the given x-value p->x
-
-Uses 150 pt Gaussian quadrature for both integrals
-
-*/
-double
-BCC_ParaCrystal(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,Dnn,gg,Rad,contrast,background,latticeScale,sld,sldSolv;		//local variables of coefficient wave
-	int nordi=150;			//order of integration
-	int nordj=150;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 2.0*Pi;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = Pi;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = w[0];
-	Dnn = w[1];					//Nearest neighbor distance A
-	gg = w[2];					//Paracrystal distortion factor
-	Rad = w[3];					//Sphere radius
-	sld = w[4];
-	sldSolv = w[5];
-	background = w[6]; 
-	
-	contrast = sld - sldSolv;
-	
-	//Volume fraction calculated from lattice symmetry and sphere radius
-	latticeScale = 2.0*(4.0/3.0)*Pi*(Rad*Rad*Rad)/pow(Dnn/sqrt(3.0/4.0),3);
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss150Z[i]*(vb-va) + va + vb )/2.0;		//the outer dummy is phi
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss150Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the inner dummy is theta
-			yyy = Gauss150Wt[j] * BCC_Integrand(w,x,zi,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		
-		//now calculate outer integral
-		yyy = Gauss150Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= SphereForm_Paracrystal(Rad,contrast,x)*scale*latticeScale;
-	// add in the background
-	answer += background;
-	
-	return answer;
-}
-
-// xx is phi (outer)
-// yy is theta (inner)
-double
-BCC_Integrand(double w[], double qq, double xx, double yy) {
-	
-	double retVal,temp1,temp3,aa,Da,Dnn,gg,Pi;
-	
-	Dnn = w[1]; //Nearest neighbor distance A
-	gg = w[2]; //Paracrystal distortion factor
-	aa = Dnn;
-	Da = gg*aa;
-	
-	Pi = 4.0*atan(1.0);
-	temp1 = qq*qq*Da*Da;
-	temp3 = qq*aa;	
-	
-	retVal = BCCeval(yy,xx,temp1,temp3);
-	retVal /=4.0*Pi;
-	
-	return(retVal);
-}
-
-double
-BCCeval(double Theta, double Phi, double temp1, double temp3) {
-
-	double temp6,temp7,temp8,temp9,temp10;
-	double result;
-	
-	temp6 = sin(Theta);
-	temp7 = sin(Theta)*cos(Phi)+sin(Theta)*sin(Phi)+cos(Theta);
-	temp8 = -1.0*sin(Theta)*cos(Phi)-sin(Theta)*sin(Phi)+cos(Theta);
-	temp9 = -1.0*sin(Theta)*cos(Phi)+sin(Theta)*sin(Phi)-cos(Theta);
-	temp10 = exp((-1.0/8.0)*temp1*((temp7*temp7)+(temp8*temp8)+(temp9*temp9)));
-	result = pow(1.0-(temp10*temp10),3)*temp6/((1.0-2.0*temp10*cos(0.5*temp3*(temp7))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp8))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp9))+(temp10*temp10)));
-	
-	return (result);
-}
-
-double
-SphereForm_Paracrystal(double radius, double delrho, double x) {					
-	
-	double bes,f,vol,f2,pi;
-	pi = 4.0*atan(1.0);
-	//
-	//handle q==0 separately
-	if(x==0) {
-		f = 4.0/3.0*pi*radius*radius*radius*delrho*delrho*1.0e8;
-		return(f);
-	}
-	
-	bes = 3.0*(sin(x*radius)-x*radius*cos(x*radius))/(x*x*x)/(radius*radius*radius);
-	vol = 4.0*pi/3.0*radius*radius*radius;
-	f = vol*bes*delrho	;	// [=] ï¿œ
-	// normalize to single particle volume, convert to 1/cm
-	f2 = f * f / vol * 1.0e8;		// [=] 1/cm
-	
-	return (f2);
-}
-
-/*	FCC_ParaCrystal  :  calculates the form factor of a Triaxial Ellipsoid at the given x-value p->x
-
-Uses 150 pt Gaussian quadrature for both integrals
-
-*/
-double
-FCC_ParaCrystal(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,Dnn,gg,Rad,contrast,background,latticeScale,sld,sldSolv;		//local variables of coefficient wave
-	int nordi=150;			//order of integration
-	int nordj=150;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = 2.0*Pi;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = Pi;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = w[0];
-	Dnn = w[1];					//Nearest neighbor distance A
-	gg = w[2];					//Paracrystal distortion factor
-	Rad = w[3];					//Sphere radius
-	sld = w[4];
-	sldSolv = w[5];
-	background = w[6]; 
-	
-	contrast = sld - sldSolv;
-	//Volume fraction calculated from lattice symmetry and sphere radius
-	latticeScale = 4.0*(4.0/3.0)*Pi*(Rad*Rad*Rad)/pow(Dnn*sqrt(2.0),3);
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss150Z[i]*(vb-va) + va + vb )/2.0;		//the outer dummy is phi
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss150Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the inner dummy is theta
-			yyy = Gauss150Wt[j] * FCC_Integrand(w,x,zi,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		
-		//now calculate outer integral
-		yyy = Gauss150Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= SphereForm_Paracrystal(Rad,contrast,x)*scale*latticeScale;
-	// add in the background
-	answer += background;
-	
-	return answer;
-}
-
-
-// xx is phi (outer)
-// yy is theta (inner)
-double
-FCC_Integrand(double w[], double qq, double xx, double yy) {
-	
-	double retVal,temp1,temp3,aa,Da,Dnn,gg,Pi;
-	
-	Pi = 4.0*atan(1.0);
-	Dnn = w[1]; //Nearest neighbor distance A
-	gg = w[2]; //Paracrystal distortion factor
-	aa = Dnn;
-	Da = gg*aa;
-	
-	temp1 = qq*qq*Da*Da;
-	temp3 = qq*aa;
-	
-	retVal = FCCeval(yy,xx,temp1,temp3);
-	retVal /=4*Pi;
-	
-	return(retVal);
-}
-
-double
-FCCeval(double Theta, double Phi, double temp1, double temp3) {
-
-	double temp6,temp7,temp8,temp9,temp10;
-	double result;
-	
-	temp6 = sin(Theta);
-	temp7 = sin(Theta)*sin(Phi)+cos(Theta);
-	temp8 = -1.0*sin(Theta)*cos(Phi)+cos(Theta);
-	temp9 = -1.0*sin(Theta)*cos(Phi)+sin(Theta)*sin(Phi);
-	temp10 = exp((-1.0/8.0)*temp1*((temp7*temp7)+(temp8*temp8)+(temp9*temp9)));
-	result = pow((1.0-(temp10*temp10)),3)*temp6/((1.0-2.0*temp10*cos(0.5*temp3*(temp7))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp8))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp9))+(temp10*temp10)));
-	
-	return (result);
-}
-
-
-/*	SC_ParaCrystal  :  calculates the form factor of a Triaxial Ellipsoid at the given x-value p->x
-
-Uses 150 pt Gaussian quadrature for both integrals
-
-*/
-double
-SC_ParaCrystal(double w[], double x)
-{
-	int i,j;
-	double Pi;
-	double scale,Dnn,gg,Rad,contrast,background,latticeScale,sld,sldSolv;		//local variables of coefficient wave
-	int nordi=150;			//order of integration
-	int nordj=150;
-	double va,vb;		//upper and lower integration limits
-	double summ,zi,yyy,answer;			//running tally of integration
-	double summj,vaj,vbj,zij;			//for the inner integration
-	
-	Pi = 4.0*atan(1.0);
-	va = 0.0;
-	vb = Pi/2.0;		//orintational average, outer integral
-	vaj = 0.0;
-	vbj = Pi/2.0;		//endpoints of inner integral
-	
-	summ = 0.0;			//initialize intergral
-	
-	scale = w[0];
-	Dnn = w[1];					//Nearest neighbor distance A
-	gg = w[2];					//Paracrystal distortion factor
-	Rad = w[3];					//Sphere radius
-	sld = w[4];
-	sldSolv = w[5];
-	background = w[6]; 
-	
-	contrast = sld - sldSolv;
-	//Volume fraction calculated from lattice symmetry and sphere radius
-	latticeScale = (4.0/3.0)*Pi*(Rad*Rad*Rad)/pow(Dnn,3);
-	
-	for(i=0;i<nordi;i++) {
-		//setup inner integral over the ellipsoidal cross-section
-		summj=0.0;
-		zi = ( Gauss150Z[i]*(vb-va) + va + vb )/2.0;		//the outer dummy is phi
-		for(j=0;j<nordj;j++) {
-			//20 gauss points for the inner integral
-			zij = ( Gauss150Z[j]*(vbj-vaj) + vaj + vbj )/2.0;		//the inner dummy is theta
-			yyy = Gauss150Wt[j] * SC_Integrand(w,x,zi,zij);
-			summj += yyy;
-		}
-		//now calculate the value of the inner integral
-		answer = (vbj-vaj)/2.0*summj;
-		
-		//now calculate outer integral
-		yyy = Gauss150Wt[i] * answer;
-		summ += yyy;
-	}		//final scaling is done at the end of the function, after the NT_FP64 case
-	
-	answer = (vb-va)/2.0*summ;
-	// Multiply by contrast^2
-	answer *= SphereForm_Paracrystal(Rad,contrast,x)*scale*latticeScale;
-	// add in the background
-	answer += background;
-	
-	return answer;
-}
-
-// xx is phi (outer)
-// yy is theta (inner)
-double
-SC_Integrand(double w[], double qq, double xx, double yy) {
-	
-	double retVal,temp1,temp2,temp3,temp4,temp5,aa,Da,Dnn,gg,Pi;
-	
-	Pi = 4.0*atan(1.0);
-	Dnn = w[1]; //Nearest neighbor distance A
-	gg = w[2]; //Paracrystal distortion factor
-	aa = Dnn;
-	Da = gg*aa;
-	
-	temp1 = qq*qq*Da*Da;
-	temp2 = pow( 1.0-exp(-1.0*temp1) ,3);
-	temp3 = qq*aa;
-	temp4 = 2.0*exp(-0.5*temp1);
-	temp5 = exp(-1.0*temp1);
-	
-	
-	retVal = temp2*SCeval(yy,xx,temp3,temp4,temp5);
-	retVal *= 2.0/Pi;
-	
-	return(retVal);
-}
-
-double
-SCeval(double Theta, double Phi, double temp3, double temp4, double temp5) { //Function to calculate integrand values for simple cubic structure
-
-	double temp6,temp7,temp8,temp9; //Theta and phi dependent parts of the equation
-	double result;
-	
-	temp6 = sin(Theta);
-	temp7 = -1.0*temp3*sin(Theta)*cos(Phi);
-	temp8 = temp3*sin(Theta)*sin(Phi);
-	temp9 = temp3*cos(Theta);
-	result = temp6/((1.0-temp4*cos((temp7))+temp5)*(1.0-temp4*cos((temp8))+temp5)*(1.0-temp4*cos((temp9))+temp5));
-	
-	return (result);
-}
-
-// scattering from a uniform sphere with a Gaussian size distribution
-//
-double
-FuzzySpheres(double dp[], double q)
-{
-	double pi,x;
-	double scale,rad,pd,sig,rho,rhos,bkg,delrho,sig_surf,f2,bes,vol,f;		//my local names
-	double va,vb,zi,yy,summ,inten;
-	int nord=20,ii;
-	
-	pi = 4.0*atan(1.0);
-	x= q;
-	
-	scale=dp[0];
-	rad=dp[1];
-	pd=dp[2];
-	sig=pd*rad;
-	sig_surf = dp[3];
-	rho=dp[4];
-	rhos=dp[5];
-	delrho=rho-rhos;
-	bkg=dp[6];
-	
-			
-	va = -4.0*sig + rad;
-	if (va<0) {
-		va=0;		//to avoid numerical error when  va<0 (-ve q-value)
-	}
-	vb = 4.0*sig +rad;
-	
-	summ = 0.0;		// initialize integral
-	for(ii=0;ii<nord;ii+=1) {
-		// calculate Gauss points on integration interval (r-value for evaluation)
-		zi = ( Gauss20Z[ii]*(vb-va) + vb + va )/2.0;
-		// calculate sphere scattering
-		//
-		//handle q==0 separately
-		if (x==0.0) {
-			f2 = 4.0/3.0*pi*zi*zi*zi*delrho*delrho*1.0e8;
-			f2 *= exp(-0.5*sig_surf*sig_surf*x*x);
-			f2 *= exp(-0.5*sig_surf*sig_surf*x*x);
-		} else {
-			bes = 3.0*(sin(x*zi)-x*zi*cos(x*zi))/(x*x*x)/(zi*zi*zi);
-			vol = 4.0*pi/3.0*zi*zi*zi;
-			f = vol*bes*delrho;		// [=] A
-			f *= exp(-0.5*sig_surf*sig_surf*x*x);
-			// normalize to single particle volume, convert to 1/cm
-			f2 = f * f / vol * 1.0e8;		// [=] 1/cm
-		}
-	
-		yy = Gauss20Wt[ii] *  Gauss_distr(sig,rad,zi) * f2;
-		yy *= 4.0*pi/3.0*zi*zi*zi;		//un-normalize by current sphere volume
-		
-		summ += yy;		//add to the running total of the quadrature
-		
-		
-   	}
-	// calculate value of integral to return
-	inten = (vb-va)/2.0*summ;
-	
-	//re-normalize by polydisperse sphere volume
-	inten /= (4.0*pi/3.0*rad*rad*rad)*(1.0+3.0*pd*pd);
-	
-	inten *= scale;
-	inten += bkg;
-	
-    return(inten);	//scale, and add in the background
-}
-
-// Micelle with spherical core 
-// J.S. Pedersen, J. Appl. Cryst. 33, 637 (2000)
-
-double
-MicelleSphericalCore(double dp[], double q)
-{
-	double x, pi;
-	double ndensity, v_core, v_corona, rho_solv, rho_core, rho_corona;      // local names of input params
-	double radius_core, radius_gyr, d_penetration, n_aggreg, bkg, scale;    // local names of input params
-	double beta_core, beta_corona, qr, qrg, qrg2, qrdrg, bes_core, bes_corona; 
-	double term1, term2, term3, term4, debye_chain, chain_ampl, i_micelle;
-
-	x = q;
-	
-	scale = dp[0];
-	ndensity = dp[1];      // number density [1/cm^3]
-	v_core = dp[2];        // volume block in core [A^3]
-	v_corona = dp[3];      // volume block in corona [A^3]
-	rho_solv = dp[4];      // sld of solvent [1/A^2]
-	rho_core = dp[5];      // sld of core [1/A^2]
-	rho_corona = dp[6];    // sld of corona [1/A^2]
-	radius_core = dp[7];   // radius of core [A]
-	radius_gyr = dp[8];    // radius of gyration of chains in corona [A]
-	d_penetration = dp[9]; // close to unity, mimics non-penetration of gaussian chains
-	n_aggreg = dp[10];     // aggregation number of the micelle
-	bkg = dp[11];          // background
-	
-	beta_core = v_core * (rho_core - rho_solv);
-	beta_corona = v_corona * (rho_corona - rho_solv);
-	
-	
-        // Self-correlation term of the core
-
-	qr = x*radius_core;
-	if(qr == 0){bes_core = 1.0;} else {bes_core = 3.0*(sin(qr)-qr*cos(qr))/(qr*qr*qr);}
-	
-        term1 = n_aggreg * n_aggreg * beta_core * beta_core * bes_core * bes_core;
-
-        // Self-correlation term of the chains
-
-	qrg = x*radius_gyr;
-	qrg2 = qrg*qrg;
-	if(qrg2 == 0){debye_chain = 1.0;} else {debye_chain = 2.0*(exp(-qrg2)-1+qrg2)/(qrg2*qrg2);}
-	
-        term2 = n_aggreg * beta_corona * beta_corona * debye_chain;
-
-        // Interference cross-term between core and chains
-
-	if(qrg2 == 0){chain_ampl = 1.0;} else {chain_ampl = (1-exp(-qrg2))/qrg2;}
-
-	qrdrg = x * (radius_core + d_penetration * radius_gyr);
-	if(qrdrg == 0){bes_corona = 1.0;} else {bes_corona = sin(qrdrg)/qrdrg;}
-
-        term3 = 2 * n_aggreg * n_aggreg * beta_core * beta_corona * bes_core * chain_ampl * bes_corona;
-
-        // Interference cross-term between chains
-
-        term4 = n_aggreg * (n_aggreg - 1.0) * beta_corona * beta_corona * chain_ampl * chain_ampl * bes_corona * bes_corona;
-
-        // I(q)_micelle : Sum of 4 terms computed above
-	
-	i_micelle = term1 + term2 + term3 + term4 ; 
-
-	// rescale from [A^2] to [cm^2]
-	
-	i_micelle *= 1.0e-16;
-
-	// "normalize" by number density --> intensity in [cm-1]
-	
-	i_micelle *= ndensity;
-	
-	//scale if desired
-	i_micelle *= scale;
-
-	// add in the background
-	i_micelle += bkg;
-	
-	return(i_micelle);
-	
-}
-
Index: src/sas/models/c_extension/libigor/libSphere.h
===================================================================
--- src/sas/models/c_extension/libigor/libSphere.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,51 +1,0 @@
-// header for SphereFit.c
-#if defined(_MSC_VER)
-#include "winFuncs.h"
-#endif
-
-/* IGOR Fit Functions */
-double MultiShell(double dp[], double q);
-double PolyMultiShell(double dp[], double q);
-double SphereForm(double dp[], double q);
-double CoreShellForm(double dp[], double q);
-double PolyCoreForm(double dp[], double q);
-double PolyCoreShellRatio(double dp[], double q);
-double VesicleForm(double dp[], double q);
-double SchulzSpheres(double dp[], double q);
-double PolyRectSpheres(double dp[], double q);
-double PolyHardSphereIntensity(double dp[], double q);
-double BimodalSchulzSpheres(double dp[], double q);
-double GaussPolySphere(double dp[], double q);
-double LogNormalPolySphere(double dp[], double q);
-double BinaryHS(double dp[], double q);
-double BinaryHS_PSF11(double dp[], double q);
-double BinaryHS_PSF12(double dp[], double q);
-double BinaryHS_PSF22(double dp[], double q);
-double OneShell(double dp[], double q);
-double TwoShell(double dp[], double q);
-double ThreeShell(double dp[], double q);
-double FourShell(double dp[], double q);
-double PolyOneShell(double dp[], double q);
-double PolyTwoShell(double dp[], double q);
-double PolyThreeShell(double dp[], double q);
-double PolyFourShell(double dp[], double q);
-double BCC_ParaCrystal(double dp[], double q);
-double FCC_ParaCrystal(double dp[], double q);
-double SC_ParaCrystal(double dp[], double q);
-double FuzzySpheres(double dp[], double q);
-double MicelleSphericalCore(double dp[], double q);
-
-//function prototypes
-double F_func(double qr);
-double MultiShellGuts(double q,double rcore,double ts,double tw,double rhocore,double rhoshel,int num);
-double fnt2(double yy, double zz);
-double fnt3(double yy, double pp, double zz);
-double SchulzSphere_Fn(double scale, double ravg, double pd, double rho, double rhos, double x);
-int ashcroft(double qval, double r2, double nf2, double aa, double phi, double *s11, double *s22, double *s12);
-double BCC_Integrand(double w[], double qq, double xx, double yy);
-double BCCeval(double Theta, double Phi, double temp1, double temp3);
-double SphereForm_Paracrystal(double radius, double delrho, double x);
-double FCC_Integrand(double w[], double qq, double xx, double yy);
-double FCCeval(double Theta, double Phi, double temp1, double temp3);
-double SC_Integrand(double w[], double qq, double xx, double yy);
-double SCeval(double Theta, double Phi, double temp3, double temp4, double temp5);
Index: src/sas/models/c_extension/libigor/libStructureFactor.c
===================================================================
--- src/sas/models/c_extension/libigor/libStructureFactor.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,758 +1,0 @@
-/*	SimpleFit.c
-
-A simplified project designed to act as a template for your curve fitting function.
-The fitting function is a simple polynomial. It works but is of no practical use.
-*/
-
-#include "StandardHeaders.h"			// Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h
-#include "libStructureFactor.h"
-
-//Hard Sphere Structure Factor
-//
-double
-HardSphereStruct(double dp[], double q)
-{
-	double denom,dnum,alpha,beta,gamm,a,asq,ath,afor,rca,rsa;
-	double calp,cbeta,cgam,prefac,c,vstruc;
-	double r,phi,struc;
-	
-	r = dp[0];
-	phi = dp[1];
-	//  compute constants
-	denom = pow((1.0-phi),4);
-	dnum = pow((1.0 + 2.0*phi),2);
-	alpha = dnum/denom;
-	beta = -6.0*phi*pow((1.0 + phi/2.0),2)/denom;
-	gamm = 0.50*phi*dnum/denom;
-	//
-	//  calculate the structure factor
-	//     
-	a = 2.0*q*r;
-	asq = a*a;
-	ath = asq*a;
-	afor = ath*a;
-	rca = cos(a);
-	rsa = sin(a);
-	calp = alpha*(rsa/asq - rca/a);
-	cbeta = beta*(2.0*rsa/asq - (asq - 2.0)*rca/ath - 2.0/ath);
-	cgam = gamm*(-rca/a + (4.0/a)*((3.0*asq - 6.0)*rca/afor + (asq - 6.0)*rsa/ath + 6.0/afor));
-	prefac = -24.0*phi/a;
-	c = prefac*(calp + cbeta + cgam);
-	vstruc = 1.0/(1.0-c);
-	struc = vstruc;
-	
-	return(struc);
-}
-
-//Sticky Hard Sphere Structure Factor
-//
-double
-StickyHS_Struct(double dp[], double q)
-{
-	double qv;
-	double rad,phi,eps,tau,eta;
-	double sig,aa,etam1,qa,qb,qc,radic;
-	double lam,lam2,test,mu,alpha,beta;
-	double kk,k2,k3,ds,dc,aq1,aq2,aq3,aq,bq1,bq2,bq3,bq,sq;
-	
-	qv= q;
-	rad = dp[0];
-	phi = dp[1];
-	eps = dp[2];
-	tau = dp[3];
-	
-	eta = phi/(1.0-eps)/(1.0-eps)/(1.0-eps);
-	
-	sig = 2.0 * rad;
-	aa = sig/(1.0 - eps);
-	etam1 = 1.0 - eta;
-	//C
-	//C  SOLVE QUADRATIC FOR LAMBDA
-	//C
-	qa = eta/12.0;
-	qb = -1.0*(tau + eta/(etam1));
-	qc = (1.0 + eta/2.0)/(etam1*etam1);
-	radic = qb*qb - 4.0*qa*qc;
-	if(radic<0) {
-		//if(x>0.01 && x<0.015)
-	 	//	Print "Lambda unphysical - both roots imaginary"
-	 	//endif
-		return(-1.0);
-	}
-	//C   KEEP THE SMALLER ROOT, THE LARGER ONE IS UNPHYSICAL
-	lam = (-1.0*qb-sqrt(radic))/(2.0*qa);
-	lam2 = (-1.0*qb+sqrt(radic))/(2.0*qa);
-	if(lam2<lam) {
-		lam = lam2;
-	}
-	test = 1.0 + 2.0*eta;
-	mu = lam*eta*etam1;
-	if(mu>test) {
-		//if(x>0.01 && x<0.015)
-		// Print "Lambda unphysical mu>test"
-		//endif
-		return(-1.0);
-	}
-	alpha = (1.0 + 2.0*eta - mu)/(etam1*etam1);
-	beta = (mu - 3.0*eta)/(2.0*etam1*etam1);
-	//C
-	//C   CALCULATE THE STRUCTURE FACTOR
-	//C
-	kk = qv*aa;
-	k2 = kk*kk;
-	k3 = kk*k2;
-	ds = sin(kk);
-	dc = cos(kk);
-	aq1 = ((ds - kk*dc)*alpha)/k3;
-	aq2 = (beta*(1.0-dc))/k2;
-	aq3 = (lam*ds)/(12.0*kk);
-	aq = 1.0 + 12.0*eta*(aq1+aq2-aq3);
-	//
-	bq1 = alpha*(0.5/kk - ds/k2 + (1.0 - dc)/k3);
-	bq2 = beta*(1.0/kk - ds/k2);
-	bq3 = (lam/12.0)*((1.0 - dc)/kk);
-	bq = 12.0*eta*(bq1+bq2-bq3);
-	//
-	sq = 1.0/(aq*aq +bq*bq);
-	
-	return(sq);
-}
-
-
-
-//     SUBROUTINE SQWELL: CALCULATES THE STRUCTURE FACTOR FOR A
-//                        DISPERSION OF MONODISPERSE HARD SPHERES
-//     IN THE Mean Spherical APPROXIMATION ASSUMING THE SPHERES
-//     INTERACT THROUGH A SQUARE WELL POTENTIAL.
-//** not the best choice of closure ** see note below
-//     REFS:  SHARMA,SHARMA, PHYSICA 89A,(1977),212
-double
-SquareWellStruct(double dp[], double q)
-{
-	double req,phis,edibkb,lambda,struc;
-	double sigma,eta,eta2,eta3,eta4,etam1,etam14,alpha,beta,gamm;
-	double x,sk,sk2,sk3,sk4,t1,t2,t3,t4,ck;
-	
-	x= q;
-	
-	req = dp[0];
-	phis = dp[1];
-	edibkb = dp[2];
-	lambda = dp[3];
-	
-	sigma = req*2.;
-	eta = phis;
-	eta2 = eta*eta;
-	eta3 = eta*eta2;
-	eta4 = eta*eta3;
-	etam1 = 1. - eta;
-	etam14 = etam1*etam1*etam1*etam1;
-	alpha = (  pow((1. + 2.*eta),2) + eta3*( eta-4.0 )  )/etam14;
-	beta = -(eta/3.0) * ( 18. + 20.*eta - 12.*eta2 + eta4 )/etam14;
-	gamm = 0.5*eta*( pow((1. + 2.*eta),2) + eta3*(eta-4.) )/etam14;
-	//
-	//  calculate the structure factor
-	
-	sk = x*sigma;
-	sk2 = sk*sk;
-	sk3 = sk*sk2;
-	sk4 = sk3*sk;
-	t1 = alpha * sk3 * ( sin(sk) - sk * cos(sk) );
-	t2 = beta * sk2 * ( 2.*sk*sin(sk) - (sk2-2.)*cos(sk) - 2.0 );
-	t3 =   ( 4.0*sk3 - 24.*sk ) * sin(sk);
-	t3 = t3 - ( sk4 - 12.0*sk2 + 24.0 )*cos(sk) + 24.0;
-	t3 = gamm*t3;
-	t4 = -edibkb*sk3*(sin(lambda*sk) - lambda*sk*cos(lambda*sk)+ sk*cos(sk) - sin(sk) );
-	ck =  -24.0*eta*( t1 + t2 + t3 + t4 )/sk3/sk3;
-	struc  = 1./(1.-ck);
-	
-	return(struc);
-}
-
-// Hayter-Penfold (rescaled) MSA structure factor for screened Coulomb interactions 
-//
-double
-HayterPenfoldMSA(double dp[], double q)
-{
-  double gMSAWave[17]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
-	double Elcharge=1.602189e-19;		// electron charge in Coulombs (C)
-	double kB=1.380662e-23;				// Boltzman constant in J/K
-	double FrSpPerm=8.85418782E-12;	//Permittivity of free space in C^2/(N m^2)
-	double SofQ, QQ, Qdiam, Vp, csalt, ss;
-	double VolFrac, SIdiam, diam, Kappa, cs, IonSt;
-	double dialec, Perm, Beta, Temp, zz, charge;
-	double pi;
-	int ierr;
-	
-	pi = 4.0*atan(1.);
-	QQ= q;
-
-	diam=dp[0];		//in A
-	zz = dp[1];		//# of charges
-	VolFrac=dp[2];
-	Temp=dp[3];		//in degrees Kelvin
-	csalt=dp[4];		//in molarity
-	dialec=dp[5];		// unitless
-						////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-						//////////////////////////// convert to USEFUL inputs in SI units                                                //
-						////////////////////////////    NOTE: easiest to do EVERYTHING in SI units                               //
-						////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-	Beta=1.0/(kB*Temp);		// in Joules^-1
-	Perm=dialec*FrSpPerm;	//in C^2/(N  m^2)
-	charge=zz*Elcharge;		//in Coulomb (C)
-	SIdiam = diam*1E-10;		//in m
-	Vp=4.0*pi/3.0*(SIdiam/2.0)*(SIdiam/2.0)*(SIdiam/2.0);	//in m^3
-	cs=csalt*6.022E23*1E3;	//# salt molecules/m^3
-	
-	//         Compute the derived values of :
-	//			 Ionic strength IonSt (in C^2/m^3)  
-	// 			Kappa (Debye-Huckel screening length in m)
-	//	and		gamma Exp(-k)
-	IonSt=0.5 * Elcharge*Elcharge*(zz*VolFrac/Vp+2.0*cs);
-	Kappa=sqrt(2*Beta*IonSt/Perm);     //Kappa calc from Ionic strength
-									   //	Kappa=2/SIdiam					// Use to compare with HP paper
-	gMSAWave[5]=Beta*charge*charge/(pi*Perm*SIdiam*pow((2.0+Kappa*SIdiam),2));
-	
-	//         Finally set up dimensionless parameters 
-	Qdiam=QQ*diam;
-	gMSAWave[6] = Kappa*SIdiam;
-	gMSAWave[4] = VolFrac;
-	
-	//Function sqhpa(qq)  {this is where Hayter-Penfold program began}
-	
-	//       FIRST CALCULATE COUPLING
-	
-	ss=pow(gMSAWave[4],(1.0/3.0));
-	gMSAWave[9] = 2.0*ss*gMSAWave[5]*exp(gMSAWave[6]-gMSAWave[6]/ss);
-	
-	//        CALCULATE COEFFICIENTS, CHECK ALL IS WELL
-	//        AND IF SO CALCULATE S(Q*SIG)
-	
-	ierr=0;
-	ierr=sqcoef(ierr, gMSAWave);
-	if (ierr>=0) {
-		SofQ=sqhcal(Qdiam, gMSAWave);
-	}else{
-       	//SofQ=NaN;
-		SofQ=-1.0;
-		//	print "Error Level = ",ierr
-		//      print "Please report HPMSA problem with above error code"
-	}
-	
-	return(SofQ);
-}
-
-
-
-/////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////
-//
-//
-//      CALCULATES RESCALED VOLUME FRACTION AND CORRESPONDING
-//      COEFFICIENTS FOR "SQHPA"
-//
-//      JOHN B. HAYTER   (I.L.L.)    14-SEP-81
-//
-//      ON EXIT:
-//
-//      SETA IS THE RESCALED VOLUME FRACTION
-//      SGEK IS THE RESCALED CONTACT POTENTIAL
-//      SAK IS THE RESCALED SCREENING CONSTANT
-//      A,B,C,F,U,V ARE THE MSA COEFFICIENTS
-//      G1= G(1+) IS THE CONTACT VALUE OF G(R/SIG):
-//      FOR THE GILLAN CONDITION, THE DIFFERENCE FROM
-//      ZERO INDICATES THE COMPUTATIONAL ACCURACY.
-//
-//      IR > 0:    NORMAL EXIT,  IR IS THE NUMBER OF ITERATIONS.
-//         < 0:    FAILED TO CONVERGE
-//
-int
-sqcoef(int ir, double gMSAWave[])
-{	
-	int itm=40,ix,ig,ii;
-	double acc=5.0E-6,del,e1,e2,f1,f2;
-
-	//      WAVE gMSAWave = $"root:HayPenMSA:gMSAWave"
-	f1=0;		//these were never properly initialized...
-	f2=0;
-	
-	ig=1;
-	if (gMSAWave[6]>=(1.0+8.0*gMSAWave[4])) {
-		ig=0;
-		gMSAWave[15]=gMSAWave[14];
-		gMSAWave[16]=gMSAWave[4];
-		ix=1;
-		ir = sqfun(ix,ir,gMSAWave);
-		gMSAWave[14]=gMSAWave[15];
-		gMSAWave[4]=gMSAWave[16];
-		if((ir<0.0) || (gMSAWave[14]>=0.0)) {
-			return ir;
-		}
-	}
-	gMSAWave[10]=fmin(gMSAWave[4],0.20);
-	if ((ig!=1) || ( gMSAWave[9]>=0.15)) {
-		ii=0;                             
-		do {
-			ii=ii+1;
-			if(ii>itm) {
-				ir=-1;
-				return ir;		
-			}
-			if (gMSAWave[10]<=0.0) {
-			    gMSAWave[10]=gMSAWave[4]/ii;
-			}
-			if(gMSAWave[10]>0.6) {
-			    gMSAWave[10] = 0.35/ii;
-			}
-			e1=gMSAWave[10];
-			gMSAWave[15]=f1;
-			gMSAWave[16]=e1;
-			ix=2;
-			ir = sqfun(ix,ir,gMSAWave);
-			f1=gMSAWave[15];
-			e1=gMSAWave[16];
-			e2=gMSAWave[10]*1.01;
-			gMSAWave[15]=f2;
-			gMSAWave[16]=e2;
-			ix=2;
-			ir = sqfun(ix,ir,gMSAWave);
-			f2=gMSAWave[15];
-			e2=gMSAWave[16];
-			e2=e1-(e2-e1)*f1/(f2-f1);
-			gMSAWave[10] = e2;
-			del = fabs((e2-e1)/e1);
-		} while (del>acc);
-		gMSAWave[15]=gMSAWave[14];
-		gMSAWave[16]=e2;
-		ix=4;
-		ir = sqfun(ix,ir,gMSAWave);
-		gMSAWave[14]=gMSAWave[15];
-		e2=gMSAWave[16];
-		ir=ii;
-		if ((ig!=1) || (gMSAWave[10]>=gMSAWave[4])) {
-		    return ir;
-		}
-	}
-	gMSAWave[15]=gMSAWave[14];
-	gMSAWave[16]=gMSAWave[4];
-	ix=3;
-	ir = sqfun(ix,ir,gMSAWave);
-	gMSAWave[14]=gMSAWave[15];
-	gMSAWave[4]=gMSAWave[16];
-	if ((ir>=0) && (gMSAWave[14]<0.0)) {
-		ir=-3;
-	}
-	return ir;
-}
-
-
-int
-sqfun(int ix, int ir, double gMSAWave[])
-{	
-	double acc=1.0e-6;
-	double reta,eta2,eta21,eta22,eta3,eta32,eta2d,eta2d2,eta3d,eta6d,e12,e24,rgek;
-	double rak,ak1,ak2,dak,dak2,dak4,d,d2,dd2,dd4,dd45,ex1,ex2,sk,ck,ckma,skma;
-	double al1,al2,al3,al4,al5,al6,be1,be2,be3,vu1,vu2,vu3,vu4,vu5,ph1,ph2,ta1,ta2,ta3,ta4,ta5;
-	double a1,a2,a3,b1,b2,b3,v1,v2,v3,p1,p2,p3,pp,pp1,pp2,p1p2,t1,t2,t3,um1,um2,um3,um4,um5,um6;
-	double w0,w1,w2,w3,w4,w12,w13,w14,w15,w16,w24,w25,w26,w32,w34,w3425,w35,w3526,w36,w46,w56;
-	double fa,fap,ca,e24g,pwk,qpw,pg,del,fun,fund,g24;
-	int ii,ibig,itm=40;
-	//      WAVE gMSAWave = $"root:HayPenMSA:gMSAWave"
-	a2=0;
-	a3=0;
-	b2=0;
-	b3=0;
-	v2=0;
-	v3=0;
-	p2=0;
-	p3=0;
-	
-	//     CALCULATE CONSTANTS; NOTATION IS HAYTER PENFOLD (1981)
-	
-	reta = gMSAWave[16];                                                
-	eta2 = reta*reta;
-	eta3 = eta2*reta;
-	e12 = 12.0*reta;
-	e24 = e12+e12;
-	gMSAWave[13] = pow( (gMSAWave[4]/gMSAWave[16]),(1.0/3.0));
-	gMSAWave[12]=gMSAWave[6]/gMSAWave[13];
-	ibig=0;
-	if (( gMSAWave[12]>15.0) && (ix==1)) {
-		ibig=1;
-	}
-    
-	gMSAWave[11] = gMSAWave[5]*gMSAWave[13]*exp(gMSAWave[6]- gMSAWave[12]);
-	rgek =  gMSAWave[11];
-	rak =  gMSAWave[12];
-	ak2 = rak*rak;
-	ak1 = 1.0+rak;
-	dak2 = 1.0/ak2;
-	dak4 = dak2*dak2;
-	d = 1.0-reta;
-	d2 = d*d;
-	dak = d/rak;
-	dd2 = 1.0/d2;
-	dd4 = dd2*dd2;
-	dd45 = dd4*2.0e-1;
-	eta3d=3.0*reta;
-	eta6d = eta3d+eta3d;
-	eta32 = eta3+ eta3;
-	eta2d = reta+2.0;
-	eta2d2 = eta2d*eta2d;
-	eta21 = 2.0*reta+1.0;
-	eta22 = eta21*eta21;
-	
-	//     ALPHA(I)
-	
-	al1 = -eta21*dak;
-	al2 = (14.0*eta2-4.0*reta-1.0)*dak2;
-	al3 = 36.0*eta2*dak4;
-	
-	//      BETA(I)
-	
-	be1 = -(eta2+7.0*reta+1.0)*dak;
-	be2 = 9.0*reta*(eta2+4.0*reta-2.0)*dak2;
-	be3 = 12.0*reta*(2.0*eta2+8.0*reta-1.0)*dak4;
-	
-	//      NU(I)
-	
-	vu1 = -(eta3+3.0*eta2+45.0*reta+5.0)*dak;
-	vu2 = (eta32+3.0*eta2+42.0*reta-2.0e1)*dak2;
-	vu3 = (eta32+3.0e1*reta-5.0)*dak4;
-	vu4 = vu1+e24*rak*vu3;
-	vu5 = eta6d*(vu2+4.0*vu3);
-	
-	//      PHI(I)
-	
-	ph1 = eta6d/rak;
-	ph2 = d-e12*dak2;
-	
-	//      TAU(I)
-	
-	ta1 = (reta+5.0)/(5.0*rak);
-	ta2 = eta2d*dak2;
-	ta3 = -e12*rgek*(ta1+ta2);
-	ta4 = eta3d*ak2*(ta1*ta1-ta2*ta2);
-	ta5 = eta3d*(reta+8.0)*1.0e-1-2.0*eta22*dak2;
-	
-	//     double PRECISION SINH(K), COSH(K)
-	
-	ex1 = exp(rak);
-	ex2 = 0.0;
-	if ( gMSAWave[12]<20.0) {
-		ex2=exp(-rak);
-	}
-	sk=0.5*(ex1-ex2);
-	ck = 0.5*(ex1+ex2);
-	ckma = ck-1.0-rak*sk;
-	skma = sk-rak*ck;
-	
-	//      a(I)
-	
-	a1 = (e24*rgek*(al1+al2+ak1*al3)-eta22)*dd4;
-	if (ibig==0) {
-		a2 = e24*(al3*skma+al2*sk-al1*ck)*dd4;
-		a3 = e24*(eta22*dak2-0.5*d2+al3*ckma-al1*sk+al2*ck)*dd4;
-	}
-	
-	//      b(I)
-	
-	b1 = (1.5*reta*eta2d2-e12*rgek*(be1+be2+ak1*be3))*dd4;
-	if (ibig==0) {
-		b2 = e12*(-be3*skma-be2*sk+be1*ck)*dd4;
-		b3 = e12*(0.5*d2*eta2d-eta3d*eta2d2*dak2-be3*ckma+be1*sk-be2*ck)*dd4;
-	}
-	
-	//      V(I)
-	
-	v1 = (eta21*(eta2-2.0*reta+1.0e1)*2.5e-1-rgek*(vu4+vu5))*dd45;
-	if (ibig==0) {
-		v2 = (vu4*ck-vu5*sk)*dd45;
-		v3 = ((eta3-6.0*eta2+5.0)*d-eta6d*(2.0*eta3-3.0*eta2+18.0*reta+1.0e1)*dak2+e24*vu3+vu4*sk-vu5*ck)*dd45;
-	}
-	
-	
-	//       P(I)
-	
-	pp1 = ph1*ph1;
-	pp2 = ph2*ph2;
-	pp = pp1+pp2;
-	p1p2 = ph1*ph2*2.0;
-	p1 = (rgek*(pp1+pp2-p1p2)-0.5*eta2d)*dd2;
-	if (ibig==0) {
-		p2 = (pp*sk+p1p2*ck)*dd2;
-		p3 = (pp*ck+p1p2*sk+pp1-pp2)*dd2;
-	}
-	
-	//       T(I)
-	
-	t1 = ta3+ta4*a1+ta5*b1;
-	if (ibig!=0) {
-		
-		//		VERY LARGE SCREENING:  ASYMPTOTIC SOLUTION
-		
-  		v3 = ((eta3-6.0*eta2+5.0)*d-eta6d*(2.0*eta3-3.0*eta2+18.0*reta+1.0e1)*dak2+e24*vu3)*dd45;
-		t3 = ta4*a3+ta5*b3+e12*ta2 - 4.0e-1*reta*(reta+1.0e1)-1.0;
-		p3 = (pp1-pp2)*dd2;
-		b3 = e12*(0.5*d2*eta2d-eta3d*eta2d2*dak2+be3)*dd4;
-		a3 = e24*(eta22*dak2-0.5*d2-al3)*dd4;
-		um6 = t3*a3-e12*v3*v3;
-		um5 = t1*a3+a1*t3-e24*v1*v3;
-		um4 = t1*a1-e12*v1*v1;
-		al6 = e12*p3*p3;
-		al5 = e24*p1*p3-b3-b3-ak2;
-		al4 = e12*p1*p1-b1-b1;
-		w56 = um5*al6-al5*um6;
-		w46 = um4*al6-al4*um6;
-		fa = -w46/w56;
-		ca = -fa;
-		gMSAWave[3] = fa;
-		gMSAWave[2] = ca;
-		gMSAWave[1] = b1+b3*fa;
-		gMSAWave[0] = a1+a3*fa;
-		gMSAWave[8] = v1+v3*fa;
-		gMSAWave[14] = -(p1+p3*fa);
-		gMSAWave[15] = gMSAWave[14];
-		if (fabs(gMSAWave[15])<1.0e-3) {
-			gMSAWave[15] = 0.0;
-		}
-		gMSAWave[10] = gMSAWave[16];
-		
-	} else {
-        
-		t2 = ta4*a2+ta5*b2+e12*(ta1*ck-ta2*sk);
-		t3 = ta4*a3+ta5*b3+e12*(ta1*sk-ta2*(ck-1.0))-4.0e-1*reta*(reta+1.0e1)-1.0;
-		
-		//		MU(i)
-		
-		um1 = t2*a2-e12*v2*v2;
-		um2 = t1*a2+t2*a1-e24*v1*v2;
-		um3 = t2*a3+t3*a2-e24*v2*v3;
-		um4 = t1*a1-e12*v1*v1;
-		um5 = t1*a3+t3*a1-e24*v1*v3;
-		um6 = t3*a3-e12*v3*v3;
-		
-		//			GILLAN CONDITION ?
-		//
-		//			YES - G(X=1+) = 0
-		//
-		//			COEFFICIENTS AND FUNCTION VALUE
-		//
-		if ((ix==1) || (ix==3)) {
-			
-			//			NO - CALCULATE REMAINING COEFFICIENTS.
-			
-			//			LAMBDA(I)
-			
-			al1 = e12*p2*p2;
-			al2 = e24*p1*p2-b2-b2;
-			al3 = e24*p2*p3;
-			al4 = e12*p1*p1-b1-b1;
-			al5 = e24*p1*p3-b3-b3-ak2;
-			al6 = e12*p3*p3;
-			
-			//			OMEGA(I)
-			
-			w16 = um1*al6-al1*um6;
-			w15 = um1*al5-al1*um5;
-			w14 = um1*al4-al1*um4;
-			w13 = um1*al3-al1*um3;
-			w12 = um1*al2-al1*um2;
-			
-			w26 = um2*al6-al2*um6;
-			w25 = um2*al5-al2*um5;
-			w24 = um2*al4-al2*um4;
-			
-			w36 = um3*al6-al3*um6;
-			w35 = um3*al5-al3*um5;
-			w34 = um3*al4-al3*um4;
-			w32 = um3*al2-al3*um2;
-			//
-			w46 = um4*al6-al4*um6;
-			w56 = um5*al6-al5*um6;
-			w3526 = w35+w26;
-			w3425 = w34+w25;
-			
-			//			QUARTIC COEFFICIENTS
-			
-			w4 = w16*w16-w13*w36;
-			w3 = 2.0*w16*w15-w13*w3526-w12*w36;
-			w2 = w15*w15+2.0*w16*w14-w13*w3425-w12*w3526;
-			w1 = 2.0*w15*w14-w13*w24-w12*w3425;
-			w0 = w14*w14-w12*w24;
-			
-			//			ESTIMATE THE STARTING VALUE OF f
-			
-			if (ix==1) {
-				//				LARGE K
-				fap = (w14-w34-w46)/(w12-w15+w35-w26+w56-w32);
-			} else {
-				//				ASSUME NOT TOO FAR FROM GILLAN CONDITION.
-				//				IF BOTH RGEK AND RAK ARE SMALL, USE P-W ESTIMATE.
-				gMSAWave[14]=0.5*eta2d*dd2*exp(-rgek);
-				if (( gMSAWave[11]<=2.0) && ( gMSAWave[11]>=0.0) && ( gMSAWave[12]<=1.0)) {
-					e24g = e24*rgek*exp(rak);
-					pwk = sqrt(e24g);
-					qpw = (1.0-sqrt(1.0+2.0*d2*d*pwk/eta22))*eta21/d;
-					gMSAWave[14] = -qpw*qpw/e24+0.5*eta2d*dd2;
-				}
-  				pg = p1+gMSAWave[14];
-				ca = ak2*pg+2.0*(b3*pg-b1*p3)+e12*gMSAWave[14]*gMSAWave[14]*p3;
-				ca = -ca/(ak2*p2+2.0*(b3*p2-b2*p3));
-				fap = -(pg+p2*ca)/p3;
-			}
-			
-			//			AND REFINE IT ACCORDING TO NEWTON
-			ii=0;
-			do {
-				ii = ii+1;
-				if (ii>itm) {
-					//					FAILED TO CONVERGE IN ITM ITERATIONS
-					ir=-2;
-					return (ir);
-				}
-				fa = fap;
-				fun = w0+(w1+(w2+(w3+w4*fa)*fa)*fa)*fa;
-				fund = w1+(2.0*w2+(3.0*w3+4.0*w4*fa)*fa)*fa;
-				fap = fa-fun/fund;
-				del=fabs((fap-fa)/fa);
-			} while (del>acc);
-			
-			ir = ir+ii;
-			fa = fap;
-			ca = -(w16*fa*fa+w15*fa+w14)/(w13*fa+w12);
-			gMSAWave[14] = -(p1+p2*ca+p3*fa);
-			gMSAWave[15] = gMSAWave[14];
-			if (fabs(gMSAWave[15])<1.0e-3) {
-				gMSAWave[15] = 0.0;
-			}
-			gMSAWave[10] = gMSAWave[16];
-		} else {
-			ca = ak2*p1+2.0*(b3*p1-b1*p3);
-			ca = -ca/(ak2*p2+2.0*(b3*p2-b2*p3));
-			fa = -(p1+p2*ca)/p3;
-			if (ix==2) {
-				gMSAWave[15] = um1*ca*ca+(um2+um3*fa)*ca+um4+um5*fa+um6*fa*fa;
-			}
-			if (ix==4) {
-				gMSAWave[15] = -(p1+p2*ca+p3*fa);
-			}
-		}
-   		gMSAWave[3] = fa;
-		gMSAWave[2] = ca;
-		gMSAWave[1] = b1+b2*ca+b3*fa;
-		gMSAWave[0] = a1+a2*ca+a3*fa;
-		gMSAWave[8] = (v1+v2*ca+v3*fa)/gMSAWave[0];
-	}
-   	g24 = e24*rgek*ex1;
-	gMSAWave[7] = (rak*ak2*ca-g24)/(ak2*g24);
-	return (ir);
-}
-
-// called as DiamCyl(hcyl,rcyl)
-double
-DiamCyl(double hcyl, double rcyl)
-{
-	
-	double diam,a,b,t1,t2,ddd;
-	double pi;
-	
-	pi = 4.0*atan(1.0);
-	if (rcyl == 0 || hcyl == 0) {
-		return 0.0;
-	}
-	a = rcyl;
-	b = hcyl/2.0;
-	t1 = a*a*2.0*b/2.0;
-	t2 = 1.0 + (b/a)*(1.0+a/b/2.0)*(1.0+pi*a/b/2.0);
-	ddd = 3.0*t1*t2;
-	diam = pow(ddd,(1.0/3.0));
-	
-	return(diam);
-}
-
-//prolate OR oblate ellipsoids
-//aa is the axis of rotation
-//if aa>bb, then PROLATE
-//if aa<bb, then OBLATE
-// A. Isihara, J. Chem. Phys. 18, 1446 (1950)
-//returns DIAMETER
-// called as DiamEllip(aa,bb)
-double
-DiamEllip(double aa, double bb)
-{
-	
-	double ee,e1,bd,b1,bL,b2,del,ddd,diam;
-
-	if (aa == 0 || bb == 0) {
-		return 0.0;
-	}
-	if (aa == bb) {
-		return 2.0*aa;
-	}
-	if(aa>bb) {
-		ee = (aa*aa - bb*bb)/(aa*aa);
-	}else{
-		ee = (bb*bb - aa*aa)/(bb*bb);
-	}
-	
-	bd = 1.0-ee;
-	e1 = sqrt(ee);
-	b1 = 1.0 + asin(e1)/(e1*sqrt(bd));
-	bL = (1.0+e1)/(1.0-e1);
-	b2 = 1.0 + bd/2/e1*log(bL);
-	del = 0.75*b1*b2;
-	
-	ddd = 2.0*(del+1.0)*aa*bb*bb;		//volume is always calculated correctly
-	diam = pow(ddd,(1.0/3.0));
-	
-	return(diam);
-}
-
-double
-sqhcal(double qq, double gMSAWave[])
-{      	
-    double SofQ,etaz,akz,gekz,e24,x1,x2,ck,sk,ak2,qk,q2k,qk2,qk3,qqk,sink,cosk,asink,qcosk,aqk,inter; 		
-	//	WAVE gMSAWave = $"root:HayPenMSA:gMSAWave"
-
-	etaz = gMSAWave[10];
-	akz =  gMSAWave[12];
-	gekz =  gMSAWave[11];
-	e24 = 24.0*etaz;
-	x1 = exp(akz);
-	x2 = 0.0;
-	if ( gMSAWave[12]<20.0) {
-		x2 = exp(-akz);
-	}
-	ck = 0.5*(x1+x2);
-	sk = 0.5*(x1-x2);
-	ak2 = akz*akz;
-	
-	if (qq<=0.0) {
-		SofQ = -1.0/gMSAWave[0];
-	} else {
-		qk = qq/gMSAWave[13];
-		q2k = qk*qk;
-		qk2 = 1.0/q2k;
-		qk3 = qk2/qk;
-		qqk = 1.0/(qk*(q2k+ak2));
-		sink = sin(qk);
-		cosk = cos(qk);
-		asink = akz*sink;
-		qcosk = qk*cosk;
-		aqk = gMSAWave[0]*(sink-qcosk);
-		aqk=aqk+gMSAWave[1]*((2.0*qk2-1.0)*qcosk+2.0*sink-2.0/qk);
-		inter=24.0*qk3+4.0*(1.0-6.0*qk2)*sink;
-		aqk=(aqk+0.5*etaz*gMSAWave[0]*(inter-(1.0-12.0*qk2+24.0*qk2*qk2)*qcosk))*qk3;
-		aqk=aqk +gMSAWave[2]*(ck*asink-sk*qcosk)*qqk;
-		aqk=aqk +gMSAWave[3]*(sk*asink-qk*(ck*cosk-1.0))*qqk;
-		aqk=aqk +gMSAWave[3]*(cosk-1.0)*qk2;
-		aqk=aqk -gekz*(asink+qcosk)*qqk;
-		SofQ = 1.0/(1.0-e24*aqk);
-	}
-	return (SofQ);
-}
-
-///////////end of XOP
-
-
Index: src/sas/models/c_extension/libigor/libStructureFactor.h
===================================================================
--- src/sas/models/c_extension/libigor/libStructureFactor.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,14 +1,0 @@
-// header for SphereFit.c
-
-/* IGOR Fit Functions */
-double HardSphereStruct(double dp[], double q);
-double SquareWellStruct(double dp[], double q);
-double StickyHS_Struct(double dp[], double q);
-double HayterPenfoldMSA(double dp[], double q);
-double DiamCyl(double a, double b);
-double DiamEllip(double a, double b);
-
-//function prototypes
-double sqhcal(double qq, double gMSAWave[]);
-int sqfun(int ix, int ir, double gMSAWave[]);
-int sqcoef(int ir, double gMSAWave[]);
Index: src/sas/models/c_extension/libigor/libTwoPhase.c
===================================================================
--- src/sas/models/c_extension/libigor/libTwoPhase.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,555 +1,0 @@
-/*	TwoPhaseFit.c
-
-*/
-
-#include "StandardHeaders.h"			// Include ANSI headers, Mac headers
-#include "libTwoPhase.h"
-
-/* internal functions */
-static double
-gammln(double xx) {
-
-    double x,y,tmp,ser;
-    static double cof[6]={76.18009172947146,-86.50532032941677,
-    24.01409824083091,-1.231739572450155,
-    0.1208650973866179e-2,-0.5395239384953e-5};
-    int j;
-
-    y=x=xx;
-    tmp=x+5.5;
-    tmp -= (x+0.5)*log(tmp);
-    ser=1.000000000190015;
-    for (j=0;j<=5;j++) ser += cof[j]/++y;
-    return -tmp+log(2.5066282746310005*ser/x);
-}
-
-// scattering from the Teubner-Strey model for microemulsions - hardly needs to be an XOP...
-double
-TeubnerStreyModel(double dp[], double q)
-{
-	double inten,q2,q4;		//my local names
-	
-	q2 = q*q;
-	q4 = q2*q2;
-	
-	inten = 1.0/(dp[0]+dp[1]*q2+dp[2]*q4);
-	inten += dp[3];  
-	return(inten);
-}
-
-double
-Power_Law_Model(double dp[], double q)
-{
-	double qval;
-	double inten,A,m,bgd;		//my local names
-	
-	qval= q;
-	
-	A = dp[0];
-	m = dp[1];
-	bgd = dp[2];
-	inten = A*pow(qval,-m) + bgd;
-	return(inten);
-}
-
-
-double
-Peak_Lorentz_Model(double dp[], double q)
-{
-	double qval;
-	double inten,I0, qpk, dq,bgd;		//my local names
-	qval= q;
-	
-	I0 = dp[0];
-	qpk = dp[1];
-	dq = dp[2];
-	bgd = dp[3];
-	inten = I0/(1.0 + pow( (qval-qpk)/dq,2) ) + bgd;
-	
-	return(inten);
-}
-
-double
-Peak_Gauss_Model(double dp[], double q)
-{
-	double qval;
-	double inten,I0, qpk, dq,bgd;		//my local names
-	
-	qval= q;
-	
-	I0 = dp[0];
-	qpk = dp[1];
-	dq = dp[2];
-	bgd = dp[3];
-	inten = I0*exp(-0.5*pow((qval-qpk)/dq,2))+ bgd;
-	
-	return(inten);
-}
-
-double
-Lorentz_Model(double dp[], double q)
-{
-	double qval;
-	double inten,I0, L,bgd;		//my local names
-	
-	qval= q;
-	
-	I0 = dp[0];
-	L = dp[1];
-	bgd = dp[2];
-	inten = I0/(1.0 + (qval*L)*(qval*L)) + bgd;
-	
-	return(inten);
-}
-
-double
-Fractal(double dp[], double q)
-{
-	double x,pi;
-	double r0,Df,corr,phi,sldp,sldm,bkg;
-	double pq,sq,ans;
-	
-	pi = 4.0*atan(1.0);
-	x=q;
-	
-	phi = dp[0];		// volume fraction of building block spheres...
-	r0 = dp[1];		//  radius of building block
-	Df = dp[2];		//  fractal dimension
-	corr = dp[3];		//  correlation length of fractal-like aggregates
-	sldp = dp[4];		// SLD of building block
-	sldm = dp[5];		// SLD of matrix or solution
-	bkg = dp[6];		//  flat background 
-	
-	//calculate P(q) for the spherical subunits, units cm-1 sr-1
-	pq = 1.0e8*phi*4.0/3.0*pi*r0*r0*r0*(sldp-sldm)*(sldp-sldm)*pow((3*(sin(x*r0) - x*r0*cos(x*r0))/pow((x*r0),3)),2);
-	
-	//calculate S(q)
-	sq = Df*exp(gammln(Df-1.0))*sin((Df-1.0)*atan(x*corr));
-	sq /= pow((x*r0),Df) * pow((1.0 + 1.0/(x*corr)/(x*corr)),((Df-1.0)/2.0));
-	sq += 1.0;
-	//combine and return
-	ans = pq*sq + bkg;
-	
-	return(ans);
-}
-
-// 6 JUL 2009 SRK changed definition of Izero scale factor to be uncorrelated with range
-//
-double
-DAB_Model(double dp[], double q)
-{
-	double qval,inten;
-	double Izero, range, incoh;
-	
-	qval= q;
-	Izero = dp[0];
-	range = dp[1];
-	incoh = dp[2]; 
-	
-	inten = (Izero*range*range*range)/pow((1.0 + (qval*range)*(qval*range)),2) + incoh;
-	
-	return(inten);
-}
-
-// G. Beaucage's Unified Model (1-4 levels)
-//
-double
-OneLevel(double dp[], double q)
-{
-	double x,ans,erf1;
-	double G1,Rg1,B1,Pow1,bkg,scale;
-	
-	x=q;
-	scale = dp[0];
-	G1 = dp[1];
-	Rg1 = dp[2];
-	B1 = dp[3];
-	Pow1 = dp[4];
-	bkg = dp[5];
-	
-	erf1 = erf( (x*Rg1/sqrt(6.0)));
-	
-	ans = G1*exp(-x*x*Rg1*Rg1/3.0);
-	ans += B1*pow((erf1*erf1*erf1/x),Pow1);
-	
-	if(x == 0) {
-		ans = G1;
-	}
-	
-	ans *= scale;
-	ans += bkg;
-	return(ans);
-}
-
-// G. Beaucage's Unified Model (1-4 levels)
-//
-double
-TwoLevel(double dp[], double q)
-{
-	double x;
-	double ans,G1,Rg1,B1,G2,Rg2,B2,Pow1,Pow2,bkg;
-	double erf1,erf2,scale;
-	
-	x=q;
-	
-	scale = dp[0];
-	G1 = dp[1];	//equivalent to I(0)
-	Rg1 = dp[2];
-	B1 = dp[3];
-	Pow1 = dp[4];
-	G2 = dp[5];
-	Rg2 = dp[6];
-	B2 = dp[7];
-	Pow2 = dp[8];
-	bkg = dp[9];
-	
-	erf1 = erf( (x*Rg1/sqrt(6.0)) );
-	erf2 = erf( (x*Rg2/sqrt(6.0)) );
-	//Print erf1
-	
-	ans = G1*exp(-x*x*Rg1*Rg1/3.0);
-	ans += B1*exp(-x*x*Rg2*Rg2/3.0)*pow((erf1*erf1*erf1/x),Pow1);
-	ans += G2*exp(-x*x*Rg2*Rg2/3.0);
-	ans += B2*pow((erf2*erf2*erf2/x),Pow2);
-
-	if(x == 0) {
-		ans = G1+G2;
-	}
-	
-	ans *= scale;
-	ans += bkg;
-	
-	return(ans);
-}
-
-// G. Beaucage's Unified Model (1-4 levels)
-//
-double
-ThreeLevel(double dp[], double q)
-{
-	double x;
-	double ans,G1,Rg1,B1,G2,Rg2,B2,Pow1,Pow2,bkg;
-	double G3,Rg3,B3,Pow3,erf3;
-	double erf1,erf2,scale;
-	
-	x=q;
-	
-	scale = dp[0];
-	G1 = dp[1];	//equivalent to I(0)
-	Rg1 = dp[2];
-	B1 = dp[3];
-	Pow1 = dp[4];
-	G2 = dp[5];
-	Rg2 = dp[6];
-	B2 = dp[7];
-	Pow2 = dp[8];
-	G3 = dp[9];
-	Rg3 = dp[10];
-	B3 = dp[11];
-	Pow3 = dp[12];
-	bkg = dp[13];
-	
-	erf1 = erf( (x*Rg1/sqrt(6.0)) );
-	erf2 = erf( (x*Rg2/sqrt(6.0)) );
-	erf3 = erf( (x*Rg3/sqrt(6.0)) );
-	//Print erf1
-	
-	ans = G1*exp(-x*x*Rg1*Rg1/3.0) + B1*exp(-x*x*Rg2*Rg2/3.0)*pow((erf1*erf1*erf1/x),Pow1);
-	ans += G2*exp(-x*x*Rg2*Rg2/3.0) + B2*exp(-x*x*Rg3*Rg3/3.0)*pow((erf2*erf2*erf2/x),Pow2);
-	ans += G3*exp(-x*x*Rg3*Rg3/3.0) + B3*pow((erf3*erf3*erf3/x),Pow3);
-
-	if(x == 0) {
-		ans = G1+G2+G3;
-	}
-	
-	ans *= scale;
-	ans += bkg;
-	
-	return(ans);
-}
-
-// G. Beaucage's Unified Model (1-4 levels)
-//
-double
-FourLevel(double dp[], double q)
-{
-	double x;
-	double ans,G1,Rg1,B1,G2,Rg2,B2,Pow1,Pow2,bkg;
-	double G3,Rg3,B3,Pow3,erf3;
-	double G4,Rg4,B4,Pow4,erf4;
-	double erf1,erf2,scale;
-	
-	x=q;
-	
-	scale = dp[0];
-	G1 = dp[1];	//equivalent to I(0)
-	Rg1 = dp[2];
-	B1 = dp[3];
-	Pow1 = dp[4];
-	G2 = dp[5];
-	Rg2 = dp[6];
-	B2 = dp[7];
-	Pow2 = dp[8];
-	G3 = dp[9];
-	Rg3 = dp[10];
-	B3 = dp[11];
-	Pow3 = dp[12];
-	G4 = dp[13];
-	Rg4 = dp[14];
-	B4 = dp[15];
-	Pow4 = dp[16];
-	bkg = dp[17];
-	
-	erf1 = erf( (x*Rg1/sqrt(6.0)) );
-	erf2 = erf( (x*Rg2/sqrt(6.0)) );
-	erf3 = erf( (x*Rg3/sqrt(6.0)) );
-	erf4 = erf( (x*Rg4/sqrt(6.0)) );
-	
-	ans = G1*exp(-x*x*Rg1*Rg1/3.0) + B1*exp(-x*x*Rg2*Rg2/3.0)*pow((erf1*erf1*erf1/x),Pow1);
-	ans += G2*exp(-x*x*Rg2*Rg2/3.0) + B2*exp(-x*x*Rg3*Rg3/3.0)*pow((erf2*erf2*erf2/x),Pow2);
-	ans += G3*exp(-x*x*Rg3*Rg3/3.0) + B3*exp(-x*x*Rg4*Rg4/3.0)*pow((erf3*erf3*erf3/x),Pow3);
-	ans += G4*exp(-x*x*Rg4*Rg4/3.0) + B4*pow((erf4*erf4*erf4/x),Pow4);
-
-	if(x == 0) {
-		ans = G1+G2+G3+G4;
-	}
-	
-	ans *= scale;
-	ans += bkg;
-	
-    return(ans);
-}
-
-double
-BroadPeak(double dp[], double q)
-{
-	// variables are:							
-	//[0] Porod term scaling
-	//[1] Porod exponent
-	//[2] Lorentzian term scaling
-	//[3] Lorentzian screening length [A]
-	//[4] peak location [1/A]
-	//[5] Lorentzian exponent
-	//[6] background
-	
-	double aa,nn,cc,LL,Qzero,mm,bgd,inten,qval;
-	qval= q;
-	aa = dp[0];
-	nn = dp[1];
-	cc = dp[2]; 
-	LL = dp[3]; 
-	Qzero = dp[4]; 
-	mm = dp[5]; 
-	bgd = dp[6]; 
-	
-	inten = aa/pow(qval,nn);
-	inten += cc/(1.0 + pow((fabs(qval-Qzero)*LL),mm) );
-	inten += bgd;
-	
-	return(inten);
-}
-
-double
-CorrLength(double dp[], double q)
-{
-	// variables are:							
-	//[0] Porod term scaling
-	//[1] Porod exponent
-	//[2] Lorentzian term scaling
-	//[3] Lorentzian screening length [A]
-	//[4] Lorentzian exponent
-	//[5] background
-	
-	double aa,nn,cc,LL,mm,bgd,inten,qval;
-	qval= q;
-	aa = dp[0];
-	nn = dp[1];
-	cc = dp[2]; 
-	LL = dp[3]; 
-	mm = dp[4]; 
-	bgd = dp[5]; 
-	
-	inten = aa/pow(qval,nn);
-	inten += cc/(1.0 + pow((qval*LL),mm) );
-	inten += bgd;
-	
-	return(inten);
-}
-
-double
-TwoLorentzian(double dp[], double q)
-{
-	// variables are:							
-	//[0] Lorentzian term scaling
-	//[1] Lorentzian screening length [A]
-	//[2] Lorentzian exponent
-	//[3] Lorentzian #2 term scaling
-	//[4] Lorentzian #2 screening length [A]
-	//[5] Lorentzian #2 exponent
-	//[6] background
-		
-	double aa,LL1,nn,cc,LL2,mm,bgd,inten,qval;
-	qval= q;
-	aa = dp[0];
-	LL1 = dp[1];
-	nn = dp[2]; 
-	cc = dp[3]; 
-	LL2 = dp[4]; 
-	mm = dp[5]; 
-	bgd= dp[6];
-	
-	inten = aa/(1.0 + pow((qval*LL1),nn) );
-	inten += cc/(1.0 + pow((qval*LL2),mm) );
-	inten += bgd;
-	
-	return(inten);
-}
-
-double
-TwoPowerLaw(double dp[], double q)
-{
-	//[0] Coefficient
-	//[1] (-) Power @ low Q
-	//[2] (-) Power @ high Q
-	//[3] crossover Q-value
-	//[4] incoherent background
-		
-	double A, m1,m2,qc,bgd,scale,inten,qval;
-	qval= q;
-	A = dp[0];
-	m1 = dp[1];
-	m2 = dp[2]; 
-	qc = dp[3]; 
-	bgd = dp[4]; 
-	
-	if(qval<=qc){
-		inten = A*pow(qval,-1.0*m1);
-	} else {
-		scale = A*pow(qc,-1.0*m1) / pow(qc,-1.0*m2);
-		inten = scale*pow(qval,-1.0*m2);
-	}
-	
-	inten += bgd;
-	
-	return(inten);
-}
-
-double
-PolyGaussCoil(double dp[], double x)
-{
-	//w[0] = scale
-	//w[1] = radius of gyration [ï¿œ]
-	//w[2] = polydispersity, ratio of Mw/Mn
-	//w[3] = bkg [cm-1]
-		
-	double scale,bkg,Rg,uval,Mw_Mn,inten,xi;
-
-	scale = dp[0];
-	Rg = dp[1];
-	Mw_Mn = dp[2]; 
-	bkg = dp[3]; 
-	
-	uval = Mw_Mn - 1.0;
-	if(uval == 0.0) {
-		uval = 1e-6;		//avoid divide by zero error
-	}
-	
-	xi = Rg*Rg*x*x/(1.0+2.0*uval);
-	
-	if(xi < 1e-3) {
-		return(scale+bkg);		//limiting value
-	}
-	
-	inten = 2.0*(pow((1.0+uval*xi),(-1.0/uval))+xi-1.0);
-	inten /= (1.0+uval)*xi*xi;
-
-	inten *= scale;
-	//add in the background
-	inten += bkg;	
-	return(inten);
-}
-
-double
-GaussLorentzGel(double dp[], double x)
-{
-	//[0] Gaussian scale factor
-	//[1] Gaussian (static) screening length
-	//[2] Lorentzian (fluctuation) scale factor
-	//[3] Lorentzian screening length
-	//[4] incoherent background
-		
-	double Ig0,gg,Il0,ll,bgd,inten;
-
-	Ig0 = dp[0];
-	gg = dp[1];
-	Il0 = dp[2]; 
-	ll = dp[3];
-	bgd = dp[4]; 
-	
-	inten = Ig0*exp(-1.0*x*x*gg*gg/2.0) + Il0/(1.0 + (x*ll)*(x*ll)) + bgd;
-	
-	return(inten);
-}
-
-
-double
-GaussianShell(double w[], double x)
-{
-	// variables are:							
-	//[0] scale
-	//[1] radius (ï¿œ)
-	//[2] thick (ï¿œ) (thickness parameter - this is the std. dev. of the Gaussian width of the shell)
-	//[3] polydispersity of the radius
-	//[4] sld shell (ï¿œ-2)
-	//[5] sld solvent
-	//[6] background (cm-1)
-	
-	double scale,rad,delrho,bkg,del,thick,pd,sig,pi;
-	double t1,t2,t3,t4,retval,exfact,vshell,vexcl,sldShell,sldSolvent;
-	scale = w[0];
-	rad = w[1];
-	thick = w[2];
-	pd = w[3];
-	sldShell = w[4];
-	sldSolvent = w[5];
-	bkg = w[6];
-	
-	delrho = w[4] - w[5];
-	sig = pd*rad;
-	
-	pi = 4.0*atan(1.0);
-	
-	///APPROXIMATION (see eqn 4 - but not a bad approximation)
-	// del is the equivalent shell thickness with sharp boundaries, centered at mean radius
-	del = thick*sqrt(2.0*pi);
-	
-	// calculate the polydisperse shell volume and the excluded volume
-	vshell=4.0*pi/3.0*( pow((rad+del/2.0),3) - pow((rad-del/2.0),3) ) *(1.0+pd*pd);
-	vexcl=4.0*pi/3.0*( pow((rad+del/2.0),3) ) *(1.0+pd*pd);
-	
-	//intensity, eqn 9(a-d)
-	exfact = exp(-2.0*sig*sig*x*x);
-	
-	t1 = 0.5*x*x*thick*thick*thick*thick*(1.0+cos(2.0*x*rad)*exfact);
-	t2 = x*thick*thick*(rad*sin(2.0*x*rad) + 2.0*x*sig*sig*cos(2.0*x*rad))*exfact;
-	t3 = 0.5*rad*rad*(1.0-cos(2.0*x*rad)*exfact);
-	t4 = 0.5*sig*sig*(1.0+4.0*x*rad*sin(2.0*x*rad)*exfact+cos(2.0*x*rad)*(4.0*sig*sig*x*x-1.0)*exfact);
-	
-	retval = t1+t2+t3+t4;
-	retval *= exp(-1.0*x*x*thick*thick);
-	retval *= (del*del/x/x);
-	retval *= 16.0*pi*pi*delrho*delrho*scale;
-	retval *= 1.0e8;
-	
-	//NORMALIZED by the AVERAGE shell volume, since scale is the volume fraction of material
-//	retval /= vshell
-	retval /= vexcl;
-	//re-normalize by polydisperse sphere volume, Gaussian distribution
-	retval /= (1.0+3.0*pd*pd);
-	
-	retval += bkg;
-	
-	return(retval);
-}
-
-
Index: src/sas/models/c_extension/libigor/libTwoPhase.h
===================================================================
--- src/sas/models/c_extension/libigor/libTwoPhase.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,23 +1,0 @@
-// header for TwoPhaseFit.c
-
-//function prototypes
-/* IGOR Fit Functions */
-double TeubnerStreyModel(double dp[], double q);
-double Power_Law_Model(double dp[], double q);
-double Peak_Lorentz_Model(double dp[], double q);
-double Peak_Gauss_Model(double dp[], double q);
-double Lorentz_Model(double dp[], double q);
-double Fractal(double dp[], double q);
-double DAB_Model(double dp[], double q);
-double OneLevel(double dp[], double q);
-double TwoLevel(double dp[], double q);
-double ThreeLevel(double dp[], double q);
-double FourLevel(double dp[], double q);
-double BroadPeak(double dp[], double q);
-double CorrLength(double dp[], double q);
-double TwoLorentzian(double dp[], double q);
-double TwoPowerLaw(double dp[], double q);
-double PolyGaussCoil(double dp[], double q);
-double GaussLorentzGel(double dp[], double q);
-double GaussianShell(double dp[], double q);
-
