Index: /trunk/psphot/src/psphotGuessModels.c
===================================================================
--- /trunk/psphot/src/psphotGuessModels.c	(revision 13342)
+++ /trunk/psphot/src/psphotGuessModels.c	(revision 13343)
@@ -1,5 +1,20 @@
 # include "psphotInternal.h"
 
-// construct an initial PSF model for each object 
+// A guess for when the moments aren't available
+static pmModel *wildGuess(pmSource *source, // Source for which to guess
+                          pmPSF *psf    // The point-spread function
+    )
+{
+    pmModel *model = pmModelAlloc(psf->type);
+    psF32 *PAR = model->params->data.F32;
+    PAR[PM_PAR_SKY]  = 0;
+    // XXX get this from the image pixels
+    PAR[PM_PAR_I0]   = source->peak->flux;
+    PAR[PM_PAR_XPOS] = source->peak->xf;
+    PAR[PM_PAR_YPOS] = source->peak->yf;
+    return model;
+}
+
+// construct an initial PSF model for each object
 bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) {
 
@@ -17,30 +32,24 @@
 
     // XXX if a source is faint, it will not have moments measured.
-    // it must be modelled as a PSF.  In this case, we need to use 
-    // the peak centroid to get the coordinates and get the peak flux 
+    // it must be modelled as a PSF.  In this case, we need to use
+    // the peak centroid to get the coordinates and get the peak flux
     // from the image?
-
-    // use the source moments, etc to guess basic model parameters
-    pmModel *modelEXT = pmSourceModelGuess (source, psf->type);
-    
-    // XXX put this in a function of its own..
-    if (modelEXT == NULL) {
-	psErrorClear (); // XXX need to clear the error from failing the model
-	modelEXT = pmModelAlloc(psf->type);
-	psF32 *PAR = modelEXT->params->data.F32;
-	PAR[PM_PAR_SKY]  = 0;
-	// XXX get this from the image pixels
-	PAR[PM_PAR_I0]   = source->peak->flux;
-	PAR[PM_PAR_XPOS] = source->peak->xf;
-	PAR[PM_PAR_YPOS] = source->peak->yf;
+    pmModel *modelEXT;
+    if (!source->moments) {
+        modelEXT = wildGuess(source, psf);
     } else {
-	// these valuse are set in pmSourceModelGuess, should this rule be in there as well?
-	if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
-	    modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x;
-	    modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y;
-	} else {
-	    modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
-	    modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
-	}
+        // use the source moments, etc to guess basic model parameters
+        modelEXT = pmSourceModelGuess (source, psf->type);
+        if (!modelEXT) {
+            modelEXT = wildGuess(source, psf);
+        }
+        // these valuse are set in pmSourceModelGuess, should this rule be in there as well?
+        if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
+            modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x;
+            modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y;
+        } else {
+            modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
+            modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
+        }
     }
 
@@ -63,3 +72,3 @@
 }
 
-// XXX do we always know which model is supposed to be used?  
+// XXX do we always know which model is supposed to be used?
