Index: /branches/rel-1_0/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/rel-1_0/psModules/src/objects/pmPSFtry.c	(revision 12340)
+++ /branches/rel-1_0/psModules/src/objects/pmPSFtry.c	(revision 12341)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-01-19 04:35:53 $
+ *  @version $Revision: 1.34.2.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-03-08 23:27:24 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -215,4 +215,7 @@
     bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, stats, mask, 1, chisq, NULL, flux);
     psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
+    if (!result) {
+	result = psVectorFitPolynomial1D(psfTry->psf->ChiTrend, mask, 1, chisq, NULL, flux);
+    }
 
     psFree (flux);
@@ -276,6 +279,9 @@
     bool result = psVectorClipFitPolynomial1D (poly, stats, psfTry->mask, PSFTRY_MASK_ALL, psfTry->metric, psfTry->metricErr, r2rflux);
     if (!result) {
-        psError(PS_ERR_UNKNOWN, false, "Failed to fit clipped poly");
-        return false;
+        psLogMsg(__func__, 3, "Failed to fit clipped poly");
+	if (!psVectorFitPolynomial1D(poly, psfTry->mask, PSFTRY_MASK_ALL,
+				     psfTry->metric, psfTry->metricErr, r2rflux)) {
+	    return false;
+	}
     }
     psLogMsg ("pmPSFtryMetric", 4, "fit stats: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
@@ -361,5 +367,6 @@
     // we are doing a robust fit.  after each pass, we drop points which are
     // more deviant than three sigma.
-    // mask is currently updated for each pass. this is inconsistent?
+    // mask is currently updated for each parameter, so potentially
+    // different sets of stars are used for SXX, SYY, SXY, ...
 
     psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
@@ -397,6 +404,12 @@
         // the weight is either the parameter error or NULL, depending on 'applyWeights'
         if (!psVectorClipFitPolynomial2D(psf->params_NEW->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
-            return false;
+	    // Should save error stack at this point, and add any new errors on the end if
+	    // we still have problems; but we don't have an API to do this
+	    psLogMsg ("pmPSFtry", 4, "failed to build psf model for parameter %d with clipping", i);
+
+	    if (!psVectorFitPolynomial2D(psf->params_NEW->data[i], psfTry->mask, 0xff, z, NULL, x, y)) {
+		psError(PS_ERR_UNKNOWN, false, "failed to build unclipped psf model for parameter %d", i);
+		return false;
+	    }
         }
     }
