Index: trunk/psModules/src/objects/pmSourceMatch.c
===================================================================
--- trunk/psModules/src/objects/pmSourceMatch.c	(revision 23989)
+++ trunk/psModules/src/objects/pmSourceMatch.c	(revision 24262)
@@ -45,4 +45,5 @@
                          psVector **x, psVector **y, // Coordinate vectors to return
                          psVector **mag, psVector **magErr, // Magnitude and error vectors to return
+                         psVector **indices, // Indices for sources
                          const psArray *sources // Input sources
     )
@@ -58,13 +59,13 @@
     *mag = psVectorRecycle(*mag, numSources, PS_TYPE_F32);
     *magErr = psVectorRecycle(*magErr, numSources, PS_TYPE_F32);
+    *indices = psVectorRecycle(*indices, numSources, PS_TYPE_S32);
     float xMin = INFINITY, xMax = -INFINITY, yMin = INFINITY, yMax = -INFINITY; // Bounds of sources
     long num = 0;                       // Number of valid sources
     for (long i = 0; i < numSources; i++) {
         pmSource *source = sources->data[i]; // Source of interest
-        if (!source) continue;
-        if (source->mode & SOURCE_MASK) continue;
-        if (!isfinite(source->psfMag)) continue;
-        if (!isfinite(source->errMag)) continue;
-        if (source->psfMag > SOURCE_FAINTEST) continue;
+        if (!source || (source->mode & SOURCE_MASK) || !isfinite(source->psfMag) ||
+            !isfinite(source->errMag) || source->psfMag > SOURCE_FAINTEST) {
+            continue;
+        }
 
         float xSrc, ySrc;               // Coordinates of source
@@ -78,5 +79,6 @@
         (*y)->data.F32[num] = ySrc;
         (*mag)->data.F32[num] = source->psfMag;
-        (*magErr)->data.F32[num] = source->errMag ;
+        (*magErr)->data.F32[num] = source->errMag;
+        (*indices)->data.S32[num] = i;
         num++;
     }
@@ -85,4 +87,5 @@
     (*mag)->n = num;
     (*magErr)->n = num;
+    (*indices)->n = num;
 
     if (*bounds) {
@@ -175,6 +178,7 @@
         psVector *xImage = NULL, *yImage = NULL; // Coordinates of sources
         psVector *magImage = NULL, *magErrImage = NULL; // Magnitude and mag
-
-        int numSources = sourcesParse(&boundsImage, &xImage, &yImage, &magImage, &magErrImage,
+        psVector *indices = NULL;     // Indices for sources
+
+        int numSources = sourcesParse(&boundsImage, &xImage, &yImage, &magImage, &magErrImage, &indices,
                                       sources); // Number of sources
 
@@ -187,5 +191,6 @@
             for (int j = 0; j < numSources; j++) {
                 pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
-                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
+                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j],
+                                 i, indices->data.S32[j]);
                 matches->data[j] = match;
             }
@@ -206,5 +211,6 @@
             for (int j = 0, k = numMaster; j < numSources; j++, k++) {
                 pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
-                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
+                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j],
+                                 i, indices->data.S32[j]);
                 matches->data[k] = match;
             }
@@ -231,10 +237,12 @@
                     // Record the match
                     pmSourceMatch *match = matches->data[index]; // Match data
-                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
+                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j],
+                                     i, indices->data.S32[j]);
                     numMatch++;
                 } else {
                     // Add to the master list
                     pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
-                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
+                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j],
+                                     i, indices->data.S32[j]);
                     xMaster->data.F32[numMaster] = xImage->data.F32[j];
                     yMaster->data.F32[numMaster] = yImage->data.F32[j];
