Index: src/sas/sascalc/calculator/c_extensions/libfunc.c
===================================================================
--- src/sas/sascalc/calculator/c_extensions/libfunc.c	(revision b6c8abea4ddb688eaf519b2c53bbd8aeebf55489)
+++ src/sas/sascalc/calculator/c_extensions/libfunc.c	(revision 144e032af2559d8208e907563f404ab479862dbf)
@@ -95,5 +95,5 @@
 // spintheta: angle (anti-clock-wise) between neutron spin(up) and x axis
 // Note: all angles are in degrees.
-polar_sld cal_msld(int isangle, double qx, double qy, double bn,
+void cal_msld(polar_sld *p_sld, int isangle, double qx, double qy, double bn,
 				double m01, double mtheta1, double mphi1,
 				double spinfraci, double spinfracf, double spintheta)
@@ -124,91 +124,91 @@
 	double my = 0.0;
 	double mz = 0.0;
-	polar_sld p_sld;
-	p_sld.uu = sld;
-	p_sld.dd = sld;
-	p_sld.re_ud = 0.0;
-	p_sld.im_ud = 0.0;
-	p_sld.re_du = 0.0;
-	p_sld.im_du = 0.0;
+	double uu = sld;
+	double dd = sld;
+	double re_ud = 0.0;
+	double im_ud = 0.0;
+	double re_du = 0.0;
+	double im_du = 0.0;
 
 	//No mag means no further calculation
-	if (isangle>0){
+	if (isangle>0) {
 		if (m_max < 1.0e-32){
-			p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu;
-			p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd;
-			return p_sld;
-		}
-	}
-	else{
-		if (fabs(m_max)< 1.0e-32 && fabs(m_phi)< 1.0e-32 && fabs(m_theta)< 1.0e-32){
-			p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu;
-			p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd;
-			return p_sld;
-		}
-	}
-
-	//These are needed because of the precision of inputs
-	if (in_spin < 0.0) in_spin = 0.0;
-	if (in_spin > 1.0) in_spin = 1.0;
-	if (out_spin < 0.0) out_spin = 0.0;
-	if (out_spin > 1.0) out_spin = 1.0;
-
-	if (q_x == 0.0) q_angle = pi / 2.0;
-	else q_angle = atan(q_y/q_x);
-	if (q_y < 0.0 && q_x < 0.0) q_angle -= pi;
-	else if (q_y > 0.0 && q_x < 0.0) q_angle += pi;
-
-	q_angle = pi/2.0 - q_angle;
-	if (q_angle > pi) q_angle -= 2.0 * pi;
-	else if (q_angle < -pi) q_angle += 2.0 * pi;
-
-	if (fabs(q_x) < 1.0e-16 && fabs(q_y) < 1.0e-16){
-		m_perp = 0.0;
-		}
-	else {
-		m_perp = m_max;
-		}
-	if (is_angle > 0){
-		m_phi *= pi/180.0;
-		m_theta *= pi/180.0;
-		mx = m_perp * cos(m_theta) * cos(m_phi);
-		my = m_perp * sin(m_theta);
-		mz = -(m_perp * cos(m_theta) * sin(m_phi));
-	}
-	else{
-		mx = m_perp;
-		my = m_phi;
-		mz = m_theta;
-	}
-	//ToDo: simplify these steps
-	// m_perp1 -m_perp2
-	m_perp_x = (mx) *  cos(q_angle);
-	m_perp_x -= (my) * sin(q_angle);
-	m_perp_y = m_perp_x;
-	m_perp_x *= cos(-q_angle);
-	m_perp_y *= sin(-q_angle);
-	m_perp_z = mz;
-
-	m_sigma_x = (m_perp_x * cos(-s_theta) - m_perp_y * sin(-s_theta));
-	m_sigma_y = (m_perp_x * sin(-s_theta) + m_perp_y * cos(-s_theta));
-	m_sigma_z = (m_perp_z);
-
-	//Find b
-	p_sld.uu -= m_sigma_x;
-	p_sld.dd += m_sigma_x;
-	p_sld.re_ud = m_sigma_y;
-	p_sld.re_du = m_sigma_y;
-	p_sld.im_ud = m_sigma_z;
-	p_sld.im_du = -m_sigma_z;
-
-	p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu;
-	p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd;
-
-	p_sld.re_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * p_sld.re_ud;
-	p_sld.im_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * p_sld.im_ud;
-	p_sld.re_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * p_sld.re_du;
-	p_sld.im_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * p_sld.im_du;
-
-	return p_sld;
+			uu = sqrt(sqrt(in_spin * out_spin)) * uu;
+			dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * dd;
+		}
+	}
+	else if (fabs(m_max)< 1.0e-32 && fabs(m_phi)< 1.0e-32 && fabs(m_theta)< 1.0e-32){
+			uu = sqrt(sqrt(in_spin * out_spin)) * uu;
+			dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * dd;
+	} else {
+
+		//These are needed because of the precision of inputs
+		if (in_spin < 0.0) in_spin = 0.0;
+		if (in_spin > 1.0) in_spin = 1.0;
+		if (out_spin < 0.0) out_spin = 0.0;
+		if (out_spin > 1.0) out_spin = 1.0;
+
+		if (q_x == 0.0) q_angle = pi / 2.0;
+		else q_angle = atan(q_y/q_x);
+		if (q_y < 0.0 && q_x < 0.0) q_angle -= pi;
+		else if (q_y > 0.0 && q_x < 0.0) q_angle += pi;
+
+		q_angle = pi/2.0 - q_angle;
+		if (q_angle > pi) q_angle -= 2.0 * pi;
+		else if (q_angle < -pi) q_angle += 2.0 * pi;
+
+		if (fabs(q_x) < 1.0e-16 && fabs(q_y) < 1.0e-16){
+			m_perp = 0.0;
+			}
+		else {
+			m_perp = m_max;
+			}
+		if (is_angle > 0){
+			m_phi *= pi/180.0;
+			m_theta *= pi/180.0;
+			mx = m_perp * cos(m_theta) * cos(m_phi);
+			my = m_perp * sin(m_theta);
+			mz = -(m_perp * cos(m_theta) * sin(m_phi));
+		}
+		else{
+			mx = m_perp;
+			my = m_phi;
+			mz = m_theta;
+		}
+		//ToDo: simplify these steps
+		// m_perp1 -m_perp2
+		m_perp_x = (mx) *  cos(q_angle);
+		m_perp_x -= (my) * sin(q_angle);
+		m_perp_y = m_perp_x;
+		m_perp_x *= cos(-q_angle);
+		m_perp_y *= sin(-q_angle);
+		m_perp_z = mz;
+
+		m_sigma_x = (m_perp_x * cos(-s_theta) - m_perp_y * sin(-s_theta));
+		m_sigma_y = (m_perp_x * sin(-s_theta) + m_perp_y * cos(-s_theta));
+		m_sigma_z = (m_perp_z);
+
+		//Find b
+		uu -= m_sigma_x;
+		dd += m_sigma_x;
+		re_ud = m_sigma_y;
+		re_du = m_sigma_y;
+		im_ud = m_sigma_z;
+		im_du = -m_sigma_z;
+
+		uu = sqrt(sqrt(in_spin * out_spin)) * uu;
+		dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * dd;
+
+		re_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * re_ud;
+		im_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * im_ud;
+		re_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * re_du;
+		im_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * im_du;
+	}
+	p_sld->uu = uu;
+	p_sld->dd = dd;
+	p_sld->re_ud = re_ud;
+	p_sld->im_ud = im_ud;
+	p_sld->re_du = re_du;
+	p_sld->im_du = im_du;
 }
 
