Index: trunk/psLib/src/imageops/psImageMapFit.c
===================================================================
--- trunk/psLib/src/imageops/psImageMapFit.c	(revision 28667)
+++ trunk/psLib/src/imageops/psImageMapFit.c	(revision 30031)
@@ -48,8 +48,10 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
+bool psImageMapFit(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                    const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
     // XXX Add Asserts
+
+    *goodFit = false;
 
     // dimensions of the output map image
@@ -81,4 +83,5 @@
         map->map->data.F32[0][0]   = psStatsGetValue(map->stats, mean);
         map->error->data.F32[0][0] = psStatsGetValue(map->stats, stdev);
+	*goodFit = true;
         return true;
     }
@@ -86,10 +89,10 @@
     if (Nx == 1) {
         bool status;
-        status = psImageMapFit1DinY (map, mask, maskValue, x, y, f, df);
+        status = psImageMapFit1DinY (goodFit, map, mask, maskValue, x, y, f, df);
         return status;
     }
     if (Ny == 1) {
         bool status;
-        status = psImageMapFit1DinX (map, mask, maskValue, x, y, f, df);
+        status = psImageMapFit1DinX (goodFit, map, mask, maskValue, x, y, f, df);
         return status;
     }
@@ -310,8 +313,7 @@
 
     if (!psMatrixGJSolve(A, B)) {
-        psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.  Returning NULL.\n");
         psFree (A);
         psFree (B);
-        return false;
+        return true;
     }
 
@@ -337,9 +339,10 @@
     psFree (Empty);
 
+    *goodFit = true;
     return true;
 }
 
 // measure residuals on each pass and clip outliers based on stats
-bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
+bool psImageMapClipFit(bool *goodFit, psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -351,4 +354,6 @@
     psAssert(f, "impossible");
 
+    *goodFit = false;
+
     // the user supplies one of various stats option pairs,
     // determine the desired mean and stdev STATS options:
@@ -393,5 +398,5 @@
         psTrace("psLib.imageops", 6, "Loop iteration %d.  Calling psImageMapFit()\n", N);
         psS32 Nkeep = 0;
-        if (!psImageMapFit(map, mask, maskValue, x, y, f, df)) {
+        if (!psImageMapFit(goodFit, map, mask, maskValue, x, y, f, df)) {
             psError(PS_ERR_UNKNOWN, false, "Could not fit image map.\n");
             psFree(resid);
@@ -399,4 +404,8 @@
             return false;
         }
+	if (!goodFit) {
+	    psWarning ("bad fit to image map, try something else");
+	    return true;
+	}
 
         psVector *fit = psImageMapEvalVector(map, mask, maskValue, x, y);
@@ -454,13 +463,16 @@
     psFree(resid);
     if (!inMask) psFree (mask);
+    *goodFit = true; // XXX probably don't need to set this (set by psImageMapFit)
     return true;
 }
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
+bool psImageMapFit1DinY(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
     // XXX Add Asserts
     assert (map->binning->nXruff == 1);
+
+    *goodFit = false;
 
     // dimensions of the output map image
@@ -578,9 +590,8 @@
 
     if (!psMatrixGJSolve(A, B)) {
-        psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations.\n");
         psFree (A);
         psFree (B);
 	psFree (Empty);
-        return false;
+        return true;
     }
 
@@ -602,13 +613,16 @@
     psFree (Empty);
 
+    *goodFit = true;
     return true;
 }
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
+bool psImageMapFit1DinX(bool *goodFit, psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
     // XXX Add Asserts
     assert (map->binning->nYruff == 1);
+
+    *goodFit = false;
 
     // dimensions of the output map image
@@ -726,9 +740,8 @@
 
     if (!psMatrixGJSolve(A, B)) {
-        psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations..\n");
         psFree (A);
         psFree (B);
 	psFree (Empty);
-        return false;
+        return true;
     }
 
@@ -750,4 +763,5 @@
     psFree (Empty);
 
+    *goodFit = true;
     return true;
 }
Index: trunk/psLib/src/imageops/psImageMapFit.h
===================================================================
--- trunk/psLib/src/imageops/psImageMapFit.h	(revision 28667)
+++ trunk/psLib/src/imageops/psImageMapFit.h	(revision 30031)
@@ -8,5 +8,6 @@
 
 // fit the image map to a set of points
-bool psImageMapFit(psImageMap *map,
+bool psImageMapFit(bool *goodFit, 
+		   psImageMap *map,
                    const psVector *mask,
                    psVectorMaskType maskValue, // 
@@ -18,5 +19,6 @@
 
 // fit the image map to a set of points
-bool psImageMapClipFit(psImageMap *map,
+bool psImageMapClipFit(bool *goodFit, 
+		       psImageMap *map,
                        psStats *stats,
                        psVector *mask,  // WARNING: Mask is modified!
@@ -28,5 +30,6 @@
     );
 
-bool psImageMapFit1DinY(psImageMap *map,
+bool psImageMapFit1DinY(bool *goodFit, 
+			psImageMap *map,
                         const psVector *mask,
                         psVectorMaskType maskValue,
@@ -37,5 +40,6 @@
     );
 
-bool psImageMapFit1DinX(psImageMap *map,
+bool psImageMapFit1DinX(bool *goodFit, 
+			psImageMap *map,
                         const psVector *mask,
                         psVectorMaskType maskValue,
