Index: branches/cleanup/ippTools/src/.cvsignore
===================================================================
--- branches/cleanup/ippTools/src/.cvsignore	(revision 17863)
+++ branches/cleanup/ippTools/src/.cvsignore	(revision 18076)
@@ -23,4 +23,5 @@
 difftool
 stacktool
+faketool
 dettool
 detselect
Index: branches/cleanup/ippTools/src/Makefile.am
===================================================================
--- branches/cleanup/ippTools/src/Makefile.am	(revision 17863)
+++ branches/cleanup/ippTools/src/Makefile.am	(revision 18076)
@@ -8,7 +8,8 @@
 	flatcorr \
 	magictool \
-        pstamptool \
+	pstamptool \
 	pxadmin \
 	pxinject \
+	faketool \
 	pzgetexp \
 	pzgetimfiles \
@@ -28,4 +29,5 @@
 	pxconfig.h \
 	pxdata.h \
+	pxfake.h \
 	pxio.h \
 	pxregister.h \
@@ -44,7 +46,8 @@
 	difftool.h \
 	flatcorr.h \
+	faketool.h \
 	guidetool.h \
 	magictool.h \
-        pstamptool.h \
+	pstamptool.h \
 	pxinject.h \
 	pzgetexp.h \
@@ -65,4 +68,5 @@
 	pxdata.c \
 	pxerrors.c \
+	pxfake.c \
 	pxfault.c \
 	pxio.c \
@@ -125,4 +129,10 @@
     camtoolConfig.c
 
+faketool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
+faketool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
+faketool_SOURCES = \
+    faketool.c \
+    faketoolConfig.c
+
 magictool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
 magictool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
Index: branches/cleanup/ippTools/src/camtool.c
===================================================================
--- branches/cleanup/ippTools/src/camtool.c	(revision 17863)
+++ branches/cleanup/ippTools/src/camtool.c	(revision 18076)
@@ -27,5 +27,4 @@
 
 #include "pxtools.h"
-#include "pxwarp.h"
 #include "pxcam.h"
 #include "camtool.h"
@@ -599,33 +598,32 @@
     psFree(output);
     camProcessedExpRow *row = camProcessedExpRowAlloc(
-        pendingRow->cam_id,
-        pendingRow->chip_id,
-        uri,
-        bg,
-        bg_stdev,
-        bg_mean_stdev,
-        bias,
-        bias_stdev,
-        fringe_0,
-        fringe_1,
-        fringe_2,
-        sigma_ra,
-        sigma_dec,
-        ap_resid,
-        ap_resid_stdev,
-        zp_mean,
-        zp_stdev,
-        fwhm_major,
-        fwhm_minor,
-        dtime_detrend,
-        dtime_photom,
-        dtime_astrom,
-        hostname,
-        n_stars,
-        n_extended,
-        n_cr,
-        n_astrom,
-        path_base,
-        code
+            pendingRow->cam_id,
+            uri,
+            bg,
+            bg_stdev,
+            bg_mean_stdev,
+            bias,
+            bias_stdev,
+            fringe_0,
+            fringe_1,
+            fringe_2,
+            sigma_ra,
+            sigma_dec,
+            ap_resid,
+            ap_resid_stdev,
+            zp_mean,
+            zp_stdev,
+            fwhm_major,
+            fwhm_minor,
+            dtime_detrend,
+            dtime_photom,
+            dtime_astrom,
+            hostname,
+            n_stars,
+            n_extended,
+            n_cr,
+            n_astrom,
+            path_base,
+            code
         );
 
@@ -649,7 +647,7 @@
     }
 
-    // should we stop here or proceed on to the warp stage?
     // NULL for end_stage means go as far as possible
-    // we can't start a warp run unlesss tess_id is defined
+    // XXX true for fake too?
+    // XXX we can't start a warp run unlesss tess_id is defined
     if ((pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "cam"))
         || (pendingRow->tess_id == NULL) || psStrcasestr(pendingRow->tess_id, "NULL")) {
@@ -666,8 +664,10 @@
     // else continue on...
 
-    if (!pxwarpQueueByCamID(config,
+    if (!pxfakeQueueByCamID(config,
             pendingRow->cam_id,
             pendingRow->workdir,
             pendingRow->label,
+            pendingRow->reduction,
+            pendingRow->expgroup,
             pendingRow->dvodb,
             pendingRow->tess_id,
@@ -678,5 +678,5 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
         }
-        psError(PS_ERR_UNKNOWN, false, "failed to queue new warpRun");
+        psError(PS_ERR_UNKNOWN, false, "failed to queue new fakeRun");
         psFree(pendingRow);
         return false;
Index: branches/cleanup/ippTools/src/faketool.c
===================================================================
--- branches/cleanup/ippTools/src/faketool.c	(revision 17863)
+++ branches/cleanup/ippTools/src/faketool.c	(revision 18076)
@@ -32,8 +32,8 @@
 
 #include "faketool.h"
-#include "camtool.h"
 
 static bool queueMode(pxConfig *config);
 static bool updaterunMode(pxConfig *config);
+static bool pendingexpMode(pxConfig *config);
 static bool pendingimfileMode(pxConfig *config);
 static bool addprocessedimfileMode(pxConfig *config);
@@ -67,4 +67,5 @@
         MODECASE(FAKETOOL_MODE_QUEUE,                   queueMode);
         MODECASE(FAKETOOL_MODE_UPDATERUN,               updaterunMode);
+        MODECASE(FAKETOOL_MODE_PENDINGEXP,              pendingexpMode);
         MODECASE(FAKETOOL_MODE_PENDINGIMFILE,           pendingimfileMode);
         MODECASE(FAKETOOL_MODE_ADDPROCESSEDIMFILE,      addprocessedimfileMode);
@@ -171,5 +172,5 @@
 
     // find the exp_id of all the exposures that we want to queue up.
-    psString query = pxDataGet("faketool_find_rawexp.sql");
+    psString query = pxDataGet("faketool_find_camrun.sql");
     if (!query) {
         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
@@ -179,6 +180,6 @@
 
     if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp");
-        psStringAppend(&query, " AND %s", whereClause);
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
         psFree(whereClause);
     }
@@ -219,12 +220,12 @@
     }
 
-    // loop over our list of exp_ids
+    // loop over our list of cam_ids
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 
         bool status;
-        psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id");
+        psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id");
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for cam_id");
             psFree(output);
             return false;
@@ -232,10 +233,10 @@
 
         // queue the exp
-        if (!pxfakeQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage)) {
+        if (!pxfakeQueueByCamID(config, cam_id, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage)) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
             psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue exp_id: %" PRId64, exp_id);
+                    "failed to trying to queue cam_id: %" PRId64, cam_id);
             psFree(output);
             return false;
@@ -354,4 +355,74 @@
 
 
+static bool pendingexpMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where, "-fake_id", "fake_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-cam_id", "cam_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-chip_id", "chip_id", "==");
+
+    psString query = pxDataGet("faketool_find_pendingexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        psFree(where);
+        return false;
+    }
+
+    if (where && psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+    psFree(where);
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("camtool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (!convertIdToStr(output)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
+        psFree(output);
+        return false;
+    }
+
+    // negate simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "fakePendingExp", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
 static bool pendingimfileMode(pxConfig *config)
 {
@@ -448,38 +519,17 @@
 
     // fake_id, ext_tag, class_id are required
-    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", true, false);
-    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false);
-    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
+    PXOPT_LOOKUP_STR(fake_id, config->args,     "-fake_id", true, false);
+    PXOPT_LOOKUP_STR(exp_id, config->args,      "-exp_id", true, false);
+    PXOPT_LOOKUP_STR(class_id, config->args,    "-class_id", true, false);
 
     // optional
-    PXOPT_LOOKUP_STR(uri, config->args,            "-uri", false, false);
-    PXOPT_LOOKUP_F32(bg, config->args,             "-bg", false, false);
-    PXOPT_LOOKUP_F32(bg_stdev, config->args,       "-bg_stdev", false, false);
-    PXOPT_LOOKUP_F32(bg_mean_stdev, config->args,  "-bg_mean_stdev", false, false);
-    PXOPT_LOOKUP_F32(bias, config->args,           "-bias", false, false);
-    PXOPT_LOOKUP_F32(bias_stdev, config->args,     "-bias_stdev", false, false);
-    PXOPT_LOOKUP_F32(fringe_0, config->args,       "-fringe_0", false, false);
-    PXOPT_LOOKUP_F32(fringe_1, config->args,       "-fringe_1", false, false);
-    PXOPT_LOOKUP_F32(fringe_2, config->args,       "-fringe_2", false, false);
-    PXOPT_LOOKUP_F32(sigma_ra, config->args,       "-sigma_ra", false, false);
-    PXOPT_LOOKUP_F32(sigma_dec, config->args,      "-sigma_dec", false, false);
-    PXOPT_LOOKUP_F32(ap_resid, config->args,       "-ap_resid", false, false);
-    PXOPT_LOOKUP_F32(ap_resid_stdev, config->args, "-ap_resid_stdev", false, false);
-    PXOPT_LOOKUP_F32(zp_mean, config->args,        "-zp_mean", false, false);
-    PXOPT_LOOKUP_F32(zp_stdev, config->args,       "-zp_stdev", false, false);
-    PXOPT_LOOKUP_F32(fwhm_major, config->args,     "-fwhm_major", false, false);
-    PXOPT_LOOKUP_F32(fwhm_minor, config->args,     "-fwhm_minor", false, false);
-    PXOPT_LOOKUP_F32(dtime_detrend, config->args,  "-dtime_detrend", false, false);
-    PXOPT_LOOKUP_F32(dtime_photom,  config->args,  "-dtime_photom",  false, false);
-    PXOPT_LOOKUP_F32(dtime_astrom,  config->args,  "-dtime_astrom",  false, false);
-    PXOPT_LOOKUP_STR(hostname, config->args,       "-hostname", false, false);
-    PXOPT_LOOKUP_F32(n_stars, config->args, "-n_stars", false, false);
-    PXOPT_LOOKUP_F32(n_extended, config->args, "-n_extended", false, false);
-    PXOPT_LOOKUP_F32(n_cr, config->args, "-n_cr", false, false);
-    PXOPT_LOOKUP_F32(n_astrom, config->args, "-n_astrom", false, false);
-    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
+    PXOPT_LOOKUP_STR(uri, config->args,         "-uri", false, false);
+
+    PXOPT_LOOKUP_F32(dtime_fake, config->args,  "-dtime_fake", false, false);
+    PXOPT_LOOKUP_STR(hostname, config->args,    "-hostname", false, false);
+    PXOPT_LOOKUP_STR(path_base, config->args,   "-path_base", false, false);
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(code, config->args,        "-code", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -493,30 +543,9 @@
                                    class_id,
                                    uri,
-                                   bg,
-                                   bg_stdev,
-                                   bg_mean_stdev,
-                                   bias,
-                                   bias_stdev,
-                                   fringe_0,
-                                   fringe_1,
-                                   fringe_2,
-                                   sigma_ra,
-                                   sigma_dec,
-                                   ap_resid,
-                                   ap_resid_stdev,
-                                   zp_mean,
-                                   zp_stdev,
-                                   fwhm_major,
-                                   fwhm_minor,
-                                   dtime_detrend,
-                                   dtime_photom,
-                                   dtime_astrom,
+                                   dtime_fake,
                                    hostname,
-                                   n_stars,
-                                   n_extended,
-                                   n_cr,
-                                   n_astrom,
                                    path_base,
-                                   code
+                                   code,
+                                   NULL         // epoch
             )) {
         // rollback
@@ -748,8 +777,22 @@
     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
 
-    if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", config->where, code)) {
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", false, false);
+    // convert fake_id into a psS64
+    if (fake_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "fake_id", 0, "==", (psS64)atoll(fake_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id");
+            psFree(where);
+            return false;
+        }
+    }
+    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
+
+    if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
+        psFree(where);
+        return false;
+    }
+    psFree(where);
 
     return true;
@@ -984,10 +1027,8 @@
         // camQueueFakeID() can only be run after fakeRun.state has been set to
         // stop
-        if (!pxcamQueueByFakeID(config,
+        if (!pxwarpQueueByFakeID(config,
                     fakeRun->fake_id,
                     fakeRun->workdir,
                     fakeRun->label,
-                    fakeRun->reduction,
-                    fakeRun->expgroup,
                     fakeRun->dvodb,
                     fakeRun->tess_id,
Index: branches/cleanup/ippTools/src/faketool.h
===================================================================
--- branches/cleanup/ippTools/src/faketool.h	(revision 18076)
+++ branches/cleanup/ippTools/src/faketool.h	(revision 18076)
@@ -0,0 +1,46 @@
+/*
+ * faketool.h
+ *
+ * Copyright (C) 2006-2008  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef FAKETOOL_H
+#define FAKETOOL_H 1
+
+#include "pxtools.h"
+
+typedef enum {
+    FAKETOOL_MODE_NONE      = 0x0,
+    FAKETOOL_MODE_QUEUE,
+    FAKETOOL_MODE_UPDATERUN,
+    FAKETOOL_MODE_PENDINGIMFILE,
+    FAKETOOL_MODE_PENDINGEXP,
+    FAKETOOL_MODE_ADDPROCESSEDIMFILE,
+    FAKETOOL_MODE_PROCESSEDIMFILE,
+    FAKETOOL_MODE_REVERTPROCESSEDIMFILE,
+    FAKETOOL_MODE_UPDATEPROCESSEDIMFILE,
+    FAKETOOL_MODE_BLOCK,
+    FAKETOOL_MODE_MASKED,
+    FAKETOOL_MODE_UNMASKED,
+    FAKETOOL_MODE_UNBLOCK,
+    FAKETOOL_MODE_RETRYPROCESSEDIMFILE,
+    FAKETOOL_MODE_PENDINGCLEANUP,
+    FAKETOOL_MODE_DONECLEANUP,
+} FAKETOOLMode;
+
+pxConfig *faketoolConfig(pxConfig *config, int argc, char **argv);
+
+#endif // FAKETOOL_H
Index: branches/cleanup/ippTools/src/faketoolConfig.c
===================================================================
--- branches/cleanup/ippTools/src/faketoolConfig.c	(revision 17863)
+++ branches/cleanup/ippTools/src/faketoolConfig.c	(revision 18076)
@@ -232,4 +232,15 @@
 
 
+    // -pendingexp
+    psMetadata *pendingexpArgs = psMetadataAlloc();
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-cam_id", 0,
+            "search by camtool ID", NULL);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-chip_id", 0,
+            "search by chiptool ID", NULL);
+    psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
+    psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-simple", 0,
+            "use the simple output format", false);
+
     // -pendingimfile
     psMetadata *pendingimfileArgs = psMetadataAlloc();
@@ -416,15 +427,18 @@
 
     PXOPT_ADD_MODE("-queue",                 "create runs from raw exposures",
-        FAKETOOL_MODE_QUEUE,    queueArgs);
+        FAKETOOL_MODE_QUEUE,                    queueArgs);
     PXOPT_ADD_MODE("-updaterun",             "change fake run properties",
-        FAKETOOL_MODE_UPDATERUN, updaterunArgs);
+        FAKETOOL_MODE_UPDATERUN,                updaterunArgs);
+    PXOPT_ADD_MODE("-pendingexp",           "show pending exposures",
+        FAKETOOL_MODE_PENDINGEXP,               pendingexpArgs);
     PXOPT_ADD_MODE("-pendingimfile",         "show pending imfiles",
-        FAKETOOL_MODE_PENDINGIMFILE,  pendingimfileArgs);
+        FAKETOOL_MODE_PENDINGIMFILE,            pendingimfileArgs);
     PXOPT_ADD_MODE("-addprocessedimfile",    "add a processed imfile",
-        FAKETOOL_MODE_ADDPROCESSEDIMFILE,addprocessedimfileArgs);
+        FAKETOOL_MODE_ADDPROCESSEDIMFILE,       addprocessedimfileArgs);
     PXOPT_ADD_MODE("-processedimfile",       "show processed imfiles",
-        FAKETOOL_MODE_PROCESSEDIMFILE, processedimfileArgs);
-    PXOPT_ADD_MODE("-updateprocessedimfile", "change procesed imfile properties", FAKETOOL_MODE_UPDATEPROCESSEDIMFILE,    updateprocessedimfileArgs);
-    PXOPT_ADD_MODE("-revertprocessedimfile", "undo a processed imfile", FAKETOOL_MODE_REVERTPROCESSEDIMFILE,    revertprocessedimfileArgs);
+        FAKETOOL_MODE_PROCESSEDIMFILE,          processedimfileArgs);
+    PXOPT_ADD_MODE("-updateprocessedimfile","change procesed imfile properties",        FAKETOOL_MODE_UPDATEPROCESSEDIMFILE,    updateprocessedimfileArgs);
+    PXOPT_ADD_MODE("-revertprocessedimfile", "undo a processed imfile",
+        FAKETOOL_MODE_REVERTPROCESSEDIMFILE,    revertprocessedimfileArgs);
     PXOPT_ADD_MODE("-block",                 "set a label block", FAKETOOL_MODE_BLOCK,          blockArgs);
     PXOPT_ADD_MODE("-masked",                "show blocked labels", FAKETOOL_MODE_MASKED,         maskedArgs);
Index: branches/cleanup/ippTools/src/pxfake.c
===================================================================
--- branches/cleanup/ippTools/src/pxfake.c	(revision 18076)
+++ branches/cleanup/ippTools/src/pxfake.c	(revision 18076)
@@ -0,0 +1,188 @@
+/*
+ * pxfake.c
+ *
+ * Copyright (C) 2007-2008  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <ippdb.h>
+#include <string.h>
+
+#include "pxtools.h"
+#include "pxcam.h"
+
+bool pxfakeRunSetState(pxConfig *config, psS64 fake_id, const char *state)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(state, false);
+
+    // check that state is a valid string value
+    if (!(
+            (strncmp(state, "run", 4) == 0)
+            || (strncmp(state, "stop", 5) == 0)
+            || (strncmp(state, "reg", 4) == 0)
+        )
+    ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "invalid fakeRun state: %s", state);
+        return false;
+    }
+
+    char *query = "UPDATE fakeRun SET state = '%s' WHERE fake_id = %" PRId64;
+    if (!p_psDBRunQuery(config->dbh, query, state, fake_id)) {
+        psError(PS_ERR_UNKNOWN, false,
+                "failed to change state for fake_id %" PRId64, fake_id);
+        return false;
+    }
+
+    return true;
+}
+
+
+bool pxfakeRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(state, false);
+
+    // check that state is a valid string value
+    if (!(
+            (strncmp(state, "run", 4) == 0)
+            || (strncmp(state, "stop", 5) == 0)
+            || (strncmp(state, "reg", 4) == 0)
+        )
+    ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "invalid fakeRun state: %s", state);
+        return false;
+    }
+
+    psString query = psStringCopy("UPDATE fakeRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET state = '%s'");
+
+    if (where) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query, state)) {
+        psFree(query);
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psFree(query);
+
+    return true;
+}
+
+
+bool pxfakeRunSetLabel(pxConfig *config, psS64 fake_id, const char *label)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    // note label == NULL should be explicitly allowed
+
+    char *query = "UPDATE fakeRun SET fakeRun.label = '%s' WHERE fake_id = %" PRId64;
+    if (!p_psDBRunQuery(config->dbh, query, label, fake_id)) {
+        psError(PS_ERR_UNKNOWN, false,
+                "failed to change state for fake_id %" PRId64, fake_id);
+        return false;
+    }
+
+    return true;
+}
+
+
+bool pxfakeRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    // note label == NULL should be explicitly allowed
+
+    psString query = psStringCopy("UPDATE fakeRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET fakeRun.label = '%s'");
+
+    if (where) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query, label)) {
+        psFree(query);
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psFree(query);
+
+    return true;
+}
+
+
+psS64 pxfakeQueueByCamID(pxConfig *config,
+                    psS64 cam_id,
+                    char *workdir,
+                    char *label,
+                    char *reduction,
+                    char *expgroup,
+                    char *dvodb,
+                    char *tess_id,
+                    char *end_stage)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psTrace("pxtool", PS_LOG_INFO, "attemping to queue cam_id: %"PRId64, cam_id);
+
+    // load the SQL to enqueue our exp_ids from disk once
+    static psString query = NULL;
+    if (!query) {
+        query = pxDataGet("faketool_queue_cam_id.sql");
+        psMemSetPersistent(query, true);
+        if (!query) {
+            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+            return false;
+        }
+    }
+
+    // queue the exp
+    // XXX chip_id is being cast here work around psS64 have a different type
+    // different on 32/64
+    if (!p_psDBRunQuery(config->dbh, query,
+                "run", // state
+                workdir  ? workdir  : "NULL",
+                label    ? label    : "NULL",
+                reduction? reduction: "NULL",
+                expgroup ? expgroup : "NULL",
+                dvodb    ? dvodb    : "NULL",
+                tess_id  ? tess_id  : "NULL",
+                end_stage ? end_stage : "NULL",
+                (long long)cam_id
+    )) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // just to be safe, we should have changed at least one row
+    if (psDBAffectedRows(config->dbh) != 1) {
+        psError(PS_ERR_UNKNOWN, false,
+                "should have changed just one row");
+        return false;
+    }
+
+    return psDBLastInsertID(config->dbh);
+}
Index: branches/cleanup/ippTools/src/pxfake.h
===================================================================
--- branches/cleanup/ippTools/src/pxfake.h	(revision 18076)
+++ branches/cleanup/ippTools/src/pxfake.h	(revision 18076)
@@ -0,0 +1,44 @@
+/*
+ * pxfake.h
+ *
+ * Copyright (C) 2007-2008  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PXFAKE_H
+#define PXFAKE_H 1
+
+#include <pslib.h>
+
+#include "pxtools.h"
+
+bool pxfakeRunSetState(pxConfig *config, psS64 fake_id, const char *state);
+bool pxfakeRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state);
+bool pxfakeRunSetLabel(pxConfig *config, psS64 fake_id, const char *label);
+bool pxfakeRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
+
+
+psS64 pxfakeQueueByCamID(pxConfig *config,
+                    psS64 cam_id,
+                    char *workdir,
+                    char *label,
+                    char *reduction,
+                    char *expgroup,
+                    char *dvodb,
+                    char *tess_id,
+                    char *end_stage);
+
+
+#endif // PXFAKE_H
Index: branches/cleanup/ippTools/src/pxinject.c
===================================================================
--- branches/cleanup/ippTools/src/pxinject.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pxinject.c	(revision 18076)
@@ -91,9 +91,9 @@
 
     if (!newExpInsert(config->dbh,
-                0x0, // exp_id
+                0x0,    // exp_id
                 tmp_exp_name,
                 tmp_camera,
                 tmp_telescope,
-                "reg", // state
+                "reg",  // state
                 workdir,
                 "dirty",
@@ -101,6 +101,7 @@
                 dvodb,
                 tess_id,
-            end_stage,
-              label
+                end_stage,
+                label,
+                NULL    // epoch
             )
         ) {
@@ -141,5 +142,5 @@
 
     // insert with error flag state set to 0 (no errors)
-    if (!newImfileInsert(config->dbh, (psS64)atoll(exp_id), tmp_class_id, uri)) {
+    if (!newImfileInsert(config->dbh, (psS64)atoll(exp_id), tmp_class_id, uri, NULL)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
Index: branches/cleanup/ippTools/src/pxtools.h
===================================================================
--- branches/cleanup/ippTools/src/pxtools.h	(revision 17863)
+++ branches/cleanup/ippTools/src/pxtools.h	(revision 18076)
@@ -28,13 +28,16 @@
 #include <ippdb.h>
 
+#include "pxconfig.h"
 #include "pxtoolsErrorCodes.h"
+
+#include "pxcam.h"
+#include "pxchip.h"
+#include "pxdata.h"
+#include "pxfake.h"
+#include "pxwarp.h"
 #include "pxio.h"
-#include "pxdata.h"
+#include "pxregister.h"
 #include "pxtag.h"
-#include "pxregister.h"
-#include "pxchip.h"
-#include "pxcam.h"
 #include "pxtree.h"
-#include "pxconfig.h"
 
 # define MAX_ROWS 10e9
Index: branches/cleanup/ippTools/src/pxwarp.c
===================================================================
--- branches/cleanup/ippTools/src/pxwarp.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pxwarp.c	(revision 18076)
@@ -135,6 +135,6 @@
 
 
-bool pxwarpQueueByCamID(pxConfig *config,
-                    psS64 cam_id,
+bool pxwarpQueueByFakeID(pxConfig *config,
+                    psS64 fake_id,
                     char *workdir,
                     char *label,
@@ -148,5 +148,5 @@
     if (!warpRunInsert(config->dbh,
         0,          // ID
-        cam_id,
+        fake_id,
         "warp",     // mode
         "run",      // state
Index: branches/cleanup/ippTools/src/pxwarp.h
===================================================================
--- branches/cleanup/ippTools/src/pxwarp.h	(revision 17863)
+++ branches/cleanup/ippTools/src/pxwarp.h	(revision 18076)
@@ -30,6 +30,6 @@
 bool pxwarpRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label);
 
-bool pxwarpQueueByCamID(pxConfig *config,
-                    psS64 cam_id,
+bool pxwarpQueueByFakeID(pxConfig *config,
+                    psS64 fake_id,
                     char *workdir,
                     char *label,
Index: branches/cleanup/ippTools/src/pzgetexp.c
===================================================================
--- branches/cleanup/ippTools/src/pzgetexp.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pzgetexp.c	(revision 18076)
@@ -192,6 +192,7 @@
             "   SElECT"
             "       incoming.*,"
-            "       NULL,"
-            "       0"
+            "       NULL,"  // imfiles
+            "       0,"     // fault
+            "       NULL"   // epoch
             "   FROM incoming"
             "   LEFT JOIN summitExp"
Index: branches/cleanup/ippTools/src/pzgetimfiles.c
===================================================================
--- branches/cleanup/ippTools/src/pzgetimfiles.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pzgetimfiles.c	(revision 18076)
@@ -250,5 +250,6 @@
             "       incoming.class,"
             "       incoming.class_id,"
-            "       incoming.uri"
+            "       incoming.uri,"
+            "       NULL"       // epoch
             "   FROM incoming";
         if (!p_psDBRunQuery(config->dbh, query)) {
@@ -307,5 +308,6 @@
             "       incoming.camera,"
             "       incoming.telescope,"
-            "       \"run\""
+            "       \"run\","    // state
+            "       NULL"
             "   FROM incoming"
             "   LEFT JOIN pzDownloadExp"
Index: branches/cleanup/ippTools/src/pztool.c
===================================================================
--- branches/cleanup/ippTools/src/pztool.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pztool.c	(revision 18076)
@@ -111,5 +111,6 @@
             camera,
             telescope,
-            uri
+            uri,
+            NULL  // epoch
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -370,5 +371,6 @@
             class_id,
             uri,
-            code
+            code,
+            NULL    // epoch
     )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -484,4 +486,10 @@
 
         pzDownloadExpRow *doneExp = pzDownloadExpObjectFromMetadata(row);
+        if (!doneExp) {
+            psError(PS_ERR_UNKNOWN, false, "pzDownloadExpObjectFromMetadata() failed");
+            psFree(doneExp);
+            psFree(output);
+            return false;
+        }
 
         if (!newExpInsert(config->dbh,
@@ -497,5 +505,6 @@
                     tess_id,            // tess_id
                     end_stage,          // end_stage
-                   label
+                    label,
+                    NULL                // epoch
                 )
         ) {
@@ -515,5 +524,6 @@
                 "       %" PRId64 "," // exp_id
                 "       pzDownloadImfile.class_id," // tmp_class_id
-                "       pzDownloadImfile.uri" // uri
+                "       pzDownloadImfile.uri," // uri
+                "       NULL" // epoch
                 "   FROM pzDownloadImfile"
                 "   WHERE"
Index: branches/cleanup/ippTools/src/regtool.c
===================================================================
--- branches/cleanup/ippTools/src/regtool.c	(revision 17863)
+++ branches/cleanup/ippTools/src/regtool.c	(revision 18076)
@@ -280,5 +280,6 @@
         object,
         hostname,
-        code
+        code,
+        NULL
     )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -630,6 +631,11 @@
     psMetadata *row = output->data[0];
     // convert metadata into a newExp object
+    psMetadataConfigPrint(stdout, row);
     newExpRow *newExp = newExpObjectFromMetadata(row);
     psFree(output);
+    if (!newExp) {
+        psError(PS_ERR_UNKNOWN, false, "this should not happen");
+        return false;
+    }
 
     // carry through these values
@@ -700,5 +706,6 @@
         0.0,
         hostname,
-        code
+        code,
+        NULL
     )) {
         // rollback
Index: branches/cleanup/ippTools/src/warptool.c
===================================================================
--- branches/cleanup/ippTools/src/warptool.c	(revision 17863)
+++ branches/cleanup/ippTools/src/warptool.c	(revision 18076)
@@ -111,5 +111,5 @@
 
     // required options
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", true, false);
+    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", true, false);
     PXOPT_LOOKUP_STR(mode, config->args, "-mode", true, false);
     // check mode
@@ -133,5 +133,5 @@
     warpRunRow *warpRun = warpRunRowAlloc(
             0,          // ID
-            (psS64)atoll(cam_id),
+            (psS64)atoll(fake_id),
             mode,
             "run",      // state
@@ -176,5 +176,5 @@
 
     PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", false, false);
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", false, false);
+    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", false, false);
     PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
@@ -190,8 +190,8 @@
     }
 
-    // convert cam_id into a psS64
-    if (cam_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "cam_id", 0, "==", (psS64)atoll(cam_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");
+    // convert fake_id into a psS64
+    if (fake_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "fake_id", 0, "==", (psS64)atoll(fake_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id");
             psFree(where);
             return false;
@@ -526,5 +526,4 @@
     PXOPT_LOOKUP_STR(mapfile, config->args, "-mapfile", false, false);
     PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", false, false);
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", false, false);
     PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
 
@@ -544,5 +543,11 @@
         }
     } else {
-        warpSkyCellMapInsert(config->dbh, (psS64)atoll(warp_id), NULL, NULL, 0, NULL, code);
+        warpSkyCellMapInsert(config->dbh,
+            (psS64)atoll(warp_id),
+            NULL,   // skycell_id
+            NULL,   // tess_id
+            NULL,   // class_id
+            code    // fault
+        );
     }
 
@@ -1029,5 +1034,5 @@
 
     PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", false, false);
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", false, false);
+    PXOPT_LOOKUP_STR(fake_id, config->args, "-fake_id", false, false);
     PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
@@ -1046,8 +1051,8 @@
     PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "==");
 
-    // convert cam_id into a psS64
-    if (cam_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "camRun.cam_id", 0, "==", (psS64)atoll(cam_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");
+    // convert fake_id into a psS64
+    if (fake_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "fakeRun.fake_id", 0, "==", (psS64)atoll(fake_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id");
             psFree(where);
             return false;
Index: branches/cleanup/ippTools/src/warptoolConfig.c
===================================================================
--- branches/cleanup/ippTools/src/warptoolConfig.c	(revision 17863)
+++ branches/cleanup/ippTools/src/warptoolConfig.c	(revision 18076)
@@ -49,5 +49,5 @@
     // -definerun
     psMetadata *definerunArgs = psMetadataAlloc();
-    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-cam_id", 0,
+    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-fake_id", 0,
             "define camtool ID (required)", NULL);
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-mode", 0,
@@ -72,10 +72,10 @@
     // -updaterun
     psMetadata *updaterunArgs = psMetadataAlloc();
-    // XXX need to allow multiple cam_ids
+    // XXX need to allow multiple fake_ids
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-warp_id", 0,
             "search by warptool ID", NULL);
-    // XXX need to allow multiple cam_ids
-    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-cam_id",  0,
-            "search by cam_id", NULL);
+    // XXX need to allow multiple fake_ids
+    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-fake_id",  0,
+            "search by fake_id", NULL);
     // XXX need to allow multiple chip_ids
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-chip_id",  0,
@@ -176,5 +176,5 @@
     psMetadataAddStr(expArgs, PS_LIST_TAIL, "-warp_id", 0,
             "search by warptool ID", NULL);
-    psMetadataAddStr(expArgs, PS_LIST_TAIL, "-cam_id", 0,
+    psMetadataAddStr(expArgs, PS_LIST_TAIL, "-fake_id", 0,
             "search by camtool ID", NULL);
     psMetadataAddU64(expArgs, PS_LIST_TAIL, "-limit",  0,
@@ -187,5 +187,5 @@
     psMetadataAddStr(imfileArgs, PS_LIST_TAIL, "-warp_id", 0,
             "search by warptool ID", NULL);
-    psMetadataAddStr(imfileArgs, PS_LIST_TAIL, "-cam_id", 0,
+    psMetadataAddStr(imfileArgs, PS_LIST_TAIL, "-fake_id", 0,
             "search by camtool ID", NULL);
     psMetadataAddU64(imfileArgs, PS_LIST_TAIL, "-limit",  0,
@@ -279,5 +279,5 @@
     psMetadataAddStr(warpedArgs, PS_LIST_TAIL, "-exp_id", 0,
             "define exposure tag", NULL);
-    psMetadataAddStr(warpedArgs, PS_LIST_TAIL, "-cam_id", 0,
+    psMetadataAddStr(warpedArgs, PS_LIST_TAIL, "-fake_id", 0,
             "define phase 3 version of exposure tag", NULL);
     psMetadataAddU64(warpedArgs, PS_LIST_TAIL, "-limit",  0,
@@ -288,5 +288,5 @@
     // -revertwarped
     psMetadata *revertwarpedArgs = psMetadataAlloc();
-    // XXX need to allow multiple cam_ids
+    // XXX need to allow multiple fake_ids
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-warp_id", 0,
             "search by warptool ID", NULL);
@@ -295,7 +295,7 @@
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-tess_id",  0,
             "searcy by tessellation ID", NULL);
-    // XXX need to allow multiple cam_ids
-    psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-cam_id",  0,
-            "search by cam_id", NULL);
+    // XXX need to allow multiple fake_ids
+    psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-fake_id",  0,
+            "search by fake_id", NULL);
     // XXX need to allow multiple chip_ids
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-chip_id",  0,
