Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/include/addstar.h
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/include/addstar.h	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/include/addstar.h	(revision 27430)
@@ -145,4 +145,5 @@
 char     *SELECT_2MASS_QUALITY;  // used only by get2mass_as
 int NREFSTAR_GROUP;
+int NSTAR_GROUP;
 
 /*** addstar prototypes ***/
Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadImageHeader.c	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadImageHeader.c	(revision 27430)
@@ -85,5 +85,5 @@
   }
 
-  { 
+  {
     double R, D;
     /* sanity check on the image coordinates */
@@ -94,9 +94,9 @@
     }
   }
-    
+
   /* CERROR in data file is in arcsec */
   if (!gfits_scan (header, "CERROR",   "%lf", 1, &tmp)) tmp = 1.0;
   image[0].cerror = tmp * 50.0;
- 
+
   /* get photcode from header */
   if (photcode == 0) {
@@ -112,5 +112,5 @@
     photcode = photcodeData[0].code;
   }
-  if (photcode == 0) { 
+  if (photcode == 0) {
     fprintf (stderr, "no valid photcode is supplied\n");
     return (FALSE);
@@ -122,5 +122,5 @@
   gfits_scan (header, ExptimeKeyword,  "%lf", 1, &tmp);
   image[0].exptime = tmp;
-  
+
   /*** why are we no longer using APMIFIT?? ***/
   tmp = 0;
@@ -172,5 +172,5 @@
   if (gfits_scan (header, AirmassKeyword, "%lf", 1, &tmp)) {
     image[0].secz = tmp;
-  } 
+  }
 
   if (!gfits_scan (header, CCDNumKeyword, "%s", 1, ccdnum)) {
@@ -199,5 +199,5 @@
   } else {
     if (sourceID > 0xffff) {
-      fprintf (stderr, "image source ID is surprisingly large: %d, skipping\n", sourceID); 
+      fprintf (stderr, "image source ID is surprisingly large: %d, skipping\n", sourceID);
       return (FALSE);
     }
@@ -208,8 +208,8 @@
   // 0 - 32 so it would fit in an unsigned int.  This is also needed because some programs like
   // sextractor will put in an arbitrary zero point that we need to understand to get back to
-  // instrumental mags.  
+  // instrumental mags.
   gfits_scan (header, "ZERO_PT", "%lf", 1, &ZeroPt);
   if (ZeroPt != GetZeroPoint()) {
-      fprintf (stderr, "WARNING: inconsistent zero point values: image: %f, config: %f\n", ZeroPt, GetZeroPoint()); 
+      fprintf (stderr, "WARNING: inconsistent zero point values: image: %f, config: %f\n", ZeroPt, GetZeroPoint());
   }
 
@@ -218,9 +218,9 @@
       float ZPT_OBS;
       if (!photcodeData || !gfits_scan (header, "ZPT_OBS", "%f", 1, &ZPT_OBS)) {
-	  fprintf (stderr, "zero point not supplied in header\n");
-	  ZERO_POINT_OFFSET = 0.0;
+          fprintf (stderr, "zero point not supplied in header\n");
+          ZERO_POINT_OFFSET = 0.0;
       } else {
-	  ZERO_POINT_OFFSET = 0.001*photcodeData[0].C - ZPT_OBS;
-      }	  
+          ZERO_POINT_OFFSET = 0.001*photcodeData[0].C - ZPT_OBS;
+      }
   }
 
@@ -228,9 +228,9 @@
   if (!strcasecmp(ZERO_POINT_OPTION, "PHU_HEADER")) {
       if (!photcodeData) {
-	  fprintf (stderr, "photcode data not supplied for this chip\n");
-	  ZERO_POINT_OFFSET = 0.0;
+          fprintf (stderr, "photcode data not supplied for this chip\n");
+          ZERO_POINT_OFFSET = 0.0;
       } else {
-	  ZERO_POINT_OFFSET = 0.001*photcodeData[0].C - ZERO_POINT_OFFSET;
-      }	  
+          ZERO_POINT_OFFSET = 0.001*photcodeData[0].C - ZERO_POINT_OFFSET;
+      }
   }
 
Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27430)
@@ -259,4 +259,5 @@
   }
 
+  NSTAR_GROUP = NFILTER;
   *nimages += NFILTER;
   *nstars = Nstars*NFILTER;
Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/args.c
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/args.c	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/args.c	(revision 27430)
@@ -9,4 +9,6 @@
   // a global used by find_matches_refstars.c (value is 1 except for load2mass)
   NREFSTAR_GROUP = 1;
+  // a global used by find_matches_closest.c (value is 1 except for loadsdss)
+  NSTAR_GROUP = 1;
 
   /* check for help request */
Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches.c
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches.c	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches.c	(revision 27430)
@@ -12,4 +12,9 @@
   unsigned int objID, catID;
   Coords tcoords;
+
+  if (NSTAR_GROUP <= 0) {
+      fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
+      exit (1);
+  }
 
   /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
@@ -103,4 +108,5 @@
 
   /** find matched stars **/
+  // XXX could use NSTAR_GROUP to do this match more quicky if NSTAR_GROUP > 1
   for (i = j = 0; (i < Nstars) && (j < Nave); ) {
     if (!finite(X1[i]) || !finite(Y1[i])) { 
@@ -141,4 +147,5 @@
 	NMEAS = Nmeas + 1000;
 	REALLOCATE (next_meas, off_t, NMEAS);
+
 	REALLOCATE (catalog[0].measure, Measure, NMEAS);
       }
@@ -227,7 +234,7 @@
   /* incorporate unmatched image stars, if this star is in field of this catalog */
   /* these new entries are all written out in UPDATE mode */ 
-  for (i = 0; (i < Nstars) && !options.only_match; i++) {
+  for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
     /* make sure there is space for next entry */
-    if (Nmeas >= NMEAS) {
+    if (Nmeas >= NMEAS - NSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
       REALLOCATE (next_meas, off_t, NMEAS);
@@ -249,5 +256,5 @@
     catalog[0].average[Nave].dD        	   = 0;
 
-    catalog[0].average[Nave].Nmeasure      = 1;
+    catalog[0].average[Nave].Nmeasure      = NSTAR_GROUP;
     catalog[0].average[Nave].Nmissing      = 0;
     catalog[0].average[Nave].Nextend       = 0;
@@ -290,26 +297,32 @@
     }
 
-    // supply the measurments from this detection
-    catalog[0].measure[Nmeas]           = stars[N].measure;
-
-    // the following measure elements cannot be set until here:
-    catalog[0].measure[Nmeas].dR       	= 0.0;
-    catalog[0].measure[Nmeas].dD       	= 0.0;
-    catalog[0].measure[Nmeas].dbFlags 	= 0;
-    catalog[0].measure[Nmeas].averef   	= Nave; // XXX EAM : must be absolute Nave if partial read
-    catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
-    catalog[0].measure[Nmeas].catID     = catalog[0].catID;
-
-    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
-    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
-    if (Nsec > -1) { 
-	catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
-    }
-
-    /* next[Nmeas] should always be -1 in this context (it is always the only
-       measurement for the star) */
-    stars[N].found = Nmeas;
-    next_meas[Nmeas] = -1;
-    Nmeas ++;
+    for (j = 0; j < NSTAR_GROUP; j++) {
+      // supply the measurments from this detection
+      catalog[0].measure[Nmeas]           = stars[N].measure;
+      N = N1[i + j];
+
+      // the following measure elements cannot be set until here:
+      catalog[0].measure[Nmeas].dR       	= 0.0;
+      catalog[0].measure[Nmeas].dD       	= 0.0;
+      catalog[0].measure[Nmeas].dbFlags 	= 0;
+      catalog[0].measure[Nmeas].averef   	= Nave; // XXX EAM : must be absolute Nave if partial read
+      catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
+      catalog[0].measure[Nmeas].catID     = catalog[0].catID;
+
+      /* set the average magnitude if not already set and the photcode.equiv is not 0 */
+      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+      if (Nsec > -1) { 
+          catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+      }
+
+      /* next[Nmeas] should always be -1 in this context (it is always the only
+         measurement for the star) */
+      stars[N].found = Nmeas;
+      next_meas[Nmeas] = -1;  // initial value here update below
+      Nmeas ++;
+    }
+    for (j = 0; j < NSTAR_GROUP - 1; j++) {
+      next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
+    }
     Nave ++;
   }
Index: branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches_closest.c	(revision 27429)
+++ branches/eam_branches/largefiles.20100314/Ohana/src/addstar/src/find_matches_closest.c	(revision 27430)
@@ -13,4 +13,9 @@
   Coords tcoords;
 
+  if (NSTAR_GROUP <= 0) {
+      fprintf (stderr, "ERROR: NSTAR_GROUP NOT SET!\n");
+      exit (1);
+  }
+
   /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
      images this function requires incoming stars to have the same photcode.equiv value.  if
@@ -104,4 +109,5 @@
 
   /** find matched stars **/
+  // XXX could use NSTAR_GROUP to do this match more quicky if NSTAR_GROUP > 1
   for (i = j = 0; (i < Nstars) && (j < Nave); ) {
     if (!finite(X1[i]) || !finite(Y1[i])) { 
@@ -223,7 +229,7 @@
   /** incorporate unmatched image stars, if this star is in field of this catalog **/
   /* these new entries are all written out in UPDATE mode */ 
-  for (i = 0; (i < Nstars) && !options.only_match; i++) {
+  for (i = 0; (i < Nstars) && !options.only_match; i += NSTAR_GROUP) {
     /* make sure there is space for next entry */
-    if (Nmeas >= NMEAS) {
+    if (Nmeas >= NMEAS - NSTAR_GROUP) {
       NMEAS = Nmeas + 1000;
       REALLOCATE (next_meas, off_t, NMEAS);
@@ -245,5 +251,5 @@
     catalog[0].average[Nave].dD        	   = 0;
 
-    catalog[0].average[Nave].Nmeasure  	   = 1;
+    catalog[0].average[Nave].Nmeasure  	   = NSTAR_GROUP;
     catalog[0].average[Nave].Nmissing  	   = 0;
     catalog[0].average[Nave].Nextend       = 0;
@@ -285,26 +291,32 @@
     }
 
-    // supply the measurments from this detection
-    catalog[0].measure[Nmeas]           = stars[N].measure;
-
-    // the following measure elements cannot be set until here:
-    catalog[0].measure[Nmeas].dR       = 0.0; // astrometric offset, not error
-    catalog[0].measure[Nmeas].dD       = 0.0; // astrometric offset, not error
-    catalog[0].measure[Nmeas].dbFlags  = 0;
-    catalog[0].measure[Nmeas].averef   = Nave;
-    catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
-    catalog[0].measure[Nmeas].catID    = catalog[0].catID;
-
-    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
-    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
-    if (Nsec > -1) { 
-	catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
-    }
-
-    /* next[Nmeas] should always be -1 in this context (it is always the only
-       measurement for the star) */
-    stars[N].found = Nmeas;
-    next_meas[Nmeas] = -1;
-    Nmeas ++;
+    for (j = 0; j < NSTAR_GROUP; j++) {
+        // supply the measurments from this detection
+        catalog[0].measure[Nmeas]           = stars[N].measure;
+        N = N1[i + j];
+
+        // the following measure elements cannot be set until here:
+        catalog[0].measure[Nmeas].dR       = 0.0; // astrometric offset, not error
+        catalog[0].measure[Nmeas].dD       = 0.0; // astrometric offset, not error
+        catalog[0].measure[Nmeas].dbFlags  = 0;
+        catalog[0].measure[Nmeas].averef   = Nave;
+        catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
+        catalog[0].measure[Nmeas].catID    = catalog[0].catID;
+
+        /* set the average magnitude if not already set and the photcode.equiv is not 0 */
+        /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+        if (Nsec > -1) { 
+            catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+        }
+
+        /* next[Nmeas] should always be -1 in this context (it is always the only
+           measurement for the star) */
+        stars[N].found = Nmeas;
+        next_meas[Nmeas] = -1;  // inital value here update below
+        Nmeas ++;
+    }
+    for (j = 0; j < NSTAR_GROUP - 1; j++) {
+        next_meas[Nmeas - NSTAR_GROUP + j] = Nmeas - NSTAR_GROUP + j + 1;
+    }
     Nave ++;
   }
