Index: trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h
===================================================================
--- trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 25106)
+++ trunk/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 25208)
@@ -18,4 +18,13 @@
 Coords *MOSAIC;         // carries the mosaic into ReadImageHeader
 
+typedef struct {
+    int     id;
+    double  ra;
+    double  dec;
+    int     Nmatches;
+    int     *matches;
+    int     arrayLength;
+} Point;
+
 int WITH_PHU;
 int SOLO_PHU;
@@ -33,7 +42,5 @@
 Image *ReadImageFiles (char *filename, int *Nimages);
 int ReadImageHeader (Header *header, Image *image);
-int *MatchCoords(Image *, int, double, double, int *);
+int MatchCoords(Image *, int, Point *, int);
 
 int GetFileMode (Header *header);
-// int edge_check (double *x1, double *y1, double *x2, double *y2);
-// double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
Index: trunk/Ohana/src/getstar/src/MatchCoords.c
===================================================================
--- trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 25106)
+++ trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 25208)
@@ -5,8 +5,8 @@
 
 /* given coordinate, find images in list that contain the point */
-int *MatchCoords (Image *dbImages, int NdbImages, double ra, double dec, int *Nmatch) {
+int MatchCoords (Image *dbImages, int NdbImages, Point *points, int Npoints) {
   
-  int i, j, N, addtolist, status;
-  int NMATCH, nmatch, *match;
+  int i, j, N;
+  int totalMatches = 0;
   Coords tcoords;
   double r, d;
@@ -15,10 +15,4 @@
   double xmin, xmax, ymin, ymax;
 
-  *Nmatch = 0;
-
-  /* match represents the subset of overlapping images */
-  nmatch = 0;
-  NMATCH = 20;
-  ALLOCATE (match, int, NMATCH);
 
   /* setup links for mosaic WRP and DIS entries */
@@ -49,28 +43,32 @@
     }
 
-    // transform input point to image coords
-    double x, y;
-    int status = RD_to_XY(&x, &y, ra, dec, &dbImages[i].coords);
+    for (j = 0; j < Npoints; j++) {
+        Point *pt = points + j;
 
-    if (!status) {
-        // avoid matching antipodal skycells
-        continue;
-    }
+        // transform input point to image coords
+        double x, y;
+        int status = RD_to_XY(&x, &y, pt->ra, pt->dec, &dbImages[i].coords);
 
-    if ((x >= xmin && x <= xmax) && (y >= ymin && y <= ymax)) {
+        if (!status) {
+            // avoid matching antipodal skycells
+            continue;
+        }
 
-        match[nmatch] = i;
-        nmatch ++;
-        if (nmatch == NMATCH) {
-          NMATCH += 20;
-          REALLOCATE (match, int, NMATCH);
+        if ((x >= xmin && x <= xmax) && (y >= ymin && y <= ymax)) {
+            totalMatches++;
+
+            pt->matches[pt->Nmatches] = i;
+            pt->Nmatches ++;
+
+            if (pt->Nmatches == pt->arrayLength) {
+                pt->arrayLength += 20;
+                REALLOCATE (pt->matches, int, pt->arrayLength);
+            }
         }
     }
-      
-  }
-  if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", nmatch);
+ }
+ if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", totalMatches);
   
-  *Nmatch = nmatch;
-  return (match);
+ return (totalMatches);
 }
   
Index: trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c
===================================================================
--- trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 25106)
+++ trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 25208)
@@ -1,12 +1,6 @@
 # include "dvoImagesAtCoords.h"
 
-typedef struct {
-    int     id;
-    double  ra;
-    double  dec;
-} Point;
-
 static int readPoints(char *filename, Point **pointsOut);
-static int ListImagesAtCoords (Image *dbImages, int id, double ra, double dec, int *matches, int Nmatches);
+static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints);
 
 int main (int argc, char **argv) {
@@ -30,5 +24,5 @@
   if (astromFile) {
       dbImages = ReadImageFiles(astromFile, &NdbImages);
-    } else {
+  } else {
     /*** update the image table ***/
     /* setup image table format and lock */
@@ -53,10 +47,8 @@
   }
   
-  Point *pt;
-  for (i = 0, pt = points; i < Npoints; i++, pt++) {
-    matches = MatchCoords (dbImages, NdbImages, pt->ra, pt->dec, &Nmatches);
-    ListImagesAtCoords(dbImages, pt->id, pt->ra, pt->dec, matches, Nmatches);
+  if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
+    ListImagesAtCoords(dbImages, points, Npoints);
   }
-
+  // XXX: should we exit with nonzero status if no matches were found?
   exit (0);
 }
@@ -83,6 +75,9 @@
 
     while ((Nread = fscanf(f, "%d %lf %lf\n", &pts[Npoints].id, &pts[Npoints].ra, &pts[Npoints].dec)) == 3) {
-        Npoints++;
-        if (Npoints >= LEN) {
+        pts[Npoints].Nmatches = 0;
+        ALLOCATE(pts[Npoints].matches, int, 20);
+        pts[Npoints].arrayLength = 20;
+
+        if (++Npoints >= LEN) {
             LEN += 20;
             REALLOCATE(pts, Point, LEN);
@@ -99,24 +94,33 @@
 }
 
-static int ListImagesAtCoords (Image *dbImages, int id, double ra, double dec, int *matches, int Nmatches)
+static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints) 
 {
+  int j;
   int i;
-  for (i = 0; i < Nmatches; i++) {
-    int N = matches[i];
+  for (j = 0; j < Npoints; j++) {
+      Point *pt = points + j;
+      for (i = 0; i < pt->Nmatches; i++) {
+        int N = pt->matches[i];
 
-    char *name;
-    // output of lookup is filename[class_id.hdr] for astrometry files
-    char *left_bracket = rindex(dbImages[N].name, '[');
-    if (left_bracket) {
-        name = strdup(left_bracket + 1);
-        // zap the .hdr]
-        char *dot = index(name, '.');
-        if (dot) {
-            *dot = 0;
+        char *name;
+        char *copy = NULL;
+        // output of lookup is filename[class_id.hdr] for astrometry files
+        char *left_bracket = rindex(dbImages[N].name, '[');
+        if (left_bracket) {
+            copy = strdup(left_bracket + 1);
+            name = copy;
+            // zap the .hdr]
+            char *dot = index(name, '.');
+            if (dot) {
+                *dot = 0;
+            }
+        } else {
+            name = dbImages[N].name;
         }
-    } else {
-        name = dbImages[N].name;
+        fprintf (stdout, "%d %lf %lf %s\n", pt->id, pt->ra, pt->dec, name);
+        if  (copy) {
+            free(copy);
+        }
     }
-    fprintf (stdout, "%d %lf %lf %s\n", id, ra, dec, name);
   }
   
