Index: trunk/psModules/src/objects/pmSourceFitSet.c
===================================================================
--- trunk/psModules/src/objects/pmSourceFitSet.c	(revision 14938)
+++ trunk/psModules/src/objects/pmSourceFitSet.c	(revision 15055)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-21 00:09:05 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-09-28 00:39:41 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -69,6 +69,7 @@
         int nParams = pmModelClassParameterCount (model->type);
 
-        set->paramSet->data[i] = psVectorAlloc (nParams, PS_DATA_F32);
+        set->paramSet->data[i] = psVectorCopy (NULL, model->params, PS_DATA_F32);
         set->derivSet->data[i] = psVectorAlloc (nParams, PS_DATA_F32);
+        psVectorInit (set->derivSet->data[i], 0.0);
 
         set->nParamSet += nParams;
@@ -107,4 +108,5 @@
 }
 
+// merge parameters from FitSet models into single param and deriv vectors
 bool pmSourceFitSetJoin (psVector *deriv, psVector *param, pmSourceFitSetData *set) {
 
@@ -117,8 +119,13 @@
         psVector *paramOne = set->paramSet->data[i];
         psVector *derivOne = set->derivSet->data[i];
-        assert ((deriv == NULL) || (paramOne->n == derivOne->n));
-
+
+	// one or the other (param or deriv) must be set
+	assert ((deriv != NULL) || (param != NULL));
+        assert ((deriv == NULL) || (param == NULL) || (paramOne->n == derivOne->n));
+	
         for (int j = 0; j < paramOne->n; j++, n++) {
-            param->data.F32[n] = paramOne->data.F32[j];
+	    if (param) {
+		param->data.F32[n] = paramOne->data.F32[j];
+	    }
             if (deriv) {
                 deriv->data.F32[n] = derivOne->data.F32[j];
@@ -129,4 +136,5 @@
 }
 
+// distribute parameters from single param and deriv vectors into FitSet models
 bool pmSourceFitSetSplit (pmSourceFitSetData *set, const psVector *deriv, const psVector *param) {
 
@@ -191,4 +199,6 @@
 }
 
+// generic psMinLMM-style function for fitting: split the parameters across the models, call
+// each model function one-at-a-time, the join the derivatives for on-going evaluation
 psF32 pmSourceFitSetFunction(psVector *deriv, const psVector *param, const psVector *x)
 {
@@ -209,4 +219,5 @@
         chisqSum += chisqOne;
     }
+    pmSourceFitSetJoin (deriv, NULL, thisSet);
 
     return (chisqSum);
@@ -248,4 +259,28 @@
         }
         n += paramOne->n;
+    }
+    return true;
+}
+
+bool pmSourcePrintModelSet (FILE *file, psArray *modelSet) {
+
+    for (int i = 0; i < modelSet->n; i++) {
+	pmModel *model = modelSet->data[i];
+	int nParams = pmModelClassParameterCount (model->type);
+	for (int j = 0; j < nParams; j++) {
+	    fprintf (file, "%d %d  : %f %f\n", i, j, model->params->data.F32[j], model->dparams->data.F32[j]);
+	}
+    }
+    return true;
+}
+
+bool pmSourceFitSetPrint (FILE *file, pmSourceFitSetData *set) {
+
+    for (int i = 0; i < set->paramSet->n; i++) {
+        psVector *paramOne = set->paramSet->data[i];
+        psVector *derivOne = set->derivSet->data[i];
+        for (int j = 0; j < paramOne->n; j++) {
+	    fprintf (file, "%d %d  : %f %f\n", i, j, paramOne->data.F32[j], derivOne->data.F32[j]);
+        }
     }
     return true;
@@ -314,4 +349,5 @@
     yErr->n = nPix;
 
+    // create the FitSet and set the initial parameter guesses
     thisSet = pmSourceFitSetDataAlloc (modelSet);
 
@@ -383,9 +419,6 @@
             altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
         }
-        if (!psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction)) {
-            // Can we really do anything about it?
-            // It will happily continue on, but the presence of an error upsets the psphot cleanup
-            psErrorClear();
-        }
+        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction);
+
         for (int i = 0; i < dparams->n; i++) {
             if (!constraint->paramMask->data.U8[i])
