Index: pr_inversion/c_extensions/Cinvertor.c
===================================================================
--- pr_inversion/c_extensions/Cinvertor.c	(revision f71287f458148547d69aae7ddc900f1afde663f6)
+++ pr_inversion/c_extensions/Cinvertor.c	(revision 43c0a8eb8df558118a4b4ec7f771a56fd0e81893)
@@ -492,9 +492,10 @@
 	PyObject *err_obj;
 	Py_ssize_t npars2;
-	  
+	int i; 
+	
 	if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL;
-	OUTVECTOR(data_obj,pars,npars);
+	OUTVECTOR(data_obj,pars,npars); 
 	OUTVECTOR(err_obj,pars_err,npars2);
-		
+
 	pr_err(pars, pars_err, self->params.d_max, npars, r, &pr_value, &pr_err_value);
 	return Py_BuildValue("ff", pr_value, pr_err_value);	
@@ -537,4 +538,38 @@
 
 	return Py_BuildValue("i", count );	
+	
+}
+
+static PyObject * get_positive(Cinvertor *self, PyObject *args) {
+	double *pars;
+	PyObject *data_obj;
+	Py_ssize_t npars;
+	double fraction;
+	 
+	if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL;
+	OUTVECTOR(data_obj,pars,npars);
+	
+	fraction = positive_integral(pars, self->params.d_max, npars, 100);
+
+	return Py_BuildValue("f", fraction );	
+	
+}
+
+static PyObject * get_pos_err(Cinvertor *self, PyObject *args) {
+	double *pars;
+	double *pars_err;
+	PyObject *data_obj;
+	PyObject *err_obj;
+	Py_ssize_t npars;
+	Py_ssize_t npars2;
+	double fraction;
+	
+	if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL;
+	OUTVECTOR(data_obj,pars,npars); 
+	OUTVECTOR(err_obj,pars_err,npars2);
+	
+	fraction = positive_errors(pars, pars_err, self->params.d_max, npars, 51);
+
+	return Py_BuildValue("f", fraction );	
 	
 }
@@ -567,4 +602,6 @@
 		   {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""},
 		   {"get_peaks", (PyCFunction)get_peaks, METH_VARARGS, ""},
+		   {"get_positive", (PyCFunction)get_positive, METH_VARARGS, ""},
+		   {"get_pos_err", (PyCFunction)get_pos_err, METH_VARARGS, ""},
    
    {NULL}
Index: pr_inversion/c_extensions/invertor.c
===================================================================
--- pr_inversion/c_extensions/invertor.c	(revision f71287f458148547d69aae7ddc900f1afde663f6)
+++ pr_inversion/c_extensions/invertor.c	(revision 43c0a8eb8df558118a4b4ec7f771a56fd0e81893)
@@ -100,5 +100,6 @@
     	func_value = ortho(d_max, i+1, r);
         sum += pars[i] * func_value;
-        sum_err += err[i]*err[i]*func_value*func_value;
+        //sum_err += err[i]*err[i]*func_value*func_value;
+        sum_err += err[i*n_c+i]*func_value*func_value;
     }
     *pr_value = sum;
@@ -115,5 +116,5 @@
 double dprdr(double *pars, double d_max, int n_c, double r) {
     double sum = 0.0; 
-	int i;
+	int i; 
     for (i=0; i<n_c; i++) {
         sum += pars[i] * 2.0*(sin(pi*(i+1)*r/d_max) + pi*(i+1)*r/d_max * cos(pi*(i+1)*r/d_max));
@@ -180,2 +181,46 @@
 }
 
+/**
+ * Get the fraction of the integral of P(r) over the whole range
+ * of r that is above zero.
+ * A valid P(r) is define as being positive for all r.
+ */
+double positive_integral(double *pars, double d_max, int n_c, int nslice) {
+    double r; 
+    double value;
+	int i;
+	double sum_pos = 0.0;
+	double sum = 0.0;
+	
+    for (i=0; i<nslice; i++) {
+    	r = d_max/(1.0*nslice)*i;
+    	value = pr(pars, d_max, n_c, r);
+    	if (value>0.0) sum_pos += value;
+    	sum += value;
+    }
+    return sum_pos/sum;
+}
+
+/**
+ * Get the fraction of the integral of P(r) over the whole range
+ * of r that is at least one sigma above zero.
+ */
+double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice) {
+    double r; 
+    double value;
+	int i; 
+	double sum_pos = 0.0;
+	double sum = 0.0;
+	double pr_val;
+	double pr_val_err;
+	
+    for (i=0; i<nslice; i++) {
+    	r = d_max/(1.0*nslice)*i;
+    	pr_err(pars, err, d_max, n_c, r, &pr_val, &pr_val_err);
+    	if (pr_val>pr_val_err) sum_pos += pr_val;
+    	sum += pr_val;
+    	
+
+    }
+    return sum_pos/sum;
+}
Index: pr_inversion/c_extensions/invertor.h
===================================================================
--- pr_inversion/c_extensions/invertor.h	(revision f71287f458148547d69aae7ddc900f1afde663f6)
+++ pr_inversion/c_extensions/invertor.h	(revision 43c0a8eb8df558118a4b4ec7f771a56fd0e81893)
@@ -33,4 +33,6 @@
 		double r, double *pr_value, double *pr_value_err);
 int npeaks(double *pars, double d_max, int n_c, int nslice);
+double positive_integral(double *pars, double d_max, int n_c, int nslice);
+double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice);
 
 #endif
