Index: trunk/psphot/src/psphotGuessModels.c
===================================================================
--- trunk/psphot/src/psphotGuessModels.c	(revision 21381)
+++ trunk/psphot/src/psphotGuessModels.c	(revision 21519)
@@ -22,6 +22,4 @@
 }
 
-bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
-
 // construct an initial PSF model for each object
 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) {
@@ -67,47 +65,45 @@
 	for (int j = 0; j < cells->n; j++) {
 
-	    if (nThreads) {
-		// allocate a job -- if threads are not defined, this just runs the job
-		psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
-		psArrayAdd(job->args, 1, readout);
-		psArrayAdd(job->args, 1, cells->data[j]); // sources
-		psArrayAdd(job->args, 1, psf);
-
-		// XXX change these to use abstract mask type info
-		PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
-		PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
-
-		if (!psThreadJobAddPending(job)) {
-		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		    psFree (job);
-		    return false;
-		}
-		psFree(job);
-	    } else {
+	    // allocate a job -- if threads are not defined, this just runs the job
+	    psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
+	    psArrayAdd(job->args, 1, readout);
+	    psArrayAdd(job->args, 1, cells->data[j]); // sources
+	    psArrayAdd(job->args, 1, psf);
+
+	    // XXX change these to use abstract mask type info
+	    PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
+	    PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
+
+	    if (!psThreadJobAddPending(job)) {
+		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+		psFree (job);
+		return false;
+	    }
+	    psFree(job);
+
+# if (0)		
 		if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) {
 		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
 		    return false;
 		}
-	    }
-	}
-
-	if (nThreads) {
-	    // wait for the threads to finish and manage results
-	    // wait here for the threaded jobs to finish
-	    // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
-	    if (!psThreadPoolWait (false)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		return false;
-	    }
-
-	    // we have only supplied one type of job, so we can assume the types here
-	    psThreadJob *job = NULL;
-	    while ((job = psThreadJobGetDone()) != NULL) {
-		// we have no returned data from this operation
-		if (job->args->n < 1) {
-		    fprintf (stderr, "error with job\n");
-		}
-		psFree(job);
-	    }
+# endif
+	}
+
+	// wait for the threads to finish and manage results
+	// wait here for the threaded jobs to finish
+	// fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
+	if (!psThreadPoolWait (false)) {
+	    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+	    return false;
+	}
+
+	// we have only supplied one type of job, so we can assume the types here
+	psThreadJob *job = NULL;
+	while ((job = psThreadJobGetDone()) != NULL) {
+	    // we have no returned data from this operation
+	    if (job->args->n < 1) {
+		fprintf (stderr, "error with job\n");
+	    }
+	    psFree(job);
 	}
     }
@@ -116,14 +112,11 @@
     int nMiss = 0;
     for (int i = 0; i < sources->n; i++) {
-
 	pmSource *source = sources->data[i];
-	if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
-	    source->mode &= ~PM_SOURCE_MODE_EXT_LIMIT;
+	if (source->tmpFlags & PM_SOURCE_TMPF_MODEL_GUESS) {
 	    continue;
 	}
-
 	nMiss ++;
     }
-    psLogMsg ("psphot.models", 4, "failed to build models for %d objects\n", nMiss);
+    psAssert (nMiss == 0, "failed to attempt to build models for %d objects\n", nMiss);
 
     psFree (cellGroups);
@@ -148,7 +141,7 @@
 	pmSource *source = sources->data[i];
 
-	// XXXX this is just for a test: use this to mark sources for which the model is measured
-	// check later that all are used.
-	source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
+	// this is used to mark sources for which the model is measured. We check later that
+	// all are used.
+	source->tmpFlags |= PM_SOURCE_TMPF_MODEL_GUESS;
 
 	// skip non-astronomical objects (very likely defects)
@@ -185,20 +178,16 @@
 	pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC X5
 	if (modelPSF == NULL) {
-	    psError(PSPHOT_ERR_PSF, false,
-		    "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
+	    psWarning ("Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
 		    source->peak->y, source->peak->x);
-	    //
-	    // Try the centre of the image
-	    //
+
+	    // Try the center of the image
 	    modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
 	    modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
 	    modelPSF = pmModelFromPSF (modelEXT, psf);
 	    if (modelPSF == NULL) {
-		psError(PSPHOT_ERR_PSF, false,
-			"Failed to determine PSF model at centre of image");
+		psError(PSPHOT_ERR_PSF, false, "Failed to determine PSF model at center of image");
 		psFree(modelEXT);
 		return false;
 	    }
-
 	    source->mode |= PM_SOURCE_MODE_BADPSF;
 	}
@@ -221,4 +210,5 @@
 }
 
+# if (0)
 // construct models only for sources in the specified region
 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
@@ -301,2 +291,3 @@
     return true;
 }
+# endif
