Index: trunk/psphot/src/psphotMergeSources.c
===================================================================
--- trunk/psphot/src/psphotMergeSources.c	(revision 30624)
+++ trunk/psphot/src/psphotMergeSources.c	(revision 31154)
@@ -1,7 +1,8 @@
 # include "psphotInternal.h"
 
+// Mask to apply for PSF sources : only exclude bad sources -- we will re-test for extendedness
 #define PSF_SOURCE_MASK (PM_SOURCE_MODE_FAIL | PM_SOURCE_MODE_SATSTAR | PM_SOURCE_MODE_BLEND | \
                          PM_SOURCE_MODE_BADPSF | PM_SOURCE_MODE_DEFECT | PM_SOURCE_MODE_SATURATED | \
-                         PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply for PSF sources
+                         PM_SOURCE_MODE_CR_LIMIT)
 
 // for now, let's store the detections on the readout->analysis for each readout
@@ -110,6 +111,7 @@
 
                 // the supplied peak flux needs to be re-normalized
-                source->peak->flux = 1.0;
-                source->peak->value = 1.0;
+                source->peak->rawFlux = 1.0;
+                source->peak->smoothFlux = 1.0;
+                source->peak->detValue = 1.0;
 
                 // drop the loaded source modelPSF
@@ -281,5 +283,6 @@
     for (int i = 0; i < sources->n; i++) {
       pmSource *source = sources->data[i];
-      source->peak->flux = source->moments->Peak;
+      source->peak->rawFlux = source->moments->Peak;
+      source->peak->smoothFlux = source->moments->Peak;
     }
 
@@ -331,14 +334,7 @@
         float ypos = model->params->data.F32[PM_PAR_YPOS];
 
-        pmPeak *peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
+        pmPeak *peak = pmPeakAlloc(xpos, ypos, flux, PM_PEAK_LONE);
         peak->xf = xpos;
         peak->yf = ypos;
-        peak->flux = flux; // this are being set wrong, but does it matter?
-
-        if (isfinite (source->errMag) && (source->errMag > 0.0)) {
-          peak->SN = 1.0 / source->errMag;
-        } else {
-          peak->SN = 0.0;
-        }
 
         psArrayAdd (detections->peaks, 100, peak);
@@ -347,4 +343,6 @@
 
     psLogMsg ("psphot", 3, "%ld PSF sources loaded", detections->peaks->n);
+    psphotVisualShowSources (sources);
+    psphotVisualShowPeaks (detections);
 
     // save detections on the readout->analysis
@@ -354,8 +352,10 @@
     }
     psFree (detections);
+
     return true;
 }
 
 // generate the detection structure for the supplied array of sources
+// XXX this function is currently unused
 bool psphotSetSourceParams (pmConfig *config, psArray *sources, pmPSF *psf) {
 
@@ -378,14 +378,9 @@
         float ypos = model->params->data.F32[PM_PAR_YPOS];
 
-        pmPeak *peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
+        pmPeak *peak = pmPeakAlloc(xpos, ypos, flux, PM_PEAK_LONE);
         peak->xf = xpos;
         peak->yf = ypos;
-        peak->flux = flux; // this are being set wrong, but does it matter?
-
-        if (isfinite (source->errMag) && (source->errMag > 0.0)) {
-          peak->SN = 1.0 / source->errMag;
-        } else {
-          peak->SN = 0.0;
-        }
+        peak->rawFlux = flux; // this are being set wrong, but does it matter?
+        peak->smoothFlux = flux; // this are being set wrong, but does it matter?
 
         source->peak = peak;
@@ -613,5 +608,7 @@
 
       // allocate image, weight, mask for the new image for each peak
-      pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
+      if (sourceOut->modelPSF) {
+	pmSourceRedefinePixels (sourceOut, readoutOut, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
+      }
 
       // child sources have not been subtracted in this image, but this flag may be raised if
@@ -679,7 +676,7 @@
 	objectsOut->data[k] = objectOut;
 
-	objectOut->SN = objectSrc->SN;
-	objectOut->x  = objectSrc->x;
-	objectOut->y  = objectSrc->y;
+	objectOut->flux = objectSrc->flux;
+	objectOut->x    = objectSrc->x;
+	objectOut->y    = objectSrc->y;
 	
 	objectOut->sources = psArrayAlloc(objectSrc->sources->n);
@@ -697,5 +694,6 @@
 	    sourceOut->parent = sourceSrc;
 
-	    // keep the original source flags
+	    // keep the original source flags and sequence ID (if set)
+	    sourceOut->seq      = sourceSrc->seq;
 	    sourceOut->type     = sourceSrc->type;
 	    sourceOut->mode     = sourceSrc->mode;
@@ -723,5 +721,7 @@
 
 	    // allocate image, weight, mask for the new image for each peak
-	    pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
+	    if (sourceOut->modelPSF) {
+	      pmSourceRedefinePixels (sourceOut, readout, sourceOut->peak->x, sourceOut->peak->y, sourceOut->modelPSF->fitRadius);
+	    }
 
 	    // child sources have not been subtracted in this image, but this flag may be raised if
