Index: /branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c
===================================================================
--- /branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c	(revision 27627)
+++ /branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c	(revision 27628)
@@ -1,50 +1,69 @@
-# include "psphotInternal.h"
-                                                                                                                                                                               
-// we need a couple of functions to distinguish coincident sources:                                                                                                              
-// XXX these are similar (identical?) to the goals of pmSourceMatch.c                                                                                                            
-                                                                                                                                                                                 
-# define NEXT1 { i++; continue; }                                                                                                                                                
-# define NEXT2 { j++; continue; }                                                                                                                                                
-                                                                                                                                                                                 
-psphotSourceMerge () {                                                                                                                                                           
-                                                                                                                                                                                 
-    float dx, dy;                                                                                                                                                                
-                                                                                                                                                                                 
-    // sort the source list by X                                                                                                                                                 
-    pmSourceSortByX (sources1);                                                                                                                                                  
-    pmSourceSortByX (sources2);                                                                                                                                                  
-                                                                                                                                                                                 
-    int i, j;                                                                                                                                                                    
-    for (i = j = 0; (i < sources1->n) && (j < sources2->n); ) {                                                                                                                  
-                                                                                                                                                                                 
-        pmSource *src1 = sources1->data[i];                                                                                                                                      
-        pmSource *src2 = sources2->data[j];                                                                                                                                      
-                                                                                                                                                                                 
-        if (!src1) NEXT1;                                                                                                                                                        
-        if (!src1->peak) NEXT1;                                                                                                                                                  
-        if (!finite(src1->peak->xf)) NEXT1;                                                                                                                                      
-        if (!finite(src1->peak->yf)) NEXT1;                                                                                                                                      
-                                                                                                                                                                                 
-        if (!src2) NEXT2;                                                                                                                                                        
-        if (!src2->peak) NEXT2;                                                                                                                                                  
-        if (!finite(src2->peak->xf)) NEXT2;                                                                                                                                      
-        if (!finite(src2->peak->yf)) NEXT2;                                                                                                                                      
-                                                                                                                                                                                 
-        dx = src1->peak->xf - src2->peak->xf;                                                                                                                                    
-        if (dx < -1.02*RADIUS) NEXT1;                                                                                                                                            
-        if (dx > +1.02*RADIUS) NEXT2;                                                                                                                                            
-                                                                                                                                                                                 
-        // we are within match range, look for matches:                                                                                                                          
-        for (int J = j; (dx > -1.02*radius) && (J < sources2->n); J++) {                                                                                                         
-                                                                                                                                                                                 
-            dx = src1->peak->xf - src2->peak->xf;                                                                                                                                
-            dy = src1->peak->yf - src2->peak->yf;                                                                                                                                
-                                                                                                                                                                                 
-            dr = dx*dx + dy*dy;                                                                                                                                                  
-            if (dr > RADIUS2) continue;                                                                                                                                          
-                                                                                                                                                                                 
-            // add to group?                                                                                                                                                     
-        }                                                                                                                                                                        
-        i++;                                                                                                                                                                     
-    }                                                                                                                                                                            
-}      
+# include "psphotInternal.h" 
+ 
+psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view) 
+{
+    bool status = true;
+
+    psArray *objects = psArrayAllocEmpty(100);
+
+    int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM");
+    psAssert (status, "programming error: must define PSPHOT.INPUT.NUM");
+
+    // loop over the available readouts
+    for (int i = 0; i < num; i++) {
+        if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) {
+            psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i);
+            return false;
+        }
+    }
+    return true;
+}
+
+// we need a couple of functions to distinguish coincident sources: 
+// XXX these are similar (identical?) to the goals of pmSourceMatch.c 
+ 
+# define NEXT1 { i++; continue; } 
+# define NEXT2 { j++; continue; } 
+ 
+bool psphotSourceMerge (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) { 
+ 
+    float dx, dy; 
+ 
+    // sort the source list by X 
+    pmSourceSortByX (sources1); 
+    pmSourceSortByX (sources2); 
+ 
+    int i, j; 
+    for (i = j = 0; (i < sources1->n) && (j < sources2->n); ) { 
+ 
+        pmSource *src1 = sources1->data[i]; 
+        pmSource *src2 = sources2->data[j]; 
+ 
+        if (!src1) NEXT1; 
+        if (!src1->peak) NEXT1; 
+        if (!finite(src1->peak->xf)) NEXT1; 
+        if (!finite(src1->peak->yf)) NEXT1; 
+ 
+        if (!src2) NEXT2; 
+        if (!src2->peak) NEXT2; 
+        if (!finite(src2->peak->xf)) NEXT2; 
+        if (!finite(src2->peak->yf)) NEXT2; 
+ 
+        dx = src1->peak->xf - src2->peak->xf; 
+        if (dx < -1.02*RADIUS) NEXT1; 
+        if (dx > +1.02*RADIUS) NEXT2; 
+ 
+        // we are within match range, look for matches: 
+        for (int J = j; (dx > -1.02*radius) && (J < sources2->n); J++) { 
+ 
+            dx = src1->peak->xf - src2->peak->xf; 
+            dy = src1->peak->yf - src2->peak->yf; 
+ 
+            dr = dx*dx + dy*dy; 
+            if (dr > RADIUS2) continue; 
+ 
+            // add to group? 
+        } 
+        i++; 
+    } 
+} 
