Index: trunk/ippTools/src/Makefile.am
===================================================================
--- trunk/ippTools/src/Makefile.am	(revision 11038)
+++ trunk/ippTools/src/Makefile.am	(revision 11047)
@@ -39,5 +39,4 @@
 	pxconfig.c \
 	pxfault.c \
-	pxframes.c \
 	pxtables.c \
 	pxtag.c
Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 11038)
+++ trunk/ippTools/src/dettool.c	(revision 11047)
@@ -77,5 +77,5 @@
 //static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
 //static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
-static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id, psS32 iteration);
+static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS32 det_id, psS32 iteration);
 static psArray *searchRawImfiles(pxConfig *config, psMetadata *where);
 static psS32 incrementIteration(pxConfig *config, const char *det_id);
@@ -161,8 +161,8 @@
      psString query = psStringCopy(
         "SELECT"
-        "   rawDetrendExp.*"
-        " FROM rawDetrendExp"
+        "   rawExp.*"
+        " FROM rawExp"
         " LEFT JOIN detInputExp"
-        "   ON rawDetrendExp.exp_tag = detInputExp.exp_tag"
+        "   ON rawExp.exp_tag = detInputExp.exp_tag"
         " WHERE"
         "    detInputExp.exp_tag IS NULL"
@@ -170,5 +170,5 @@
 
     if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawDetrendExp");
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
@@ -189,5 +189,5 @@
     if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending rawExp rows found");
         psFree(output);
         return true;
@@ -205,5 +205,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "rawDetrendExp", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -390,15 +390,15 @@
 
     // check that the specified exp_tags actually exist
-    psArray *detrendExps = rawDetrendExpSelectRowObjects(config->dbh, where, 0);
+    psArray *detrendExps = rawExpSelectRowObjects(config->dbh, where, 0);
     psFree(where);
     if (!detrendExps) {
-        psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found");
-        return false;
-    }
-
-    // we should have one rawDetrendExp row per exp_tag specified
+        psError(PS_ERR_UNKNOWN, false, "no rawExp rows found");
+        return false;
+    }
+
+    // we should have one rawExp row per exp_tag specified
     if (psListLength(item->data.list) != psArrayLength(detrendExps)) {
         psAbort(config->argv[0],
-    "an -exp_tag matched more then one rawDetrendExp (this should not happen");
+    "an -exp_tag matched more then one rawExp (this should not happen");
 
     }
@@ -433,5 +433,5 @@
     long det_id = psDBLastInsertID(config->dbh);
 
-    // create new detInputExp row(s) from the rawDetrendExp row(s)
+    // create new detInputExp row(s) from the rawExp row(s)
     psArray *inputExps = psArrayAllocEmpty(psArrayLength(detrendExps));
     for (long i = 0; i < psArrayLength(detrendExps); i++) {
@@ -803,8 +803,8 @@
     }
 
-    // search for rawDetrendExps with the specified options
-    psArray *detrendExps = rawDetrendExpSelectRowObjects(config->dbh, where, 0);
+    // search for rawExps with the specified options
+    psArray *detrendExps = rawExpSelectRowObjects(config->dbh, where, 0);
     psFree(where);
-    // make sure that we found at least one rawDetrendExp
+    // make sure that we found at least one rawExp
     if (!detrendExps) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -815,5 +815,5 @@
     }
     if (!psArrayLength(detrendExps)) {
-        psError(PS_ERR_UNKNOWN, true, "no rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, true, "no rawExp rows found");
         psFree(detrendExps);
         psFree(registered);
@@ -825,5 +825,5 @@
     if (pretend) {
         // negative simple so the default is true
-        if (!rawDetrendExpPrintObjects(stdout, detrendExps, !simple)) {
+        if (!rawExpPrintObjects(stdout, detrendExps, !simple)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print array");
             psFree(detrendExps);
@@ -874,5 +874,5 @@
     long det_id = psDBLastInsertID(config->dbh);
 
-    // create new detInputExp row(s) from the rawDetrendExp row(s)
+    // create new detInputExp row(s) from the rawExp row(s)
     psArray *inputExps = psArrayAllocEmpty(psArrayLength(detrendExps));
     for (long i = 0; i < psArrayLength(detrendExps); i++) {
@@ -1208,5 +1208,5 @@
         "       detResidExp.accept"
         "   FROM detResidExp"
-        "   JOIN rawDetrendExp"
+        "   JOIN rawExp"
         "       USING(exp_tag)"
         "   WHERE det_id = %d"
@@ -1214,5 +1214,5 @@
 
     if (time_filter->list->n) {
-        psString whereClause = psDBGenerateWhereConditionSQL(time_filter, "rawDetrendExp");
+        psString whereClause = psDBGenerateWhereConditionSQL(time_filter, "rawExp");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
@@ -1325,5 +1325,5 @@
 }
 
-static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id, psS32 iteration)
+static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS32 det_id, psS32 iteration)
 {
     PS_ASSERT_PTR_NON_NULL(rawExp, NULL);
@@ -1342,5 +1342,5 @@
 
     // select detInputExp.*
-    // select rawDetrendExp.*
+    // select rawExp.*
     // by:
     // exp_tag
@@ -1349,5 +1349,5 @@
         "SELECT DISTINCT *"
         " FROM detInputExp"
-        " JOIN rawDetrendExp"
+        " JOIN rawExp"
         " USING(exp_tag)"
         );
@@ -1373,5 +1373,5 @@
     if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending rawExp rows found");
         psFree(output);
         return true;
@@ -1409,9 +1409,9 @@
             "   detRun.det_type,"
             "   rawImfile.*,"
-            "   rawDetrendExp.camera"
+            "   rawExp.camera"
             " FROM rawImfile"
             " JOIN detInputExp"
             "   USING(exp_tag) "
-            " JOIN rawDetrendExp"
+            " JOIN rawExp"
             "   USING(exp_tag) "
             " JOIN detRun"
@@ -1494,10 +1494,10 @@
             "   detRun.det_type,"
             "   rawImfile.*,"
-            "   rawDetrendExp.camera"
+            "   rawExp.camera"
             " FROM detRun"
             " JOIN detInputExp"
             "    USING(det_id, iteration)"
-            " JOIN rawDetrendExp"
-            "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+            " JOIN rawExp"
+            "    ON detInputExp.exp_tag = rawExp.exp_tag"
             " JOIN rawImfile"
             "    ON detInputExp.exp_tag = rawImfile.exp_tag"
@@ -1582,5 +1582,5 @@
         detInputExpSelectRowObjects(config->dbh, where, 0);
     if (!detInputExp) {
-        psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no rawExp rows found");
         return NULL;
     }
@@ -1789,14 +1789,14 @@
         "    detRun.det_type,"
         "    detProcessedImfile.exp_tag,"
-        "    rawDetrendExp.camera,"
+        "    rawExp.camera,"
         "    detProcessedImfile.class_id,"
-        "    rawDetrendExp.imfiles"
+        "    rawExp.imfiles"
         " FROM detRun"
         " JOIN detInputExp"
         "   USING(det_id, iteration)"
-        " JOIN rawDetrendExp"
-        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "   ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN rawImfile"
-        "   ON rawDetrendExp.exp_tag = rawImfile.exp_tag"
+        "   ON rawExp.exp_tag = rawImfile.exp_tag"
         " LEFT JOIN detProcessedImfile"
         "   ON detRun.det_id = detProcessedImfile.det_id"
@@ -1813,8 +1813,8 @@
         "   AND detInputExp.include = 1"
         " GROUP BY"
-        "    rawDetrendExp.exp_tag,"
+        "    rawExp.exp_tag,"
         "    detRun.det_id"
         " HAVING"
-        "    COUNT(detProcessedImfile.class_id) = rawDetrendExp.imfiles"
+        "    COUNT(detProcessedImfile.class_id) = rawExp.imfiles"
         " ) AS detProcessedExp"
         );
@@ -1850,5 +1850,5 @@
     if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending rawExp rows found");
         psFree(output);
         return true;
@@ -1960,6 +1960,6 @@
         "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
-        " JOIN rawDetrendExp"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN detProcessedImfile"
         "    ON detInputExp.det_id = detProcessedImfile.det_id"
@@ -2001,5 +2001,5 @@
     if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending rawExp rows found");
         return true;
     }
@@ -2114,11 +2114,11 @@
         "    detRun.det_type,"
         "    detProcessedImfile.class_id,"
-        "    rawDetrendExp.camera"
+        "    rawExp.camera"
         " FROM detRun"
         " JOIN detInputExp"
         "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
-        " JOIN rawDetrendExp"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN rawImfile"
         "    ON detInputExp.exp_tag = rawImfile.exp_tag"
@@ -2271,5 +2271,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -2471,5 +2471,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -2517,6 +2517,6 @@
         "   detRun.det_type,"
         "   detRun.iteration,"
-        "   rawDetrendExp.camera,"
-        "   rawDetrendExp.imfiles,"
+        "   rawExp.camera,"
+        "   rawExp.imfiles,"
         "   detStackedImfile.class_id"
         " FROM detRun"
@@ -2524,6 +2524,6 @@
         "   ON detRun.det_id = detInputExp.det_id"
         "   AND detRun.iteration = detInputExp.iteration"
-        " JOIN rawDetrendExp"
-        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "   ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN detStackedImfile"
         "   ON detInputExp.det_id = detStackedImfile.det_id"
@@ -2540,8 +2540,8 @@
         "   AND detNormalizedStatImfile.class_id IS NULL"
         " GROUP BY"
-        "   rawDetrendExp.exp_tag,"
+        "   rawExp.exp_tag,"
         "   detRun.iteration,"
         "   detRun.det_id"
-        " HAVING MAX(rawDetrendExp.imfiles) = COUNT(detStackedImfile.class_id)"
+        " HAVING MAX(rawExp.imfiles) = COUNT(detStackedImfile.class_id)"
         ") as tonormalizedstat"
         );
@@ -2734,5 +2734,5 @@
         "SELECT DISTINCT"
         "   detRun.det_type,"
-        "   rawDetrendExp.camera,"
+        "   rawExp.camera,"
         "   detStackedImfile.uri,"
         "   detNormalizedStatImfile.*"
@@ -2742,6 +2742,6 @@
         " JOIN detInputExp"
         "   USING(det_id, iteration)"
-        " JOIN rawDetrendExp"
-        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "   ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN detNormalizedStatImfile"
         "   ON detStackedImfile.det_id = detNormalizedStatImfile.det_id"
@@ -2805,5 +2805,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -3064,14 +3064,14 @@
         "    detRun.iteration,"
         "    detRun.det_type,"
-        "    rawDetrendExp.camera,"
-        "    rawDetrendExp.telescope,"
-        "    rawDetrendExp.exp_type,"
-        "    rawDetrendExp.imfiles"
+        "    rawExp.camera,"
+        "    rawExp.telescope,"
+        "    rawExp.exp_type,"
+        "    rawExp.imfiles"
         " FROM detRun"
         " JOIN detInputExp"
         "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
-        " JOIN rawDetrendExp"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN detNormalizedImfile"
         "    ON detInputExp.det_id = detNormalizedImfile.det_id"
@@ -3227,14 +3227,14 @@
         "    detRun.iteration,"
         "    detRun.det_type,"
-        "    rawDetrendExp.camera,"
-        "    rawDetrendExp.telescope,"
-        "    rawDetrendExp.exp_type,"
-        "    rawDetrendExp.imfiles"
+        "    rawExp.camera,"
+        "    rawExp.telescope,"
+        "    rawExp.exp_type,"
+        "    rawExp.imfiles"
         " FROM detRun"
         " JOIN detInputExp"
         "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
-        " JOIN rawDetrendExp"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawExp"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag"
         " JOIN detNormalizedImfile"
         "    ON detInputExp.det_id = detNormalizedImfile.det_id"
@@ -3462,10 +3462,10 @@
         "   detProcessedImfile.uri,\n"
         "   detNormalizedImfile.uri AS det_uri,\n"
-        "   rawDetrendExp.camera\n"
+        "   rawExp.camera\n"
         " FROM detRun\n"
         " JOIN detInputExp\n"
         "   USING(det_id, iteration)\n"
-        " JOIN rawDetrendExp\n"
-        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        " JOIN rawExp\n"
+        "   ON detInputExp.exp_tag = rawExp.exp_tag\n"
         " JOIN detProcessedImfile\n"
         "   ON detRun.det_id = detProcessedImfile.det_id\n"
@@ -3497,10 +3497,10 @@
         "   rawImfile.uri,\n"
         "   'NULL' AS det_uri,\n"
-        "   rawDetrendExp.camera\n"
+        "   rawExp.camera\n"
         " FROM detRun\n"
         " JOIN detInputExp\n"
         "    USING(det_id, iteration)\n"
-        " JOIN rawDetrendExp\n"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        " JOIN rawExp\n"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag\n"
         " JOIN rawImfile\n"
         "    ON detInputExp.exp_tag = rawImfile.exp_tag\n"
@@ -3689,6 +3689,6 @@
         " JOIN detInputExp\n"
         "    USING(det_id, iteration)\n"
-        " JOIN rawDetrendExp\n"
-        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        " JOIN rawExp\n"
+        "    ON detInputExp.exp_tag = rawExp.exp_tag\n"
         " JOIN rawImfile\n"
         "    ON detInputExp.exp_tag = rawImfile.exp_tag\n"
@@ -4047,12 +4047,12 @@
         "       detInputExp.exp_tag,\n"
         "       detInputExp.include,\n"
-        "       rawDetrendExp.imfiles,\n"
-        "       rawDetrendExp.camera,\n"
+        "       rawExp.imfiles,\n"
+        "       rawExp.camera,\n"
         "       detResidImfile.class_id\n"
         "   FROM detRun\n"
         "   JOIN detInputExp\n"
         "       USING(det_id, iteration)\n"
-        "   JOIN rawDetrendExp\n"
-        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        "   JOIN rawExp\n"
+        "       ON detInputExp.exp_tag = rawExp.exp_tag\n"
         "   JOIN detResidImfile\n"
         "       ON detRun.det_id = detResidImfile.det_id\n"
@@ -4073,5 +4073,5 @@
         "       detRun.det_id\n"
         "   HAVING\n"
-        "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)\n"
+        "       rawExp.imfiles = COUNT(detResidImfile.class_id)\n"
         " ) AS toresidexp\n"
         );
@@ -4171,10 +4171,10 @@
         "       detInputExp.exp_tag,"
         "       detInputExp.include,"
-        "       rawDetrendExp.imfiles"
+        "       rawExp.imfiles"
         "   FROM detRun"
         "   JOIN detInputExp"
         "       USING(det_id, iteration)"
-        "   JOIN rawDetrendExp"
-        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        "   JOIN rawExp"
+        "       ON detInputExp.exp_tag = rawExp.exp_tag"
         "   JOIN detResidImfile"
         "       ON detRun.det_id = detResidImfile.det_id"
@@ -4195,5 +4195,5 @@
         "       detRun.det_id"
         "   HAVING"
-        "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
+        "       rawExp.imfiles = COUNT(detResidImfile.class_id)"
         " ) AS toresidexp"
         );
@@ -4528,10 +4528,10 @@
         "       detRun.mode,\n"
         "       detInputExp.exp_tag,\n"
-        "       rawDetrendExp.camera\n"
+        "       rawExp.camera\n"
         "   FROM detRun\n"
         "   JOIN detInputExp\n"
         "       USING(det_id, iteration)\n"
-        "   JOIN rawDetrendExp\n"
-        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        "   JOIN rawExp\n"
+        "       ON detInputExp.exp_tag = rawExp.exp_tag\n"
         "   LEFT JOIN detResidExp\n"
         "       ON detRun.det_id = detResidExp.det_id\n"
@@ -4802,6 +4802,6 @@
         "       ON detRun.det_id = detInputExp.det_id\n"
         "       AND detRun.iteration = detInputExp.iteration\n"
-        "   LEFT JOIN rawDetrendExp\n"
-        "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag\n"
+        "   LEFT JOIN rawExp\n"
+        "       ON detInputExp.exp_tag = rawExp.exp_tag\n"
         "   LEFT JOIN detResidExp\n"
         "       ON detRun.det_id = detResidExp.det_id\n"
@@ -5305,5 +5305,5 @@
     psFree(where);
     if (!detrendExps) {
-        psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found");
+        psError(PS_ERR_UNKNOWN, false, "no rawExp rows found");
         psFree(where);
         return false;
Index: trunk/ippTools/src/pxframes.c
===================================================================
--- trunk/ippTools/src/pxframes.c	(revision 11038)
+++ trunk/ippTools/src/pxframes.c	(revision 11047)
@@ -57,5 +57,5 @@
 //PX_FRAME_ALLOC(newFrame, newExp);
 //PX_FRAME_ALLOC(rawDetrendFrame, rawDetrendExp);
-PX_FRAME_ALLOC(rawScienceFrame, rawScienceExp);
+//PX_FRAME_ALLOC(rawScienceFrame, rawScienceExp);
 //PX_FRAME_ALLOC(p2PendingFrame, p2PendingExp);
 
@@ -92,5 +92,5 @@
 
 //PX_FRAME_PRINT(newFrame, newImfile);
-PX_FRAME_PRINT(rawScienceFrame, rawImfile);
+//PX_FRAME_PRINT(rawScienceFrame, rawImfile);
 //PX_FRAME_PRINT(rawDetrendFrame, rawImfile);
 //PX_FRAME_PRINT(p2PendingFrame, p2PendingImfile);
@@ -145,5 +145,5 @@
 //PX_FRAME_SEARCH(newFrame, newExp, newImfile);
 //PX_FRAME_SEARCH(rawDetrendFrame, rawDetrendExp, rawImfile, exp_tag);
-PX_FRAME_SEARCH(rawScienceFrame, rawScienceExp, rawImfile, exp_tag);
+//PX_FRAME_SEARCH(rawScienceFrame, rawScienceExp, rawImfile, exp_tag);
 //PX_FRAME_SEARCH(p2PendingFrame, p2PendingExp, p2PendingImfile, exp_tag);
 
Index: trunk/ippTools/src/pxinject.c
===================================================================
--- trunk/ippTools/src/pxinject.c	(revision 11038)
+++ trunk/ippTools/src/pxinject.c	(revision 11047)
@@ -148,6 +148,5 @@
                 dateobs,
                 exp_type,
-                imfiles,
-                0           // error flags
+                imfiles
             )
         ) {
@@ -232,5 +231,5 @@
 
     // insert with error flag state set to 0 (no errors)
-    if (!newImfileInsert(config->dbh, exp_tag, class, class_id, uri, 0)) {
+    if (!newImfileInsert(config->dbh, exp_tag, class, class_id, uri)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
Index: trunk/ippTools/src/pxtables.c
===================================================================
--- trunk/ippTools/src/pxtables.c	(revision 11038)
+++ trunk/ippTools/src/pxtables.c	(revision 11047)
@@ -57,7 +57,6 @@
     CREATE_TABLE(newExpCreateTable);
     CREATE_TABLE(newImfileCreateTable);
-    CREATE_TABLE(rawScienceExpCreateTable);
+    CREATE_TABLE(rawExpCreateTable);
     CREATE_TABLE(rawImfileCreateTable);
-    CREATE_TABLE(rawDetrendExpCreateTable);
     CREATE_TABLE(p1PendingExpCreateTable);
     CREATE_TABLE(p2PendingExpCreateTable);
@@ -130,7 +129,6 @@
     DROP_TABLE(newExpDropTable);
     DROP_TABLE(newImfileDropTable);
-    DROP_TABLE(rawScienceExpDropTable);
+    DROP_TABLE(rawExpDropTable);
     DROP_TABLE(rawImfileDropTable);
-    DROP_TABLE(rawDetrendExpDropTable);
     DROP_TABLE(p1PendingExpDropTable);
     DROP_TABLE(p2PendingExpDropTable);
Index: trunk/ippTools/src/pxtools.h
===================================================================
--- trunk/ippTools/src/pxtools.h	(revision 11038)
+++ trunk/ippTools/src/pxtools.h	(revision 11047)
@@ -49,18 +49,4 @@
 bool pxDeleteTables (pxConfig *config);
 
-typedef struct {
-    rawScienceExpRow *exposure;
-    psArray *images;
-} rawScienceFrame;
-
-rawScienceFrame *rawScienceFrameAlloc(
-    rawScienceExpRow *exposure,
-    psArray *images
-);
-
-bool rawScienceFramePrint(FILE *stream, pxConfig *config, psArray *frames);
-psArray *rawScienceFrameSearch(pxConfig *config);
-bool rawScienceFrameInsert(pxConfig *config, rawScienceFrame *frame);
-
 bool pxSetFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS8 code);
 
Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 11038)
+++ trunk/ippTools/src/regtool.c	(revision 11047)
@@ -27,16 +27,20 @@
 #include "p0tool.h"
 
+static bool pendingimfileMode(pxConfig *config);
+static bool addprocessedimfileMode(pxConfig *config);
+static bool processedimfileMode(pxConfig *config);
+static bool updateprocessedimfileMode(pxConfig *config);
+
 static bool pendingexpMode(pxConfig *config);
-static bool pendingimfileMode(pxConfig *config);
-static bool updateexpMode(pxConfig *config);
-static bool updateimfileMode(pxConfig *config);
-static bool faultexpMode(pxConfig *config);
-static bool faultimfileMode(pxConfig *config);
-static bool rawimfileMode(pxConfig *config);
+static bool addprocessedexpMode(pxConfig *config);
+static bool processedexpMode(pxConfig *config);
+static bool updateprocessedexpMode(pxConfig *config);
+
+
 // static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp);
 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *newExp);
 static p2PendingImfileRow *rawImfileToP2PendingImfile(pxConfig *config, rawImfileRow *rawImfile);
-static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp);
-static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp);
+
+static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp);
 static rawImfileRow *newToRawImfile(pxConfig *config, newImfileRow *exp);
 //static psU32 mapCodeStrToInt(const char *codeStr);
@@ -59,11 +63,12 @@
 
     switch (config->mode) {
-        MODECASE(P0TOOL_MODE_PENDINGEXP,        pendingexpMode);
-        MODECASE(P0TOOL_MODE_PENDINGIMFILE,     pendingimfileMode);
-        MODECASE(P0TOOL_MODE_UPDATEEXP,         updateexpMode);
-        MODECASE(P0TOOL_MODE_FAULTEXP,          faultexpMode);
-        MODECASE(P0TOOL_MODE_UPDATEIMFILE,      updateimfileMode);
-        MODECASE(P0TOOL_MODE_FAULTIMFILE,       faultimfileMode);
-        MODECASE(P0TOOL_MODE_RAWIMFILE,         rawimfileMode);
+        MODECASE(P0TOOL_MODE_PENDINGIMFILE,         pendingimfileMode);
+        MODECASE(P0TOOL_MODE_ADDPROCESSEDIMFILE,    addprocessedimfileMode);
+        MODECASE(P0TOOL_MODE_PROCESSEDIMFILE,       processedimfileMode);
+        MODECASE(P0TOOL_MODE_UPDATEPROCESSEDIMFILE, updateprocessedimfileMode);
+        MODECASE(P0TOOL_MODE_PENDINGEXP,            pendingexpMode);
+        MODECASE(P0TOOL_MODE_ADDPROCESSEDEXP,       addprocessedexpMode);
+        MODECASE(P0TOOL_MODE_PROCESSEDEXP,          processedexpMode);
+        MODECASE(P0TOOL_MODE_UPDATEPROCESSEDEXP,    updateprocessedexpMode);
         default:
             psAbort(argv[0], "invalid option (this should not happen)");
@@ -88,5 +93,6 @@
 }
 
-static bool pendingexpMode(pxConfig *config)
+
+static bool pendingimfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -99,4 +105,238 @@
     }
 
+    // select newImfiles that:
+    // exp_tag is in newExp
+    // don't have their exp_tag in rawExp 
+    // XXX having the same exp_tag in newExp and raw*Exp is probably an error
+    // that should be checked for
+
+    psString query = psStringCopy(
+        "SELECT\n"
+        "   newImfile.*\n"
+        " FROM newImfile\n"
+        " LEFT JOIN newExp\n"
+        "   USING(exp_tag)\n"
+        " LEFT JOIN rawExp\n"
+        "   USING(exp_tag)\n"
+        " WHERE\n"
+        "   newExp.exp_tag is NOT NULL\n"
+        "   AND rawExp.exp_tag IS NULL\n"
+    );
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psFree(output);
+        return true;
+    }
+
+    bool simple = false;
+    simple = psMetadataLookupBool(&status, config->args, "-simple");
+    if (!status) {
+	psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -simple");
+	return false;
+    }
+
+    // negate simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "p0PendingImfile", !simple)) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
+static bool addprocessedimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // XXX search by the whole frame some imfiles without a newExp don't get
+    // processed -- this may not be the correct thing to do
+    psString query = psStringCopy(
+        "SELECT\n"
+        "   *\n"
+        " FROM\n"
+        "   (SELECT newImfile.* FROM newImfile\n"
+        "       LEFT JOIN newExp USING(exp_tag)\n"
+        "       LEFT JOIN rawExp USING(exp_tag)\n"
+        "       WHERE newExp.exp_tag IS NOT NULL\n"
+        "       AND rawExp.exp_tag IS NULL) as Foo\n"
+        ); // WHERE class is generated from exp_tag, class, & class_id
+
+    {
+        // build a query to search by exp_tag, class, class_id
+        psMetadata *where = psMetadataAlloc();
+        bool status = false;
+        psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
+            psFree(query);
+            return false;
+        }
+        if (exp_tag) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag", 0, "==", exp_tag)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
+                psFree(where);
+                psFree(query);
+                return false;
+            }
+        }
+        psString class = psMetadataLookupStr(&status, config->args, "-class");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class");
+            psFree(query);
+            return false;
+        }
+        if (class) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class", 0, "==", class)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item class");
+                psFree(where);
+                psFree(query);
+                return false;
+            }
+        }
+        psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
+            psFree(query);
+            return false;
+        }
+        if (class_id) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+                psFree(where);
+                psFree(query);
+                return false;
+            }
+        }
+
+        // there's not
+        psString whereClaus = psDBGenerateWhereSQL(where, NULL);
+        psFree(where);
+        if (whereClaus) {
+            psStringAppend(&query, " %s", whereClaus);
+            psFree(whereClaus);
+        }
+    }
+
+    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)) {
+        // XXX check psError here
+        psError(PS_ERR_UNKNOWN, false, "no pending newImfile rows found");
+        psFree(output);
+        return false;
+    }
+
+    // insert 'newImfile's into rawImfile
+    if (psArrayLength(output) > 0) {
+        // start a transaction so we don't end up half of the imfiles we were
+        // trying to update uninserted
+        if (!psDBTransaction(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(output);
+            return false;
+        }
+
+        for (long i = 0; i < psArrayLength(output); i++) {
+            // convert newImfile metadata -> newImfile object
+            newImfileRow *object = newImfileObjectFromMetadata(output->data[i]);
+            // convert newImfile object -> rawImfile object
+            rawImfileRow *imfile = newToRawImfile(config, object); 
+            if (!imfile) {
+                // rollback
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                psError(PS_ERR_UNKNOWN, false, "failed to create a new rawImfile row");
+                psFree(object);
+                psFree(output);
+                return false;
+            }
+            // insert the rawImfile object into the database
+            if (!rawImfileInsertObject(config->dbh, imfile)) {
+                // rollback
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database");
+                psFree(imfile);
+                psFree(object);
+                psFree(output);
+                return false;
+            }
+            psFree(imfile);
+            // remove the neImfile object from the database
+            if (!newImfileDeleteObject(config->dbh, object)) {
+                // rollback
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                psError(PS_ERR_UNKNOWN, false, "failed to delete row from the database");
+                psFree(object);
+                psFree(output);
+                return false;
+            }
+            psFree(object);
+        }
+
+        // point of no return for rawImfile
+        if (!psDBCommit(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(output);
+            return false;
+        }
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
+static bool processedimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
+        return false;
+    }
+
     bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     if (!status) {
@@ -105,7 +345,109 @@
     }
 
+    // find all rawImfiles matching the default query
+    psString query = psStringCopy( 
+        "SELECT\n"
+        "   *\n"
+        " FROM rawImfile\n"
+        " WHERE rawImfile.exp_tag is NOT NULL\n" //bogus conditional so there is a where clause to append to
+    );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawImfile");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (faulted) {
+        // list only faulted rows
+        psStringAppend(&query, " %s", "AND rawImfile.fault != 0");
+    } else {
+        // don't list faulted rows
+        psStringAppend(&query, " %s", "AND rawImfile.fault = 0");
+    }
+
+    // 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)) {
+        psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found");
+        psFree(output);
+        return true;
+    }
+
+    bool simple = false;
+    {
+        bool status = false;
+        simple = psMetadataLookupBool(&status, config->args, "-simple");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
+            return false;
+        }
+    }
+
+    if (psArrayLength(output)) {
+        // negative simple so the default is true
+        if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
+static bool updateprocessedimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
+        return false;
+    }
+
+    if (!pxSetFaultCode(config->dbh, "rawImfile", config->where, code)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
+        return false;
+    }
+
+    return true;
+}
+
+
+static bool pendingexpMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
+        return false;
+    }
+
     // return only exps that:
-    // are not in rawScienceExp 
-    // are not in rawDetrendExp 
+    // are not in rawExp 
     // have ALL of their imfiles in rawImfile (by count)
     // and have no associated imfiles left in newImfile
@@ -117,24 +459,13 @@
         " LEFT JOIN newImfile"
         "   USING(exp_tag)"
-        " LEFT JOIN rawScienceExp"
-        "   USING(exp_tag)"
-        " LEFT JOIN rawDetrendExp"
+        " LEFT JOIN rawExp"
         "   USING(exp_tag)"
         " WHERE"
         "   newImfile.exp_tag IS NULL"
-        "   AND rawScienceExp.exp_tag IS NULL"
-        "   AND rawDetrendExp.exp_tag IS NULL"
+        "   AND rawExp.exp_tag IS NULL"
         "   AND newExp.imfiles ="
         "   (SELECT COUNT(exp_tag) FROM rawImfile"
         "       WHERE rawImfile.exp_tag = newExp.exp_tag)"
     );
-
-    if (faulted) {
-        // list only faulted rows
-        psStringAppend(&query, " %s", "AND newExp.fault != 0");
-    } else {
-        // don't list faulted rows
-        psStringAppend(&query, " %s", "AND newExp.fault = 0");
-    }
 
     // treat limit == 0 as "no limit"
@@ -183,135 +514,11 @@
 }
 
-static bool pendingimfileMode(pxConfig *config)
+
+static bool addprocessedexpMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
-
-    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -faulted");
-        return false;
-    }
-
-    // select newImfiles that:
-    // exp_tag is in newExp
-    // don't have their exp_tag in rawScienceExp 
-    // don't have their exp_tag in rawDetrendExp
-    // XXX having the same exp_tag in newExp and raw*Exp is probably an error
-    // that should be checked for
-
-    psString query = psStringCopy(
-        "SELECT newImfile.* FROM newImfile"
-        " LEFT JOIN newExp USING(exp_tag)"
-        " LEFT JOIN rawScienceExp USING(exp_tag)"
-        " LEFT JOIN rawDetrendExp USING (exp_tag)"
-        " WHERE newExp.exp_tag is NOT NULL"
-        " AND rawScienceExp.exp_tag IS NULL"
-        " AND rawDetrendExp.exp_tag IS NULL"
-    );
-
-    if (faulted) {
-        // list only faulted rows
-        psStringAppend(&query, " %s", "AND newImfile.fault != 0");
-    } else {
-        // don't list faulted rows
-        psStringAppend(&query, " %s", "AND newImfile.fault = 0");
-    }
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
-        psError(PXTOOLS_ERR_PROG, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
-        psError(PXTOOLS_ERR_PROG, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psFree(output);
-        return true;
-    }
-
-    bool simple = false;
-    simple = psMetadataLookupBool(&status, config->args, "-simple");
-    if (!status) {
-	psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -simple");
-	return false;
-    }
-
-    // negate simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "newImfile", !simple)) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-static bool faultexpMode(pxConfig *config)
-{
-    bool status = false;
-    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
-        return false;
-    }
-
-    if (!pxSetFaultCode(config->dbh, "newExp", config->where, code)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
-
-    return true;
-}
-
-static bool faultimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    bool status = false;
-    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
-        return false;
-    }
-
-    if (!pxSetFaultCode(config->dbh, "newImfile", config->where, code)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-        return false;
-    }
-
-    return true;
-}
-
-
-static bool updateexpMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
     // make sure that the exp_tag(s) are ready to be updated based on:
-    // exp_tag is not in rawScienceExp
-    // exp_tag is not in rawDetrendExp
+    // exp_tag is not in rawExp
     // exp_tag is not in newImfile
     // that the correct count of imfiles is in rawImfile
@@ -340,12 +547,10 @@
         " LEFT JOIN newImfile"
         "   USING(exp_tag)"
-        " LEFT JOIN rawScienceExp"
-        "   USING(exp_tag)"
-        " LEFT JOIN rawDetrendExp"
+        " LEFT JOIN rawExp"
         "   USING(exp_tag)"
         " WHERE"
         "   newExp.exp_tag IS NOT NULL"
         "   AND newImfile.exp_tag IS NULL"
-        "   AND rawScienceExp.exp_tag IS NULL"
+        "   AND rawExp.exp_tag IS NULL"
         "   AND newExp.imfiles ="
         "   (SELECT COUNT(exp_tag) FROM rawImfile"
@@ -369,7 +574,6 @@
     }
 
-
-    // start a transaction so we don't end up with an exp in
-    // rawScience/DetrendExp and in newExp
+    // start a transaction so we don't end up with an exp in both rawExp &
+    // newExp
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -378,67 +582,11 @@
     }
 
-    // if it's a detrend exp
-    if (detrend) {        
-        for (long i = 0; psArrayLength(output) > i; i++) {
-            psMetadata *row = output->data[i];
-            // convert metadata into a newExp object
-            newExpRow *newExp = newExpObjectFromMetadata(row);
-            // convert newExp object into a rawDetrendExp object
-            rawDetrendExpRow *rawExp = newToRawDetrendExp(config, newExp);
-            if (!rawExp) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawDetrendExp");
-                psFree(newExp);
-                psFree(output);
-                return false;
-            }
-            // insert the rawDetrendExp object into the database
-            if (!rawDetrendExpInsertObject(config->dbh, rawExp)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "database error");
-                psFree(rawExp);
-                psFree(newExp);
-                psFree(output);
-                return false;
-            }
-            psFree(rawExp);
-            // delete the newExp object from the database
-            if (!newExpDeleteObject(config->dbh, newExp)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "database error");
-                psFree(newExp);
-                psFree(output);
-                return false;
-            }
-            psFree(newExp);
-        }
-
-        psFree(output);
-
-        if (!psDBCommit(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            return false;
-        }
-
-        return true;
-    } 
-
-    // else
-    // it's a science exp
+    // insert the exp into rawExp
     for (long i = 0; psArrayLength(output) > i; i++) {
         psMetadata *row = output->data[i];
         // convert metadata into a newExp object
         newExpRow *newExp = newExpObjectFromMetadata(row);
-        // convert newExp object into a rawDetrendExp object
-        rawScienceExpRow *rawExp = newToRawScienceExp(config, newExp);
+        // convert newExp object into a rawExp object
+        rawExpRow *rawExp = newToRawExp(config, newExp);
         if (!rawExp) {
             // rollback
@@ -446,11 +594,12 @@
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawScienceExp");
+            psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawExp");
             psFree(newExp);
             psFree(output);
             return false;
         }
-        // insert the rawDetrendExp object into the database
-        if (!rawScienceExpInsertObject(config->dbh, rawExp)) {
+
+        // insert the rawExp object into the database
+        if (!rawExpInsertObject(config->dbh, rawExp)) {
             // rollback
             if (!psDBRollback(config->dbh)) {
@@ -464,4 +613,5 @@
         }
         psFree(rawExp);
+
         // delete the newExp object from the database
         if (!newExpDeleteObject(config->dbh, newExp)) {
@@ -475,4 +625,12 @@
             return false;
         }
+
+        // if this is a detrend image don't put it in the p2 queue (and we're
+        // done)
+        if (detrend) {
+            psFree(newExp);
+            continue;
+        }
+
         // insert an entry into the p2PendingExp table
         p2PendingExpRow *p2PendingExp = newToP2PendingExp(config, newExp);
@@ -483,4 +641,5 @@
             return false;
         }
+
         // insert the p2PendingExp object into the database
         if (!p2PendingExpInsertObject(config->dbh, p2PendingExp)) {
@@ -496,4 +655,5 @@
         }
         psFree(p2PendingExp);
+
         // find all of the rawImfiles associated with the p2PendingExp object
         psArray *rawImfiles = NULL;
@@ -570,80 +730,54 @@
 }
 
-static bool updateimfileMode(pxConfig *config)
+
+static bool processedexpMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // XXX search by the whole frame some imfiles without a newExp don't get
-    // processed -- this may not be the correct thing to do
-    psString query = psStringCopy(
-        "SELECT * FROM"
-            " (SELECT newImfile.* FROM newImfile"
-                " LEFT JOIN newExp USING(exp_tag)"
-                " LEFT JOIN rawScienceExp USING(exp_tag)"
-                " LEFT JOIN rawDetrendExp USING (exp_tag)"
-                " WHERE newExp.exp_tag IS NOT NULL"
-                " AND rawScienceExp.exp_tag IS NULL"
-                " AND rawDetrendExp.exp_tag IS NULL) AS foo"
-        ); // WHERE class is generated from exp_tag, class, & class_id
-
-    {
-        // build a query to search by exp_tag, class, class_id
-        psMetadata *where = psMetadataAlloc();
-        bool status = false;
-        psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
-            psFree(query);
-            return false;
-        }
-        if (exp_tag) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_tag", 0, "==", exp_tag)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
-                psFree(where);
-                psFree(query);
-                return false;
-            }
-        }
-        psString class = psMetadataLookupStr(&status, config->args, "-class");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class");
-            psFree(query);
-            return false;
-        }
-        if (class) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class", 0, "==", class)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item class");
-                psFree(where);
-                psFree(query);
-                return false;
-            }
-        }
-        psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-            psFree(query);
-            return false;
-        }
-        if (class_id) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-                psFree(where);
-                psFree(query);
-                return false;
-            }
-        }
-
-        // there's not
-        psString whereClaus = psDBGenerateWhereSQL(where, NULL);
-        psFree(where);
-        if (whereClaus) {
-            psStringAppend(&query, " %s", whereClaus);
-            psFree(whereClaus);
-        }
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
+    if (!status) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -faulted");
+        return false;
+    }
+
+    // find all rawImfiles matching the default query
+    psString query = psStringCopy( 
+        "SELECT\n"
+        "   *\n"
+        " FROM rawExp\n"
+        " WHERE\n"
+        "   rawExp.exp_tag IS NOT NULL\n" // bogus where clause
+    );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "rawExp");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (faulted) {
+        // list only faulted rows
+        psStringAppend(&query, " %s", "AND rawExp.fault != 0");
+    } else {
+        // don't list faulted rows
+        psStringAppend(&query, " %s", "AND rawExp.fault = 0");
+    }
+
+    // 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;
     }
@@ -656,85 +790,9 @@
     }
     if (!psArrayLength(output)) {
-        // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending newImfile rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending rawExp rows found");
         psFree(output);
-        return false;
-    }
-
-    // insert 'newImfile's into rawImfile
-    if (psArrayLength(output) > 0) {
-        // start a transaction so we don't end up half of the imfiles we were
-        // trying to update uninserted
-        if (!psDBTransaction(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(output);
-            return false;
-        }
-
-        for (long i = 0; i < psArrayLength(output); i++) {
-            // convert newImfile metadata -> newImfile object
-            newImfileRow *object = newImfileObjectFromMetadata(output->data[i]);
-            // convert newImfile object -> rawImfile object
-            rawImfileRow *imfile = newToRawImfile(config, object); 
-            if (!imfile) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to create a new rawImfile row");
-                psFree(object);
-                psFree(output);
-                return false;
-            }
-            // insert the rawImfile object into the database
-            if (!rawImfileInsertObject(config->dbh, imfile)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database");
-                psFree(imfile);
-                psFree(object);
-                psFree(output);
-                return false;
-            }
-            psFree(imfile);
-            // remove the neImfile object from the database
-            if (!newImfileDeleteObject(config->dbh, object)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to delete row from the database");
-                psFree(object);
-                psFree(output);
-                return false;
-            }
-            psFree(object);
-        }
-
-        // point of no return for rawImfile
-        if (!psDBCommit(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-static bool rawimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    // find all rawImfiles matching the default query
-    psArray *rawImfiles = rawImfileSelectRowObjects(config->dbh, config->where, 0);
-    if (!rawImfiles) {
-        psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
-        return false;
-    }
+        return true;
+    }
+
     bool simple = false;
     {
@@ -747,17 +805,37 @@
     }
 
-    if (psArrayLength(rawImfiles)) {
+    if (psArrayLength(output)) {
         // negative simple so the default is true
-        if (!rawImfilePrintObjects(stdout, rawImfiles, !simple)) {
+        if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(rawImfiles);
-            return false;
-        }
-    }
-
-    psFree(rawImfiles);
+            psFree(output);
+            return false;
+        }
+    }
+
+    psFree(output);
 
     return true;
 }
+
+
+static bool updateprocessedexpMode(pxConfig *config)
+{
+    bool status = false;
+    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
+        return false;
+    }
+
+    if (!pxSetFaultCode(config->dbh, "rawExp", config->where, code)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
+        return false;
+    }
+
+    return true;
+}
+
+
 # if 0
 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp)
@@ -781,4 +859,5 @@
 #endif
 
+
 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *exp)
 {
@@ -804,4 +883,5 @@
     return p2Exp;
 }
+
 
 static p2PendingImfileRow *rawImfileToP2PendingImfile(pxConfig *config, rawImfileRow *rawImfile)
@@ -817,15 +897,6 @@
 }
 
-static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-    PS_ASSERT_PTR_NON_NULL(exp, NULL);
-
-    // XXX this is dangerous but we should be able to get away with this as
-    // long rawScienceExp & rawDetrendExp are idetnical
-    return (rawScienceExpRow *)newToRawDetrendExp(config, exp);
-}
-
-static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp)
+
+static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -932,5 +1003,12 @@
     }
 
-    rawDetrendExpRow *raw = rawDetrendExpRowAlloc(
+    // default
+    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
+        return false;
+    }
+
+    rawExpRow *raw = rawExpRowAlloc(
         exp->exp_tag,
         exp->camera,
@@ -951,5 +1029,6 @@
         posang,
         object,
-        dateobs
+        dateobs,
+        code
     );
 
@@ -960,4 +1039,5 @@
     return raw;
 }
+
 
 static rawImfileRow *newToRawImfile(pxConfig *config, newImfileRow *imfile)
@@ -1065,4 +1145,10 @@
             dateobs = NULL;
         }
+    }
+
+    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
+        return false;
     }
 
@@ -1086,5 +1172,6 @@
         posang,
         object,
-        dateobs
+        dateobs,
+        code
     );
 
Index: trunk/ippTools/src/regtool.h
===================================================================
--- trunk/ippTools/src/regtool.h	(revision 11038)
+++ trunk/ippTools/src/regtool.h	(revision 11047)
@@ -25,11 +25,12 @@
 typedef enum {
     P0TOOL_MODE_NONE      = 0x0,
+    P0TOOL_MODE_PENDINGIMFILE,
+    P0TOOL_MODE_ADDPROCESSEDIMFILE,
+    P0TOOL_MODE_PROCESSEDIMFILE,
+    P0TOOL_MODE_UPDATEPROCESSEDIMFILE,
     P0TOOL_MODE_PENDINGEXP,
-    P0TOOL_MODE_PENDINGIMFILE,
-    P0TOOL_MODE_UPDATEEXP,
-    P0TOOL_MODE_FAULTEXP,
-    P0TOOL_MODE_UPDATEIMFILE,
-    P0TOOL_MODE_FAULTIMFILE,
-    P0TOOL_MODE_RAWIMFILE
+    P0TOOL_MODE_ADDPROCESSEDEXP,
+    P0TOOL_MODE_PROCESSEDEXP,
+    P0TOOL_MODE_UPDATEPROCESSEDEXP,
 } p0toolMode;
 
Index: trunk/ippTools/src/regtoolConfig.c
===================================================================
--- trunk/ippTools/src/regtoolConfig.c	(revision 11038)
+++ trunk/ippTools/src/regtoolConfig.c	(revision 11047)
@@ -41,4 +41,85 @@
     }
 
+    // -pendingimfile
+    psMetadata *pendingimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class",  0,
+        "search by class", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class_id",  0,
+        "search by class ID", NULL);
+    psMetadataAddU64(pendingimfileArgs, PS_LIST_TAIL, "-limit",  0,
+        "limit result set to N items", 0);
+    psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple",  0,
+        "use the simple output format", false);
+
+    // -addprocessedimfile
+    psMetadata *addprocessedimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-class",  0,
+        "search by class", NULL);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,
+        "search by class ID", NULL);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_type",  0,
+        "define exposure type", NULL);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-filter",  0,
+        "define filter ", NULL);
+    psMetadataAddF32(addprocessedimfileArgs, PS_LIST_TAIL, "-airmass",  0,
+        "define airmass", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-ra",  0,
+        "define RA", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-decl",  0,
+        "define DEC", NAN);
+    psMetadataAddF32(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_time",  0,
+        "define exposure time", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-bg",  0,
+        "define exposue background", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-bg_stdev",  0,
+        "define exposue background stdev", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
+        "define exposue background mean stdev", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-alt",  0,
+        "define altitute", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-az",  0,
+        "define azimuth", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-ccd_temp",  0,
+        "define ccd tempature", NAN);
+    psMetadataAddF64(addprocessedimfileArgs, PS_LIST_TAIL, "-posang",  0,
+        "define rotator position angle", NAN);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-object",  0,
+        "define exposure object", NULL);
+    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-dateobs",  0,
+        "define observation time", NULL);
+    psMetadataAddS8(addprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,
+        "set fault code (required)", 0);
+
+    // -processedimfile
+    psMetadata *processedimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(processedimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddStr(processedimfileArgs, PS_LIST_TAIL, "-class",  0,
+        "search by class", NULL);
+    psMetadataAddStr(processedimfileArgs, PS_LIST_TAIL, "-class_id",  0,
+        "search by class ID", NULL);
+    psMetadataAddU64(processedimfileArgs, PS_LIST_TAIL, "-limit",  0,
+        "limit result set to N items", 0);
+    psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-faulted",  0,
+        "only return imfiles with a fault status set", false);
+    psMetadataAddBool(processedimfileArgs, PS_LIST_TAIL, "-simple",  0,
+        "use the simple output format", false);
+
+    // -updateprocessedimfile
+    psMetadata *updateprocessedimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(updateprocessedimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddStr(updateprocessedimfileArgs, PS_LIST_TAIL, "-class",  0,
+        "search by class", NULL);
+    psMetadataAddStr(updateprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,
+        "search by class ID", NULL);
+    psMetadataAddS8(updateprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,
+        "set fault code (required)", 0);
+    
+
     // -pendingexp
     psMetadata *pendingexpArgs = psMetadataAlloc();
@@ -55,61 +136,45 @@
     psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",  0,
         "limit result set to N items", 0);
-    psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-faulted",  0,
-        "only return imfiles with a fault status set", false);
     psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-simple",  0,
         "use the simple output format", false);
-    
-    // -pendingimfile
-    psMetadata *pendingimfileArgs = psMetadataAlloc();
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
-        "search by exposure ID", NULL);
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class",  0,
-        "search by class", NULL);
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-class_id",  0,
-        "search by class ID", NULL);
-    psMetadataAddU64(pendingimfileArgs, PS_LIST_TAIL, "-limit",  0,
-        "limit result set to N items", 0);
-    psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-faulted",  0,
-        "only return imfiles with a fault status set", false);
-    psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple",  0,
-        "use the simple output format", false);
-
-
-    // -updateexp
-    psMetadata *updateexpArgs = psMetadataAlloc();
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
+
+    // -addprocessedexp
+    psMetadata *addprocessedexpArgs = psMetadataAlloc();
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
         "exp_tag to operate on (required)", NULL); 
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-exp_type",  0,
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-exp_type",  0,
         "define exposure type", NULL);
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-filter",  0,
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-filter",  0,
         "define filter ", NULL);
-    psMetadataAddF32(updateexpArgs, PS_LIST_TAIL, "-airmass",  0,
+    psMetadataAddF32(addprocessedexpArgs, PS_LIST_TAIL, "-airmass",  0,
         "define airmass", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-ra",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-ra",  0,
         "define RA", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-decl",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-decl",  0,
         "define DEC", NAN);
-    psMetadataAddF32(updateexpArgs, PS_LIST_TAIL, "-exp_time",  0,
+    psMetadataAddF32(addprocessedexpArgs, PS_LIST_TAIL, "-exp_time",  0,
         "define exposure time", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-bg",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-bg",  0,
         "define exposue background", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-bg_stdev",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-bg_stdev",  0,
         "define exposue background stdev", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
         "define exposue background mean stdev", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-alt",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-alt",  0,
         "define altitute", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-az",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-az",  0,
         "define azimuth", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-ccd_temp",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-ccd_temp",  0,
         "define ccd tempature", NAN);
-    psMetadataAddF64(updateexpArgs, PS_LIST_TAIL, "-posang",  0,
+    psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-posang",  0,
         "define rotator position angle", NAN);
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-object",  0,
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-object",  0,
         "define exposure object", NULL);
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-dateobs",  0,
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-dateobs",  0,
         "define observation time", NULL);
-    psMetadataAddStr(updateexpArgs, PS_LIST_TAIL, "-label",  0,
+    psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-label",  0,
         "define label for phase 2 processing (non-detrend data only)", NULL);
+    psMetadataAddS8(addprocessedexpArgs, PS_LIST_TAIL, "-code",  0,
+        "set fault code (required)", 0);
     /*
     psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-recip",  0,
@@ -118,72 +183,25 @@
         "define URL", NULL);
     */
-    psMetadataAddBool(updateexpArgs, PS_LIST_TAIL, "-detrend",  0,
+    psMetadataAddBool(addprocessedexpArgs, PS_LIST_TAIL, "-detrend",  0,
         "declare this as detrend data", false);
 
-    // -faultexp
-    psMetadata *faultexpArgs = psMetadataAlloc();
-    psMetadataAddStr(faultexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
-        "search by exposure ID", NULL);
-    psMetadataAddS8(faultexpArgs, PS_LIST_TAIL, "-code",  0,
+    // -processedexp
+    psMetadata *processedexpArgs = psMetadataAlloc();
+    psMetadataAddStr(processedexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddU64(processedexpArgs, PS_LIST_TAIL, "-limit",  0,
+        "limit result set to N items", 0);
+    psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-faulted",  0,
+        "only return imfiles with a fault status set", false);
+    psMetadataAddBool(processedexpArgs, PS_LIST_TAIL, "-simple",  0,
+        "use the simple output format", false);
+
+    // -updatedprocessedexp
+    psMetadata *updatedprocessedexpArgs = psMetadataAlloc();
+    psMetadataAddStr(updatedprocessedexpArgs, PS_LIST_TAIL, "-exp_tag",  0,
+        "search by exposure ID", NULL);
+    psMetadataAddS8(updatedprocessedexpArgs, PS_LIST_TAIL, "-code",  0,
         "set fault code (required)", 0);
     
-    // -updateimfile
-    psMetadata *updateimfileArgs = psMetadataAlloc();
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
-        "search by exposure ID", NULL);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-class",  0,
-        "search by class", NULL);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-class_id",  0,
-        "search by class ID", NULL);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-exp_type",  0,
-        "define exposure type", NULL);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-filter",  0,
-        "define filter ", NULL);
-    psMetadataAddF32(updateimfileArgs, PS_LIST_TAIL, "-airmass",  0,
-        "define airmass", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-ra",  0,
-        "define RA", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-decl",  0,
-        "define DEC", NAN);
-    psMetadataAddF32(updateimfileArgs, PS_LIST_TAIL, "-exp_time",  0,
-        "define exposure time", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-bg",  0,
-        "define exposue background", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-bg_stdev",  0,
-        "define exposue background stdev", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,
-        "define exposue background mean stdev", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-alt",  0,
-        "define altitute", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-az",  0,
-        "define azimuth", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-ccd_temp",  0,
-        "define ccd tempature", NAN);
-    psMetadataAddF64(updateimfileArgs, PS_LIST_TAIL, "-posang",  0,
-        "define rotator position angle", NAN);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-object",  0,
-        "define exposure object", NULL);
-    psMetadataAddStr(updateimfileArgs, PS_LIST_TAIL, "-dateobs",  0,
-        "define observation time", NULL);
-
-    // -faultimfile
-    psMetadata *faultimfileArgs = psMetadataAlloc();
-    psMetadataAddStr(faultimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
-        "search by exposure ID", NULL);
-    psMetadataAddStr(faultimfileArgs, PS_LIST_TAIL, "-class",  0,
-        "search by class", NULL);
-    psMetadataAddStr(faultimfileArgs, PS_LIST_TAIL, "-class_id",  0,
-        "search by class ID", NULL);
-    psMetadataAddS8(faultimfileArgs, PS_LIST_TAIL, "-code",  0,
-        "set fault code (required)", 0);
-    
-    // -rawimfile
-    psMetadata *rawimfileArgs = psMetadataAlloc();
-    psMetadataAddStr(rawimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
-        "search by exposure ID", NULL);
-    psMetadataAddStr(rawimfileArgs, PS_LIST_TAIL, "-class_id",  0,
-        "search by class ID", NULL);
-    psMetadataAddBool(rawimfileArgs, PS_LIST_TAIL, "-simple",  0,
-        "use the simple output format", false);
 
 #define PXTOOL_MODE(option, modeval, argset) \
@@ -207,11 +225,12 @@
     psMetadata *argSets = psMetadataAlloc();
     // find which mode we're running under
-    PXTOOL_MODE("-pendingexp",   P0TOOL_MODE_PENDINGEXP,    pendingexpArgs);
-    PXTOOL_MODE("-pendingimfile",P0TOOL_MODE_PENDINGIMFILE, pendingimfileArgs);
-    PXTOOL_MODE("-updateexp",    P0TOOL_MODE_UPDATEEXP,     updateexpArgs);
-    PXTOOL_MODE("-faultexp",     P0TOOL_MODE_FAULTEXP,      faultexpArgs);
-    PXTOOL_MODE("-updateimfile", P0TOOL_MODE_UPDATEIMFILE,  updateimfileArgs);
-    PXTOOL_MODE("-faultimfile",  P0TOOL_MODE_FAULTIMFILE,   faultimfileArgs);
-    PXTOOL_MODE("-rawimfile",    P0TOOL_MODE_RAWIMFILE,     rawimfileArgs);
+    PXTOOL_MODE("-pendingimfile",   P0TOOL_MODE_PENDINGIMFILE, pendingimfileArgs);
+    PXTOOL_MODE("-addprocessedimfile", P0TOOL_MODE_ADDPROCESSEDIMFILE, addprocessedimfileArgs);
+    PXTOOL_MODE("-processedimfile", P0TOOL_MODE_PROCESSEDIMFILE, processedimfileArgs);
+    PXTOOL_MODE("-updateprocessedimfile",  P0TOOL_MODE_UPDATEPROCESSEDIMFILE, updateprocessedimfileArgs);
+    PXTOOL_MODE("-pendingexp",      P0TOOL_MODE_PENDINGEXP,pendingexpArgs);
+    PXTOOL_MODE("-addprocessedexp", P0TOOL_MODE_ADDPROCESSEDEXP, addprocessedexpArgs);
+    PXTOOL_MODE("-processedexp",    P0TOOL_MODE_PROCESSEDEXP, processedexpArgs);
+    PXTOOL_MODE("-updateprocessedexp", P0TOOL_MODE_UPDATEPROCESSEDEXP,      updatedprocessedexpArgs);
 
     bool argErr = false;
