Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 27391)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 27392)
@@ -145,4 +145,5 @@
 char     *SELECT_2MASS_QUALITY;  // used only by get2mass_as
 int NREFSTAR_GROUP;
+int NSTAR_GROUP;
 
 /*** addstar prototypes ***/
Index: /trunk/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27391)
+++ /trunk/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 27392)
@@ -258,4 +258,5 @@
   }
 
+  NSTAR_GROUP = NFILTER;
   *nimages += NFILTER;
   *nstars = Nstars*NFILTER;
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 27391)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 27392)
@@ -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: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 27391)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 27392)
@@ -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, int, 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, int, 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: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27391)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 27392)
@@ -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
@@ -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])) { 
@@ -222,7 +228,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, int, NMEAS);
@@ -244,5 +250,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;
@@ -286,26 +292,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 ++;
   }
