Index: branches/czw_branch/20100519/Ohana/src/addstar/test/dvomerge.dvo
===================================================================
--- branches/czw_branch/20100519/Ohana/src/addstar/test/dvomerge.dvo	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/addstar/test/dvomerge.dvo	(revision 28338)
@@ -105,8 +105,8 @@
 end
 
-# create 2 populated catdirs, each with a couple of cmf files
-macro test.dvomerge.create
-
-  tapPLAN 21
+# create 2 populated catdirs, each with a couple of cmf files -- force some unmatched objects 
+macro test.dvomerge.update.extras
+
+  tapPLAN 51
 
   exec rm -rf catdir.test1
@@ -124,4 +124,6 @@
   exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
 
+  # generate a few extra unmatched sources 
+  mkinput.extras
   exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
@@ -130,5 +132,7 @@
   exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
 
-  exec dvomerge catdir.test1 and catdir.test2 to catdir.test3
+  exec rsync -auc catdir.test2/ catdir.test3/
+
+  exec dvomerge catdir.test1 into catdir.test3
 
   catdir catdir.test3
@@ -205,4 +209,104 @@
 end
 
+# create 2 populated catdirs, each with a couple of cmf files
+macro test.dvomerge.create
+
+  tapPLAN 21
+
+  exec rm -rf catdir.test1
+  exec rm -rf catdir.test2
+  exec rm -rf catdir.test3
+
+  $RA = 10.0
+  $DEC = 20.0
+
+  mkinput
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 02:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test1 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 03:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 04:00:00 -radec $RA $DEC
+  exec addstar -D CATDIR catdir.test2 -D CAMERA simtest test.cmf
+
+  exec dvomerge catdir.test1 and catdir.test2 to catdir.test3
+
+  catdir catdir.test3
+  skyregion {$RA-1} {$RA+1} {$DEC-1} {$DEC+1} 
+  mextract ra dec mag
+  create n 0 ra[]
+  subset r0 = ra if (n % 4 == 0)
+  subset r1 = ra if (n % 4 == 1)
+  subset r2 = ra if (n % 4 == 2)
+  subset r3 = ra if (n % 4 == 3)
+
+  catdir catdir.test1/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R0 = RA if (N % 2 == 0)
+  subset R1 = RA if (N % 2 == 1)
+
+  set dr0 = r0 - R0
+  vstat -q dr0
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr1 = r1 - R1
+  vstat -q dr1
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  catdir catdir.test2/
+  mextract RA DEC MAG
+  create N 0 RA[]
+  subset R2 = RA if (N % 2 == 0)
+  subset R3 = RA if (N % 2 == 1)
+
+  set dr2 = r2 - R2
+  vstat -q dr2
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  set dr3 = r3 - R3
+  vstat -q dr3
+  tapOK {abs($MEAN)  < 0.001} "ra (in - 0) vs ra (out - 0) (MEAN)"
+  tapOK {abs($SIGMA) < 0.001} "ra (in - 0) vs ra (out - 0) (SIGMA)"
+
+  # check on updates to imageID
+  catdir catdir.test3
+  imextract imageID
+  sort imageID
+  tapOK {imageID[]  == 4} "image IDs exist"
+  tapOK {imageID[0] == 1} "updated image IDs"
+  tapOK {imageID[1] == 2} "updated image IDs"
+  tapOK {imageID[2] == 3} "updated image IDs"
+  tapOK {imageID[3] == 4} "updated image IDs"
+
+  catdir catdir.test3
+  mextract imageID, time
+  set id = imageID
+  set t = time
+  imextract imageID, time
+
+  for i 0 time[]
+    subset T = t if (id == imageID[$i])
+    set dT = T - time[$i]
+    vstat -q dT 
+    tapOK {abs($MEAN)  < 0.00001} "time for measure ID $i (MEAN)"
+    tapOK {abs($SIGMA) < 0.00001} "time for measure ID $i (SIGMA)"
+  end
+
+  # exec rm test.in.txt test.cmf
+  # exec rm -rf catdir.test1
+  # exec rm -rf catdir.test2
+  # exec rm -rf catdir.test3
+
+  tapDONE
+end
+
 # make a simple input file for mkcmf
 macro mkinput.alt
@@ -225,4 +329,22 @@
   for i 10 1024 100
     for j 10 1024 100
+      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  output stdout
+end
+
+# make a simple input file for mkcmf
+macro mkinput.extras
+  exec rm -f test.in.txt
+
+  output test.in.txt
+  for i 10 1024 100
+    for j 10 1024 100
+      fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
+    end
+  end
+  for i 20 1024 500
+    for j 20 1024 500
       fprintf " %4d %4d  %6.2f" $i $j {-15.0 + 2.5*($i + $j)/1000.0}
     end
Index: branches/czw_branch/20100519/Ohana/src/dvomerge/src/LoadCatalog.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 28338)
@@ -7,9 +7,6 @@
     catalog[0].Nsecfilt  = GetPhotcodeNsecfilt ();
 
-    if (!strcmp (mode, "w")) {
-	catalog[0].catflags = LOAD_NONE;
-    } else {
-	catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-    }
+    // always load all of the data (if any exists)
+    catalog[0].catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
 
     catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
Index: branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomerge.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomerge.c	(revision 28338)
@@ -7,4 +7,6 @@
   ConfigInit (&argc, argv);
   dvomerge_args (&argc, argv);
+
+  // XXX require both inputs to be sorted?
 
   if (argc == 6) dvomergeCreate (argc, argv);
Index: branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 28338)
@@ -16,9 +16,14 @@
   output = argv[3];
 
-  // the first input defines the photcode table & db layout
-  sprintf (filename, "%s/Photcodes.dat", input);
+  // since we are merging the input db into the output db, the output defines the photcode
+  // table & db layout but, this requires the output to exist.  if it does not, instead use the
+  // input.
+  sprintf (filename, "%s/Photcodes.dat", output);
   if (!LoadPhotcodes (filename, NULL, FALSE)) {
-    fprintf (stderr, "error loading photcode table %s\n", filename);
-    exit (1);
+    sprintf (filename, "%s/Photcodes.dat", input);
+    if (!LoadPhotcodes (filename, NULL, FALSE)) {
+      fprintf (stderr, "error loading photcode table: tried %s/Photcodes.dat and %s/Photcodes.dat\n", output, input);
+      exit (1);
+    }
   }
 
@@ -27,8 +32,14 @@
   // load the sky table for the existing database
   insky = SkyTableLoadOptimal (input, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
+  if (!insky) {
+      Shutdown ("can't read SkyTable for %s", input);
+  }
   SkyTableSetFilenames (insky, input, "cpt");
 
   // generate an output table populated at the desired depth
-  outsky = SkyTableLoadOptimal (output, NULL, NULL, TRUE, SKY_DEPTH, VERBOSE);
+  outsky = SkyTableLoadOptimal (output, NULL, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+  if (!outsky) {
+      Shutdown ("can't read or create SkyTable for %s", output);
+  }
   SkyTableSetFilenames (outsky, output, "cpt");
 
@@ -43,6 +54,6 @@
     if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
 
-    // load / create output catalog
-    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "a");
+    // load / create output catalog (if catalog does not exist, it will be created)
+    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
 
     // combine only tables at equal or larger depth
@@ -102,8 +113,8 @@
   // load the image table 
   if (inDB.dbstate == LCK_EMPTY) {
-    Shutdown ("can't find input (1) image catalog %s", inDB.filename);
+    Shutdown ("can't find input image catalog %s", inDB.filename);
   }
   if (!dvo_image_load (&inDB, VERBOSE, TRUE)) {
-    Shutdown ("can't read input (1) image catalog %s", inDB.filename);
+    Shutdown ("can't read input image catalog %s", inDB.filename);
   }
 
@@ -117,8 +128,9 @@
   /* load the image table */
   if (outDB.dbstate == LCK_EMPTY) {
-    Shutdown ("can't find input (2) image catalog %s", outDB.filename);
-  }
-  if (!dvo_image_load (&outDB, VERBOSE, TRUE)) {
-    Shutdown ("can't read input (2) image catalog %s", outDB.filename);
+    dvo_image_create (&outDB, GetZeroPoint());
+  } else {
+    if (!dvo_image_load (&outDB, VERBOSE, TRUE)) {
+      Shutdown ("can't read output image catalog %s", outDB.filename);
+    }
   }
 
Index: branches/czw_branch/20100519/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 28338)
@@ -63,4 +63,6 @@
   tcoords.Npolyterms = 1;
   strcpy (tcoords.ctype, "RA---ARC");
+
+  if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
 
   /* build spatial index (RA sort) referencing input array sequence */
@@ -161,4 +163,6 @@
       REALLOCATE (output[0].measure, Measure, NMEAS);
     }
+
+    // 4) average properties from the input and the output db need to be properly merged.
 
     /** add ALL measurements for this input average object **/
@@ -209,4 +213,18 @@
     }
 
+    // update the average properties to reflect the incoming entries:
+    // if the original value is NAN but the input value is not, accept the input:
+    for (j = 0; j < Nsecfilt; j++) {
+      if ( isfinite(output[0].secfilt[n*Nsecfilt+j].M)) continue;
+      if (!isfinite( input[0].secfilt[N*Nsecfilt+j].M)) continue;
+      output[0].secfilt[n*Nsecfilt+j].M     = input[0].secfilt[N*Nsecfilt+j].M;
+      output[0].secfilt[n*Nsecfilt+j].dM    = input[0].secfilt[N*Nsecfilt+j].dM;
+      output[0].secfilt[n*Nsecfilt+j].Xm    = input[0].secfilt[N*Nsecfilt+j].Xm;
+      output[0].secfilt[n*Nsecfilt+j].M_20  = input[0].secfilt[N*Nsecfilt+j].M_20;
+      output[0].secfilt[n*Nsecfilt+j].M_80  = input[0].secfilt[N*Nsecfilt+j].M_80;
+      output[0].secfilt[n*Nsecfilt+j].Ncode = input[0].secfilt[N*Nsecfilt+j].Ncode;
+      output[0].secfilt[n*Nsecfilt+j].Nused = input[0].secfilt[N*Nsecfilt+j].Nused;
+    }
+
     /* Nm is updated, but not written out in -update mode (for existing entries)
        Nm is recalculated in build_meas_links if loaded table is not sorted */
@@ -242,4 +260,6 @@
     if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
 
+    // XXX should we accept the input measurements for the fields?
+
     output[0].average[Nave].R         	   = input[0].average[N].R;
     output[0].average[Nave].D         	   = input[0].average[N].D;
@@ -247,5 +267,5 @@
     output[0].average[Nave].dD        	   = 0;
 
-    output[0].average[Nave].Nmeasure  	   = 1;
+    output[0].average[Nave].Nmeasure  	   = 0; // this value is update as the measurements are associated with this entry below
     output[0].average[Nave].Nmissing  	   = 0;
     output[0].average[Nave].Nextend        = 0;
@@ -282,11 +302,21 @@
 
     for (j = 0; j < Nsecfilt; j++) {
-      output[0].secfilt[Nave*Nsecfilt+j].M  = NAN;
-      output[0].secfilt[Nave*Nsecfilt+j].dM = NAN;
-      output[0].secfilt[Nave*Nsecfilt+j].Xm = NAN_S_SHORT;
-      output[0].secfilt[Nave*Nsecfilt+j].M_20 	= NAN_S_SHORT;
-      output[0].secfilt[Nave*Nsecfilt+j].M_80 	= NAN_S_SHORT;
-      output[0].secfilt[Nave*Nsecfilt+j].Ncode = 0;
-      output[0].secfilt[Nave*Nsecfilt+j].Nused = 0;
+      if (isfinite(input[0].secfilt[N*Nsecfilt+j].M)) {
+	output[0].secfilt[Nave*Nsecfilt+j].M     = input[0].secfilt[N*Nsecfilt+j].M;
+	output[0].secfilt[Nave*Nsecfilt+j].dM    = input[0].secfilt[N*Nsecfilt+j].dM;
+	output[0].secfilt[Nave*Nsecfilt+j].Xm    = input[0].secfilt[N*Nsecfilt+j].Xm;
+	output[0].secfilt[Nave*Nsecfilt+j].M_20  = input[0].secfilt[N*Nsecfilt+j].M_20;
+	output[0].secfilt[Nave*Nsecfilt+j].M_80  = input[0].secfilt[N*Nsecfilt+j].M_80;
+	output[0].secfilt[Nave*Nsecfilt+j].Ncode = input[0].secfilt[N*Nsecfilt+j].Ncode;
+	output[0].secfilt[Nave*Nsecfilt+j].Nused = input[0].secfilt[N*Nsecfilt+j].Nused;
+      } else {
+	output[0].secfilt[Nave*Nsecfilt+j].M     = NAN;
+	output[0].secfilt[Nave*Nsecfilt+j].dM    = NAN;
+	output[0].secfilt[Nave*Nsecfilt+j].Xm    = NAN_S_SHORT;
+	output[0].secfilt[Nave*Nsecfilt+j].M_20  = NAN_S_SHORT;
+	output[0].secfilt[Nave*Nsecfilt+j].M_80  = NAN_S_SHORT;
+	output[0].secfilt[Nave*Nsecfilt+j].Ncode = 0;
+	output[0].secfilt[Nave*Nsecfilt+j].Nused = 0;
+      }
     }
 
@@ -304,6 +334,8 @@
       output[0].measure[Nmeas].catID    = output[0].catID;
 
-      /* next[Nmeas] should always be -1 in this context (it is always the only
-	 measurement for the star) */
+      // as we add measurements, update Nmeasure to match
+      output[0].average[Nave].Nmeasure ++;
+
+      /* we set next[Nmeas] to -1 here, and update correctly below */
       input[0].found[N] = Nmeas;
       next_meas[Nmeas] = -1;
@@ -327,5 +359,5 @@
 # endif
 
-# define NOSORT FALSE
+# define NOSORT 0
   if (NOSORT) {
     output[0].sorted = FALSE;
Index: branches/czw_branch/20100519/Ohana/src/libdvo/src/SavePhotcodesText.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/libdvo/src/SavePhotcodesText.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/libdvo/src/SavePhotcodesText.c	(revision 28338)
@@ -69,5 +69,5 @@
 	     type,
 	     table[0].code[i].C*SCALE, 
-	     table[0].code[i].K*SCALE, 
+	     table[0].code[i].K, 
 	     table[0].code[i].dC*SCALE);
 
Index: branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/create.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/create.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/create.c	(revision 28338)
@@ -4,5 +4,5 @@
   
   int i, N, INT;
-  float start, end, delta;
+  opihi_flt start, end, delta;
   Vector *vec;
   
Index: branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/histogram
===================================================================
--- branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/histogram	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/histogram	(revision 28338)
@@ -1,8 +1,19 @@
 
-   histogram <buffer> <x> <y> [-region sx sy nx ny] [-range min max]
+   histogram <invec> <outvec> <start> <end> [<delta>] [-range <dx_outvec>]
 
-   calculate a histogram of the image pixel values in the given
-   buffer, optionally constrained to the given region, with optional
-   max and min values.  the results are placed in the vectors x and y,
-   which contain the pixel values and the number of occurences.
+   calculate a histogram of the <invec> values and store the
+   occurrences count in the <outvec> buffer. Optionally constrained to
+   the given <start>-<end> region with <delta> step value (default
+   step is 1). The optional '-range <dx_outvec>' parameter allows storing
+   the range <start>-<end> values with <delta> increment
 
+   Sample code usage:
+   
+   # create a vector ('x') containing arbitrary values  [0.:1.] range
+   create y 0 100 1; set x = sin(y)
+
+   # build histogram from x from 0. to 1. with 0.1 delta step
+   histogram x xhist 0. 1. .1 -range dx
+
+   # plot corresponding histogram
+   limits dx xhist; clear; box; plot dx xhist -x 1
Index: branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/imhist
===================================================================
--- branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/imhist	(revision 28338)
+++ branches/czw_branch/20100519/Ohana/src/opihi/cmd.data/help/imhist	(revision 28338)
@@ -0,0 +1,8 @@
+
+   imhist <buffer> <x> <y> [-region sx sy nx ny] [-range min max]
+
+   calculate a histogram of the image pixel values in the given
+   buffer, optionally constrained to the given region, with optional
+   max and min values.  the results are placed in the vectors x and y,
+   which contain the pixel values and the number of occurences.
+
Index: branches/czw_branch/20100519/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/opihi/dvo/gstar.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/opihi/dvo/gstar.c	(revision 28338)
@@ -165,5 +165,7 @@
 	gprint (GP_LOG, "%3d   ",  catalog.average[k].Nmeasure);
 	gprint (GP_LOG, "%4.1f ",  0.01*catalog.average[k].Xp);
-	gprint (GP_LOG, "%5d ",     catalog.average[k].flags);
+	gprint (GP_LOG, "%5x ",    catalog.average[k].flags);
+	gprint (GP_LOG, "%x ",     catalog.average[k].objID);
+	gprint (GP_LOG, "%x ",     catalog.average[k].catID);
 	
 	if (FULL_OUTPUT) {
@@ -176,6 +178,4 @@
 	    gprint (GP_LOG, "%f ",     catalog.average[k].P);
 	    gprint (GP_LOG, "%f ",     catalog.average[k].dP);
-	    gprint (GP_LOG, "%x ",     catalog.average[k].objID);
-	    gprint (GP_LOG, "%x ",     catalog.average[k].catID);
 	}
 
@@ -244,6 +244,4 @@
 		gprint (GP_LOG, "%f ", catalog.measure[m].crNsigma);
 		gprint (GP_LOG, "%f ", catalog.measure[m].extNsigma);
-		gprint (GP_LOG, "%f ", 0.01*catalog.measure[m].FWx);
-		gprint (GP_LOG, "%f ", 0.01*catalog.measure[m].FWy);
 		gprint (GP_LOG, "%f ", (360.0/(float)0xffff)*catalog.measure[m].theta);
 	    }
Index: branches/czw_branch/20100519/Ohana/src/opihi/pcontrol/StartJob.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/opihi/pcontrol/StartJob.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/opihi/pcontrol/StartJob.c	(revision 28338)
@@ -36,5 +36,5 @@
   }
 
-  fprintf (stderr, "command: %s\n", line);
+  // fprintf (stderr, "command: %s\n", line);
 
   status = PclientCommand (host, line, PCLIENT_PROMPT, PCONTROL_RESP_START_JOB);
Index: branches/czw_branch/20100519/Ohana/src/photdbc/include/photdbc.h
===================================================================
--- branches/czw_branch/20100519/Ohana/src/photdbc/include/photdbc.h	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/photdbc/include/photdbc.h	(revision 28338)
@@ -52,4 +52,5 @@
 double CHISQ_MAX;
 double SIGMA_MAX;
+double AVE_SIGMA_LIM;
 int    NMEAS_MIN;
 double ZERO_POINT;
Index: branches/czw_branch/20100519/Ohana/src/photdbc/src/ConfigInit.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/photdbc/src/ConfigInit.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/photdbc/src/ConfigInit.c	(revision 28338)
@@ -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: branches/czw_branch/20100519/Ohana/src/photdbc/src/copy_images.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/photdbc/src/copy_images.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/photdbc/src/copy_images.c	(revision 28338)
@@ -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: branches/czw_branch/20100519/Ohana/src/photdbc/src/make_subcatalog.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/photdbc/src/make_subcatalog.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/photdbc/src/make_subcatalog.c	(revision 28338)
@@ -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: branches/czw_branch/20100519/Ohana/src/photdbc/src/photdbc.c
===================================================================
--- branches/czw_branch/20100519/Ohana/src/photdbc/src/photdbc.c	(revision 28334)
+++ branches/czw_branch/20100519/Ohana/src/photdbc/src/photdbc.c	(revision 28338)
@@ -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);
