Index: /branches/czw_branch/20100519/Ohana/src/addstar/test/dvomerge.dvo
===================================================================
--- /branches/czw_branch/20100519/Ohana/src/addstar/test/dvomerge.dvo	(revision 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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 28337)
+++ /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);
Index: /branches/czw_branch/20100519/ippScripts/scripts/automate_stacks.pl
===================================================================
--- /branches/czw_branch/20100519/ippScripts/scripts/automate_stacks.pl	(revision 28337)
+++ /branches/czw_branch/20100519/ippScripts/scripts/automate_stacks.pl	(revision 28338)
@@ -674,5 +674,5 @@
 
     my $cmd = "$dettool";
-    $cmd .= " -pretend ";
+#    $cmd .= " -pretend ";
     $cmd .= " -simple -dbname $dbname -definebyquery -det_type $det_type ";
     $cmd .= " -mode verify -ref_det_id $ref_det_id -ref_iter $ref_iter ";
Index: /branches/czw_branch/20100519/ippScripts/scripts/minidvodb_merge.pl
===================================================================
--- /branches/czw_branch/20100519/ippScripts/scripts/minidvodb_merge.pl	(revision 28337)
+++ /branches/czw_branch/20100519/ippScripts/scripts/minidvodb_merge.pl	(revision 28338)
@@ -171,5 +171,5 @@
             if ($this_is_the_first) {
 		
-		$merge_command = "cp -rp $minidvodb/* $mergedvodb";
+		$merge_command = "rsync -rvat $minidvodb/* $mergedvodb";
 	    } else {
                 $merge_command = "$dvomerge $minidvodb into $mergedvodb";
Index: /branches/czw_branch/20100519/ippTasks/nightly_stacks.pro
===================================================================
--- /branches/czw_branch/20100519/ippTasks/nightly_stacks.pro	(revision 28337)
+++ /branches/czw_branch/20100519/ippTasks/nightly_stacks.pro	(revision 28338)
@@ -214,6 +214,7 @@
   periods         -exec $LOADEXEC
   periods         -timeout 30
-  trange          23:00:00 24:00:00 -nmax 1
+  trange          23:00:00 23:59:59 -nmax 1
   npending        1
+  active          false
 
   task.exec
Index: /branches/czw_branch/20100519/ippTasks/stack.pro
===================================================================
--- /branches/czw_branch/20100519/ippTasks/stack.pro	(revision 28337)
+++ /branches/czw_branch/20100519/ippTasks/stack.pro	(revision 28338)
@@ -426,4 +426,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 1200
+  trange       07:00:00 08:00:00
   npending     1
 
Index: /branches/czw_branch/20100519/ippTools/share/chiptool_processedimfile.sql
===================================================================
--- /branches/czw_branch/20100519/ippTools/share/chiptool_processedimfile.sql	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/share/chiptool_processedimfile.sql	(revision 28338)
@@ -29,5 +29,6 @@
     rawImfile.magicked AS raw_magicked,
     rawImfile.burntool_state,
-    magicDSRun.state AS dsRun_state
+    magicDSRun.state AS dsRun_state,
+    magicDSRun.magic_ds_id
 FROM chipRun
 JOIN chipImfile
Index: /branches/czw_branch/20100519/ippTools/share/pubtool_definerun.sql
===================================================================
--- /branches/czw_branch/20100519/ippTools/share/pubtool_definerun.sql	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/share/pubtool_definerun.sql	(revision 28338)
@@ -6,13 +6,19 @@
 FROM (
     -- Get diffs to publish
-    SELECT
+    SELECT DISTINCT
         client_id,
         diff_id AS stage_id,
-        label AS src_label
+        diffRun.label AS src_label
     FROM publishClient
     JOIN diffRun
+    JOIN diffInputSkyfile USING(diff_id)
+    JOIN warpRun ON warpRun.warp_id = diffInputSkyfile.warp1 -- Only JOINing input, not reference!
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
     WHERE publishClient.stage = 'diff'
         AND publishClient.active = 1
-        AND diffRun.state = 'full'
+        AND diffRun.state IN ('full', 'cleaned', 'goto_cleaned')
         AND (diffRun.magicked > 0 OR diffRun.diff_mode = 4 OR publishClient.magicked = 0)
     -- WHERE hook %s
@@ -22,10 +28,12 @@
         client_id,
         cam_id AS stage_id,
-        label AS src_label
+        camRun.label AS src_label
     FROM publishClient
     JOIN camRun
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
     WHERE publishClient.stage = 'camera'
         AND publishClient.active = 1
-        AND camRun.state = 'full'
+        AND camRun.state IN ('full', 'cleaned', 'goto_cleaned')
         AND (camRun.magicked > 0 OR publishClient.magicked = 0)
     -- WHERE hook %s
@@ -33,3 +41,2 @@
 -- Only get stuff that hasn't been published
 LEFT JOIN publishRun USING(client_id, stage_id)
-WHERE publishRun.client_id IS NULL
Index: /branches/czw_branch/20100519/ippTools/share/pubtool_pending.sql
===================================================================
--- /branches/czw_branch/20100519/ippTools/share/pubtool_pending.sql	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/share/pubtool_pending.sql	(revision 28338)
@@ -26,5 +26,5 @@
         AND publishClient.active = 1
         AND publishRun.state = 'new'
-        AND diffRun.state = 'full'
+        AND diffRun.state IN ('full', 'cleaned', 'goto_cleaned')
         AND (diffRun.magicked > 0 OR diffRun.diff_mode = 4 OR publishClient.magicked = 0)
         -- WHERE hook %s
@@ -47,5 +47,5 @@
         AND publishClient.active = 1
         AND publishRun.state ='new'
-        AND camRun.state = 'full'
+        AND camRun.state IN ('full', 'cleaned', 'goto_cleaned')
         AND (camRun.magicked > 0 OR publishClient.magicked = 0)
         -- WHERE hook %s
Index: /branches/czw_branch/20100519/ippTools/src/pstamptool.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/pstamptool.c	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/src/pstamptool.c	(revision 28338)
@@ -870,8 +870,9 @@
 
     PXOPT_LOOKUP_S64(job_id,    config->args, "-job_id", false, false);
+    PXOPT_LOOKUP_S64(req_id,    config->args, "-req_id", false, false);
     PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", false, false);
 
-    if (!job_id && !dep_id) {
-        psError(PS_ERR_UNKNOWN, true, "at least -job_id or -dep_id is required");
+    if (!job_id && !req_id && !dep_id) {
+        psError(PS_ERR_UNKNOWN, true, "at least one of -job_id -req_id or -dep_id is required");
         return false;
     }
@@ -888,5 +889,7 @@
 
     PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
     PXOPT_COPY_S64(config->args, where, "-dep_id", "dep_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-state",  "pstampJob.state", "==");
 
     psString query = pxDataGet("pstamptool_updatejob.sql");
Index: /branches/czw_branch/20100519/ippTools/src/pstamptoolConfig.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/pstamptoolConfig.c	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/src/pstamptoolConfig.c	(revision 28338)
@@ -160,6 +160,8 @@
     // -updatejob
     psMetadata *updatejobArgs = psMetadataAlloc();
-    psMetadataAddS64(updatejobArgs, PS_LIST_TAIL, "-job_id", 0,            "req_id for which to change state", 0);
-    psMetadataAddS64(updatejobArgs, PS_LIST_TAIL, "-dep_id", 0,            "dep_id for which to change state", 0);
+    psMetadataAddS64(updatejobArgs, PS_LIST_TAIL, "-req_id", 0,            "req_id of jobs to update", 0);
+    psMetadataAddS64(updatejobArgs, PS_LIST_TAIL, "-job_id", 0,            "job_id of jobs to update", 0);
+    psMetadataAddS64(updatejobArgs, PS_LIST_TAIL, "-dep_id", 0,            "dep_id of jobs to update", 0);
+    psMetadataAddStr(updatejobArgs, PS_LIST_TAIL, "-state", 0,            "current state of jobs to update", 0);
     psMetadataAddStr(updatejobArgs, PS_LIST_TAIL, "-set_state", 0,            "new state", NULL);
     psMetadataAddS16(updatejobArgs, PS_LIST_TAIL, "-set_fault", 0,            "new result", 0);
Index: /branches/czw_branch/20100519/ippTools/src/pubtool.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/pubtool.c	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/src/pubtool.c	(revision 28338)
@@ -151,37 +151,77 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psMetadata *where = psMetadataAlloc(); // WHERE conditions
+    psMetadata *diffWhere = psMetadataAlloc(); // WHERE conditions for diffs
+    psMetadata *camWhere = psMetadataAlloc(); // WHERE conditions for cams
 
     // required
 
     // optional
-    PXOPT_COPY_S64(config->args, where, "-client_id", "client_id", "==");
-    pxAddLabelSearchArgs(config, where, "-label", "label", "=="); // define using newExp label
+    PXOPT_COPY_S64(config->args, diffWhere, "-client_id", "client_id", "==");
+    pxAddLabelSearchArgs(config, diffWhere, "-label", "diffRun.label", "==");
+    pxAddLabelSearchArgs(config, diffWhere, "-data_group", "diffRun.data_group", "LIKE");
+    PXOPT_COPY_TIME(config->args, diffWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
+    PXOPT_COPY_TIME(config->args, diffWhere, "-dateobs_end", "rawExp.dateobs", "<=");
+    PXOPT_COPY_STR(config->args, diffWhere, "-filter", "rawExp.filter", "LIKE");
+    PXOPT_COPY_STR(config->args, diffWhere, "-obs_mode", "rawExp.obs_mode", "LIKE");
+
+    PXOPT_COPY_S64(config->args, camWhere, "-client_id", "client_id", "==");
+    pxAddLabelSearchArgs(config, camWhere, "-label", "camRun.label", "==");
+    pxAddLabelSearchArgs(config, camWhere, "-data_group", "camRun.data_group", "LIKE");
+    PXOPT_COPY_TIME(config->args, camWhere, "-dateobs_begin", "rawExp.dateobs", ">=");
+    PXOPT_COPY_TIME(config->args, camWhere, "-dateobs_end", "rawExp.dateobs", "<=");
+    PXOPT_COPY_STR(config->args, camWhere, "-filter", "rawExp.filter", "LIKE");
+    PXOPT_COPY_STR(config->args, camWhere, "-obs_mode", "rawExp.obs_mode", "LIKE");
+
+    PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
+    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psString query = pxDataGet("pubtool_definerun.sql"); // Query to run
     if (!query) {
         psError(PXTOOLS_ERR_SYS, false, "Failed to retreive SQL statement");
-        psFree(where);
-        return false;
+        psFree(diffWhere);
+        psFree(camWhere);
+        return false;
+    }
+
+    if (!rerun) {
+        psStringAppend(&query, "\nWHERE publishRun.client_id IS NULL");
+    }
+
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, "\n%s", limitString);
+        psFree(limitString);
     }
 
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
-        psFree(where);
-        return false;
-    }
-
-    psString whereClause = psStringCopy(""); // Additional constraints to add to query
-    if (psListLength(where->list)) {
-        psString clause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&whereClause, "\n AND %s", clause);
+        psFree(diffWhere);
+        psFree(camWhere);
+        return false;
+    }
+
+    psString whereDiff = psStringCopy(""); // Additional constraints to add to query
+    if (psListLength(diffWhere->list)) {
+        psString clause = psDBGenerateWhereConditionSQL(diffWhere, NULL);
+        psStringAppend(&whereDiff, "\n AND %s", clause);
         psFree(clause);
     }
-    psFree(where);
-
-    if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause)) {
+    psFree(diffWhere);
+
+    psString whereCam = psStringCopy(""); // Additional constraints to add to query
+    if (psListLength(camWhere->list)) {
+        psString clause = psDBGenerateWhereConditionSQL(camWhere, NULL);
+        psStringAppend(&whereCam, "\n AND %s", clause);
+        psFree(clause);
+    }
+    psFree(camWhere);
+
+    if (!p_psDBRunQueryF(config->dbh, query, whereDiff, whereCam)) {
         psError(PS_ERR_UNKNOWN, false, "Database error");
         psFree(query);
-        psFree(whereClause);
+        psFree(whereDiff);
+        psFree(whereCam);
         if (!psDBRollback(config->dbh)) {
             psError(PS_ERR_UNKNOWN, false, "Database error");
@@ -190,5 +230,6 @@
     }
     psFree(query);
-    psFree(whereClause);
+    psFree(whereDiff);
+    psFree(whereCam);
 
     psArray *output = p_psDBFetchResult(config->dbh); // Output of SELECT statement
@@ -202,4 +243,14 @@
     if (!psArrayLength(output)) {
         psTrace("pubtool", PS_LOG_INFO, "No rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (pretend) {
+        if (!ippdbPrintMetadatas(stdout, output, "publishRun", !simple)) {
+            psError(psErrorCodeLast(), false, "Failed to print array");
+            psFree(output);
+            return false;
+        }
         psFree(output);
         return true;
@@ -241,5 +292,5 @@
     PXOPT_COPY_STR(config->args, where, "-stage", "publishClient.stage", "==");
     PXOPT_COPY_STR(config->args, where, "-comment", "publishClient.comment", "LIKE");
-    PXOPT_COPY_STR(config->args, where, "-label", "publishRun.label", "==");
+    pxAddLabelSearchArgs(config, where, "-label", "label", "==");
 
     // optional
Index: /branches/czw_branch/20100519/ippTools/src/pubtoolConfig.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/pubtoolConfig.c	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/src/pubtoolConfig.c	(revision 28338)
@@ -64,4 +64,13 @@
     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-client_id", 0, "search by client_id", 0);
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "set and search by label", NULL);
+    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-data_group", PS_META_DUPLICATE_OK, "search by data_group", NULL);
+    psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-dateobs_begin", 0, "search for exposures by time (>=)", NULL);
+    psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-dateobs_end", 0, "search for exposures by time (<=)", NULL);
+    psMetadataAddStr(definerunArgs,  PS_LIST_TAIL, "-filter", 0, "search for filter", NULL);
+    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-obs_mode", 0, "search by observation mode", NULL);
+    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-rerun", 0, "Re-run publish?", false);
+    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-pretend", 0, "Pretend to define?", false);
+    psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
+    psMetadataAddU64(definerunArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
 
     // -pending
@@ -70,5 +79,5 @@
     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-stage", 0, "search on source", NULL);
     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-comment", 0, "search on comment (LIKE)", NULL);
-    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", 0, "search on label", NULL);
+    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search on label", NULL);
     psMetadataAddBool(pendingArgs, PS_LIST_TAIL, "-simple",  0, "use simple output format?", false);
     psMetadataAddU64(pendingArgs, PS_LIST_TAIL, "-limit",  0, "limit result set", 0);
Index: /branches/czw_branch/20100519/ippTools/src/pxtools.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/pxtools.c	(revision 28337)
+++ /branches/czw_branch/20100519/ippTools/src/pxtools.c	(revision 28338)
@@ -250,10 +250,11 @@
         psMetadataItem *item = NULL;
         while ((item = psListGetAndIncrement(iter))) {
+            psMetadataItem *new = psMetadataItemCopy(item);
             // need to change the name and comment
-            psFree (item->name);
-            item->name = psStringCopy (field);
-            psFree (item->comment);
-            item->comment = psStringCopy (op);
-            if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
+            psFree (new->name);
+            new->name = psStringCopy (field);
+            psFree (new->comment);
+            new->comment = psStringCopy (op);
+            if (!psMetadataAddItem(where, new, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
                 psError(psErrorCodeLast(), false, "failed to add item %s", field);
                 psFree(where);
@@ -261,5 +262,5 @@
             }
         }
-        psFree (iter);
+        psFree(iter);
     }
     return true;
Index: /branches/czw_branch/20100519/ippconfig/recipes/nightly_science.config
===================================================================
--- /branches/czw_branch/20100519/ippconfig/recipes/nightly_science.config	(revision 28337)
+++ /branches/czw_branch/20100519/ippconfig/recipes/nightly_science.config	(revision 28338)
@@ -121,4 +121,5 @@
 #  COMMENT STR Stellar Transit%
   STACKABLE BOOL FALSE
+  NOCLEAN BOOL TRUE
 END
 TARGETS METADATA
Index: /branches/czw_branch/20100519/magic/remove/src/streaksio.c
===================================================================
--- /branches/czw_branch/20100519/magic/remove/src/streaksio.c	(revision 28337)
+++ /branches/czw_branch/20100519/magic/remove/src/streaksio.c	(revision 28338)
@@ -1294,5 +1294,12 @@
         }
     }
-    sfiles->maskMask = ~convPoor;
+    // preserve pixels that are only suspect
+    psU32 suspect = (double) psMetadataLookupU32(&status, masks, "SUSPECT");
+    if (!status) {
+        psError(PM_ERR_CONFIG, false, "failed to lookup mask value for SUSPECT in recipes\n");
+        streaksExit("", PS_EXIT_CONFIG_ERROR);
+    }
+
+    sfiles->maskMask = ~(convPoor | suspect);
 }
 
Index: /branches/czw_branch/20100519/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- /branches/czw_branch/20100519/psModules/src/imcombine/pmPSFEnvelope.c	(revision 28337)
+++ /branches/czw_branch/20100519/psModules/src/imcombine/pmPSFEnvelope.c	(revision 28338)
@@ -33,5 +33,5 @@
 
 
-// #define TESTING                         // Enable test output
+//#define TESTING                         // Enable test output
 // #define PEAK_NORM                       // Normalise peaks?
 #define PEAK_FLUX 1.0e4                 // Peak flux for each source
@@ -235,5 +235,5 @@
 
             // Get the radius
-            pmModel *model = pmModelFromPSFforXY(psf, x, y, PEAK_FLUX); // Model for source
+            pmModel *model = pmModelFromPSFforXY(psf, source->peak->xf, source->peak->yf, PEAK_FLUX); // Model for source
             if (!model || (model->flags & MODEL_MASK)) {
                 continue;
@@ -321,5 +321,5 @@
     numFakes = fakes->n;
 
-    if (numFakes == 0.0) {
+    if (numFakes == 0) {
         psError(PS_ERR_UNKNOWN, false, "No fake sources are suitable for PSF fitting.");
         psFree(fakes);
Index: /branches/czw_branch/20100519/pstamp/src/ppstampMakeStamp.c
===================================================================
--- /branches/czw_branch/20100519/pstamp/src/ppstampMakeStamp.c	(revision 28337)
+++ /branches/czw_branch/20100519/pstamp/src/ppstampMakeStamp.c	(revision 28338)
@@ -688,5 +688,10 @@
         }
     }
-    psU32 maskMask = ~convPoor;
+    psU32 suspect = psMetadataLookupU32(&status, masks, "SUSPECT");
+    if (!status) {
+        psError(PM_ERR_CONFIG, false, "failed to lookup mask value for SUSPECT in recipes\n");
+        return false;
+    }
+    psU32 maskMask = ~(convPoor | suspect);
 
     double exciseValue;
