Index: /trunk/Ohana/src/photdbc/include/photdbc.h
===================================================================
--- /trunk/Ohana/src/photdbc/include/photdbc.h	(revision 28330)
+++ /trunk/Ohana/src/photdbc/include/photdbc.h	(revision 28331)
@@ -52,4 +52,5 @@
 double CHISQ_MAX;
 double SIGMA_MAX;
+double AVE_SIGMA_LIM;
 int    NMEAS_MIN;
 double ZERO_POINT;
Index: /trunk/Ohana/src/photdbc/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/photdbc/src/ConfigInit.c	(revision 28330)
+++ /trunk/Ohana/src/photdbc/src/ConfigInit.c	(revision 28331)
@@ -42,4 +42,5 @@
 
   ScanConfig (config, "SIGMA_MAX",              "%lf", 0, &SIGMA_MAX);
+  ScanConfig (config, "AVE_SIGMA_LIM",          "%lf", 0, &AVE_SIGMA_LIM);
   ScanConfig (config, "NMEAS_MIN",              "%d",  0, &NMEAS_MIN);
 
Index: /trunk/Ohana/src/photdbc/src/copy_images.c
===================================================================
--- /trunk/Ohana/src/photdbc/src/copy_images.c	(revision 28330)
+++ /trunk/Ohana/src/photdbc/src/copy_images.c	(revision 28331)
@@ -6,4 +6,5 @@
   off_t Nimage;
   char *ImageOut;
+  unsigned int imageID;
   FITS_DB in;
   FITS_DB out;
@@ -47,4 +48,12 @@
   dvo_image_addrows (&out, image, Nimage);
 
+  // note that imageID is unsigned int
+  status = gfits_scan (&in.header, "IMAGEID", "%u", 1, &imageID);
+  if (!status) {
+    status = gfits_scan (&in.header, "NIMAGES", "%u", 1, &imageID);
+    imageID++;
+  }
+  status = gfits_modify (&out.header, "IMAGEID", "%u", 1, imageID);
+
   dvo_image_update (&out, VERBOSE);
   dvo_image_unlock (&out);
Index: /trunk/Ohana/src/photdbc/src/make_subcatalog.c
===================================================================
--- /trunk/Ohana/src/photdbc/src/make_subcatalog.c	(revision 28330)
+++ /trunk/Ohana/src/photdbc/src/make_subcatalog.c	(revision 28331)
@@ -8,5 +8,6 @@
   off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
   double mag, minMag;
-
+  int keep;
+  
   Nsecfilt = GetPhotcodeNsecfilt ();
   assert (catalog[0].Nsecfilt == Nsecfilt);
@@ -25,4 +26,15 @@
     // exclude stars with too few measurements
     if (NMEAS_MIN && (catalog[0].average[i].Nmeasure < NMEAS_MIN)) continue; 
+
+    if (AVE_SIGMA_LIM) {
+      // if all of the average magnitude errors are >AVE_SIGMA_LIM, drop the object
+      keep = FALSE;
+      for (j = 0; !keep && (j < Nsecfilt); j++) {
+	if (catalog[0].secfilt[Nsecfilt*i+j].dM < AVE_SIGMA_LIM) {
+	  keep = TRUE;
+	}
+      }
+      if (!keep) continue;
+    }
 
     /* assign average and secfilt values */
Index: /trunk/Ohana/src/photdbc/src/photdbc.c
===================================================================
--- /trunk/Ohana/src/photdbc/src/photdbc.c	(revision 28330)
+++ /trunk/Ohana/src/photdbc/src/photdbc.c	(revision 28331)
@@ -21,5 +21,5 @@
   skylist = SkyListByPatch (sky, -1, &REGION);
   for (i = 0; i < skylist[0].Nregions; i++) {
-    if (i % 100 == 0) fprintf (stderr, "%s\n", skylist[0].regions[i][0].name);
+    if (VERBOSE) fprintf (stderr, "%s\n", skylist[0].regions[i][0].name);
 
     // set the parameters which guide catalog open/load/create
@@ -56,4 +56,12 @@
     }
 
+    // the output catalog needs to have the same values for 'objID' and 'sorted' as the input
+    outcatalog.objID = incatalog.objID;
+    outcatalog.sorted = incatalog.sorted;
+    if (!incatalog.sorted) {
+      fprintf (stderr, "ERROR: input db must be sorted: %s\n", incatalog.filename);
+      exit (2);
+    }
+
     /* limit number of measures based on selections */
     make_subcatalog (&outcatalog, &incatalog);
