Index: trunk/psphot/src/psphotBlendFit.c
===================================================================
--- trunk/psphot/src/psphotBlendFit.c	(revision 21359)
+++ trunk/psphot/src/psphotBlendFit.c	(revision 21366)
@@ -21,5 +21,5 @@
     int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
     if (!status) {
-	nThreads = 0;
+        nThreads = 0;
     }
 
@@ -44,5 +44,5 @@
     psphotInitRadiusPSF (recipe, psf->type);
 
-    // starts the timer, sets up the array of fitSets 
+    // starts the timer, sets up the array of fitSets
     psphotFitInit (nThreads);
 
@@ -56,91 +56,89 @@
     psArray *cellGroups = psphotAssignSources (Cx, Cy, sources);
 
-    fprintf (stderr, "starting with %ld sources\n", sources->n);
-
     for (int i = 0; i < cellGroups->n; i++) {
 
-	psArray *cells = cellGroups->data[i];
-
-	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_BLEND_FIT");
-		psArray *newSources = psArrayAllocEmpty(16);
-
-		psArrayAdd(job->args, 1, readout);
-		psArrayAdd(job->args, 1, recipe);
-		psArrayAdd(job->args, 1, cells->data[j]); // sources
-		psArrayAdd(job->args, 1, psf);
-		psArrayAdd(job->args, 1, newSources); // return for new sources
-		psFree (newSources);
-
-		PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
-		PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
-		PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
-		PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
-
-		if (!psThreadJobAddPending(job)) {
-		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		    psFree (job);
-		    return NULL;
-		}
-		psFree(job);
-	    } else {
-		int nfit = 0;
-		int npsf = 0;
-		int next = 0;
-		int nfail = 0;
-		psArray *newSources = psArrayAllocEmpty(16);
-
-		if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {
-		    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		    return NULL;
-		}
-		Nfit += nfit;
-		Npsf += npsf;
-		Next += next;
-		Nfail += nfail;
-
-		// add these back onto sources
-		for (int k = 0; k < newSources->n; k++) {
-		    psArrayAdd (sources, 16, newSources->data[k]);
-		}
-		psFree (newSources);
-	    }
-	}
-
-	if (nThreads) {
-	    // wait for the threads to finish and manage results
-	    if (!psThreadPoolWait (false)) {
-		psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
-		return NULL;
-	    }
-
-	    // we have only supplied one type of job, so we can assume the types here
-	    psThreadJob *job = NULL;
-	    while ((job = psThreadJobGetDone()) != NULL) {
-		if (job->args->n < 1) {
-		    fprintf (stderr, "error with job\n");
-		} else {
-		    psScalar *scalar = NULL;
-		    scalar = job->args->data[5];
-		    Nfit += scalar->data.S32;
-		    scalar = job->args->data[6];
-		    Npsf += scalar->data.S32;
-		    scalar = job->args->data[7];
-		    Next += scalar->data.S32;
-		    scalar = job->args->data[8];
-		    Nfail += scalar->data.S32;
-
-		    // add these back onto sources
-		    psArray *newSources = job->args->data[4];
-		    for (int j = 0; j < newSources->n; j++) {
-			psArrayAdd (sources, 16, newSources->data[j]);
-		    }
-		}
-		psFree(job);
-	    }
-	}
+        psArray *cells = cellGroups->data[i];
+
+        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_BLEND_FIT");
+                psArray *newSources = psArrayAllocEmpty(16);
+
+                psArrayAdd(job->args, 1, readout);
+                psArrayAdd(job->args, 1, recipe);
+                psArrayAdd(job->args, 1, cells->data[j]); // sources
+                psArrayAdd(job->args, 1, psf);
+                psArrayAdd(job->args, 1, newSources); // return for new sources
+                psFree (newSources);
+
+                PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
+                PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
+                PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
+                PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
+
+                if (!psThreadJobAddPending(job)) {
+                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                    psFree (job);
+                    return NULL;
+                }
+                psFree(job);
+            } else {
+                int nfit = 0;
+                int npsf = 0;
+                int next = 0;
+                int nfail = 0;
+                psArray *newSources = psArrayAllocEmpty(16);
+
+                if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {
+                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                    return NULL;
+                }
+                Nfit += nfit;
+                Npsf += npsf;
+                Next += next;
+                Nfail += nfail;
+
+                // add these back onto sources
+                for (int k = 0; k < newSources->n; k++) {
+                    psArrayAdd (sources, 16, newSources->data[k]);
+                }
+                psFree (newSources);
+            }
+        }
+
+        if (nThreads) {
+            // wait for the threads to finish and manage results
+            if (!psThreadPoolWait (false)) {
+                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
+                return NULL;
+            }
+
+            // we have only supplied one type of job, so we can assume the types here
+            psThreadJob *job = NULL;
+            while ((job = psThreadJobGetDone()) != NULL) {
+                if (job->args->n < 1) {
+                    fprintf (stderr, "error with job\n");
+                } else {
+                    psScalar *scalar = NULL;
+                    scalar = job->args->data[5];
+                    Nfit += scalar->data.S32;
+                    scalar = job->args->data[6];
+                    Npsf += scalar->data.S32;
+                    scalar = job->args->data[7];
+                    Next += scalar->data.S32;
+                    scalar = job->args->data[8];
+                    Nfail += scalar->data.S32;
+
+                    // add these back onto sources
+                    psArray *newSources = job->args->data[4];
+                    for (int j = 0; j < newSources->n; j++) {
+                        psArrayAdd (sources, 16, newSources->data[j]);
+                    }
+                }
+                psFree(job);
+            }
+        }
     }
     psFree (cellGroups);
@@ -207,5 +205,5 @@
         if (source->peak->SN < FIT_SN_LIM) continue;
 
-	// exclude sources outside optional analysis region
+        // exclude sources outside optional analysis region
         if (source->peak->xf < AnalysisRegion.x0) continue;
         if (source->peak->yf < AnalysisRegion.y0) continue;
@@ -216,6 +214,6 @@
         if (source->modelPSF == NULL) continue;
 
-        // skip sources which are insignificant flux? 
-	// XXX this is somewhat ad-hoc
+        // skip sources which are insignificant flux?
+        // XXX this is somewhat ad-hoc
         if (source->modelPSF->params->data.F32[1] < 0.1) {
             psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n",
@@ -234,19 +232,19 @@
         // try fitting PSFs or extended sources depending on source->mode
         // these functions subtract the resulting fitted source
-	if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
-	    if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
-		source->type = PM_SOURCE_TYPE_EXTENDED;
-		psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
-		Next ++;
-		continue;
-	    }
-	} else {
-	    if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
-		source->type = PM_SOURCE_TYPE_STAR;
-		psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
-		Npsf ++;
-		continue;
-	    }
-	}
+        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
+            if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
+                source->type = PM_SOURCE_TYPE_EXTENDED;
+                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
+                Next ++;
+                continue;
+            }
+        } else {
+            if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
+                source->type = PM_SOURCE_TYPE_STAR;
+                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
+                Npsf ++;
+                continue;
+            }
+        }
 
         psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
@@ -317,5 +315,5 @@
         if (source->peak->SN < FIT_SN_LIM) continue;
 
-	// exclude sources outside optional analysis region
+        // exclude sources outside optional analysis region
         if (source->peak->xf < AnalysisRegion.x0) continue;
         if (source->peak->yf < AnalysisRegion.y0) continue;
@@ -326,6 +324,6 @@
         if (source->modelPSF == NULL) continue;
 
-        // skip sources which are insignificant flux? 
-	// XXX this is somewhat ad-hoc
+        // skip sources which are insignificant flux?
+        // XXX this is somewhat ad-hoc
         if (source->modelPSF->params->data.F32[1] < 0.1) {
             psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n",
@@ -344,19 +342,19 @@
         // try fitting PSFs or extended sources depending on source->mode
         // these functions subtract the resulting fitted source
-	if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
-	    if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
-		source->type = PM_SOURCE_TYPE_EXTENDED;
-		psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
-		Next ++;
-		continue;
-	    }
-	} else {
-	    if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
-		source->type = PM_SOURCE_TYPE_STAR;
-		psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
-		Npsf ++;
-		continue;
-	    }
-	}
+        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
+            if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
+                source->type = PM_SOURCE_TYPE_EXTENDED;
+                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
+                Next ++;
+                continue;
+            }
+        } else {
+            if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
+                source->type = PM_SOURCE_TYPE_STAR;
+                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
+                Npsf ++;
+                continue;
+            }
+        }
 
         psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
