diff maths/Polyfit.h @ 268:9aedf5ea8c35

* remove exceptions from Polyfit, return bool instead of int from isModeMinor
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 07 Feb 2008 10:01:38 +0000
parents a98dd8ec96f8
children 31f22daeba64
line wrap: on
line diff
--- a/maths/Polyfit.h	Fri Feb 01 16:46:36 2008 +0000
+++ b/maths/Polyfit.h	Thu Feb 07 10:01:38 2008 +0000
@@ -40,10 +40,10 @@
  // Modified by CLandone for VC6 Aug 2004
  ///////////////////////////////////////////////////////////////////////////////
 
+#include <iostream>
 
 using std::vector;
 
-
 class TPolyFit
 {
     typedef vector<vector<double> > Matrix;
@@ -116,12 +116,18 @@
     zeroise(g, nterms);
     zeroise(a, nterms, nterms);
     zeroise(xmatr, npoints, nterms);
-    if(nterms < 1)
-	throw "PolyFit called with less than one term";
-    if(npoints < 2)
-	throw "PolyFit called with less than two points";
-    if(npoints != y.size())
-	throw "PolyFit called with x and y of unequal size";
+    if (nterms < 1) {
+        std::cerr << "ERROR: PolyFit called with less than one term" << std::endl;
+        return 0;
+    }
+    if(npoints < 2) {
+        std::cerr << "ERROR: PolyFit called with less than two points" << std::endl;
+        return 0;
+    }
+    if(npoints != y.size()) {
+        std::cerr << "ERROR: PolyFit called with x and y of unequal size" << std::endl;
+        return 0;
+    }
     for(i = 0; i < npoints; ++i)
     {
 	//      { setup x matrix }
@@ -247,7 +253,8 @@
     {
 	if(index [k][2] != 0)
 	{
-	    throw "Error in GaussJordan: matrix is singular";
+            std::cerr << "ERROR: Error in PolyFit::GaussJordan: matrix is singular" << std::endl;
+            return false;
 	}
     }
 
@@ -290,8 +297,10 @@
 	    {
 		for(int k = 0; k < ncol; ++k)
 		{
-		    if(index[k][2] > 0)
-			throw "Error in GaussJordan2: matrix is singular";
+		    if(index[k][2] > 0) {
+                        std::cerr << "ERROR: Error in PolyFit::GaussJordan2: matrix is singular" << std::endl;
+                        return false;
+                    }
 
 		    if(index[k][2] < 0 && fabs(b[j][k]) > big)
 		    {