Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 11001)
+++ /trunk/ippTools/src/Makefile.am	(revision 11002)
@@ -32,4 +32,5 @@
 libpxtools_la_SOURCES   = \
 	pxconfig.c \
+	pxfault.c \
 	pxframes.c \
 	pxtables.c \
Index: /trunk/ippTools/src/chiptool.c
===================================================================
--- /trunk/ippTools/src/chiptool.c	(revision 11001)
+++ /trunk/ippTools/src/chiptool.c	(revision 11002)
@@ -33,4 +33,5 @@
 static bool pendingimfileMode(pxConfig *config);
 static bool addprocessedimfileMode(pxConfig *config);
+static bool faultimfileMode(pxConfig *config);
 static bool blockMode(pxConfig *config);
 static bool maskedMode(pxConfig *config);
@@ -58,4 +59,5 @@
         MODECASE(P2TOOL_MODE_PENDINGIMFILE,         pendingimfileMode);
         MODECASE(P2TOOL_MODE_ADDPROCESSEDIMFILE,    addprocessedimfileMode);
+        MODECASE(P2TOOL_MODE_FAULTIMFILE,           faultimfileMode);
         MODECASE(P2TOOL_MODE_BLOCK,                 blockMode);
         MODECASE(P2TOOL_MODE_MASKED,                maskedMode);
@@ -174,4 +176,17 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
+        return false;
+    }
+
     // XXX does this need to be constrained so that it won't return any results
     // if a match p2PendingExp hasn't been registered?
@@ -197,4 +212,19 @@
     }
 
+    if (faulted) {
+        // list only faulted rows
+        psStringAppend(&query, " %s", "AND p2PendingImfile.fault != 0");
+    } else {
+        // don't list faulted rows
+        psStringAppend(&query, " %s", "AND p2PendingImfile.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");
@@ -401,4 +431,25 @@
     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, "p2PendingImfile", config->where, code)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
+        return false;
+    }
+
+    return true;
+}
+
 
 static bool blockMode(pxConfig *config)
Index: /trunk/ippTools/src/chiptool.h
===================================================================
--- /trunk/ippTools/src/chiptool.h	(revision 11001)
+++ /trunk/ippTools/src/chiptool.h	(revision 11002)
@@ -29,4 +29,5 @@
     P2TOOL_MODE_PENDINGIMFILE,
     P2TOOL_MODE_ADDPROCESSEDIMFILE,
+    P2TOOL_MODE_FAULTIMFILE,
     P2TOOL_MODE_BLOCK,
     P2TOOL_MODE_MASKED,
Index: /trunk/ippTools/src/chiptoolConfig.c
===================================================================
--- /trunk/ippTools/src/chiptoolConfig.c	(revision 11001)
+++ /trunk/ippTools/src/chiptoolConfig.c	(revision 11002)
@@ -59,4 +59,8 @@
     psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-uri",  0,
             "define URL", 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);
@@ -83,4 +87,16 @@
             "define banana 2", 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);
+
+
     // -block
     psMetadata *blockArgs = psMetadataAlloc();
@@ -121,4 +137,5 @@
     PXTOOL_MODE("-pendingimfile", P2TOOL_MODE_PENDINGIMFILE, pendingimfileArgs);
     PXTOOL_MODE("-addprocessedimfile",P2TOOL_MODE_ADDPROCESSEDIMFILE,addprocessedimfileArgs);
+    PXTOOL_MODE("-faultimfile",  P2TOOL_MODE_FAULTIMFILE,   faultimfileArgs);
     PXTOOL_MODE("-block",        P2TOOL_MODE_BLOCK,          blockArgs);
     PXTOOL_MODE("-masked",       P2TOOL_MODE_MASKED,         maskedArgs);
Index: /trunk/ippTools/src/pxfault.c
===================================================================
--- /trunk/ippTools/src/pxfault.c	(revision 11002)
+++ /trunk/ippTools/src/pxfault.c	(revision 11002)
@@ -0,0 +1,65 @@
+/*
+ * pxfault.c
+ *
+ * Copyright (C) 2007  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 <pslib.h>
+
+#include "pxtools.h"
+
+bool pxSetFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS8 code)
+{
+    PS_ASSERT_PTR_NON_NULL(dbh, false);
+    PS_ASSERT_PTR_NON_NULL(tableName, false);
+    PS_ASSERT_PTR_NON_NULL(where, false);
+
+#if 0
+    // map code string to numeric fault code
+    psU32 code = mapCodeStrToInt(codeStr);
+    if (code == (psU32)-1) {
+        psError(PS_ERR_UNKNOWN, false, "error resolving error code");
+        return false;
+    }
+#endif
+
+    // update the database
+    psMetadata *values = psMetadataAlloc();
+    if (!psMetadataAddS8(values, PS_LIST_HEAD, "fault", 0, NULL, code)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add metadata item fault");
+        psFree(values);
+        return false;
+    }
+    psFree(values);
+
+    long rowsAffected = psDBUpdateRows(dbh, tableName, where, values); 
+    if (rowsAffected < 0) {
+        // database error
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (rowsAffected < 1) {
+        // we didn't do anything
+        psError(PS_ERR_UNKNOWN, false, "zero rows were affected - either the search criteria didn't match any rows or the field already had the value being set.");
+        return false;
+    }
+
+    return true;
+}
Index: /trunk/ippTools/src/pxtools.h
===================================================================
--- /trunk/ippTools/src/pxtools.h	(revision 11001)
+++ /trunk/ippTools/src/pxtools.h	(revision 11002)
@@ -69,3 +69,5 @@
 bool rawScienceFrameInsert(pxConfig *config, rawScienceFrame *frame);
 
+bool pxSetFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS8 code);
+
 #endif // PXTOOLS_H
Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 11001)
+++ /trunk/ippTools/src/regtool.c	(revision 11002)
@@ -41,5 +41,4 @@
 static rawImfileRow *newToRawImfile(pxConfig *config, newImfileRow *exp);
 //static psU32 mapCodeStrToInt(const char *codeStr);
-static bool setFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS8 code);
 
 
@@ -281,5 +280,5 @@
     }
 
-    if (!setFaultCode(config->dbh, "newExp", config->where, code)) {
+    if (!pxSetFaultCode(config->dbh, "newExp", config->where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         return false;
@@ -300,46 +299,6 @@
     }
 
-    if (!setFaultCode(config->dbh, "newImfile", config->where, code)) {
+    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 setFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS8 code)
-{
-    PS_ASSERT_PTR_NON_NULL(dbh, false);
-    PS_ASSERT_PTR_NON_NULL(tableName, false);
-    PS_ASSERT_PTR_NON_NULL(where, false);
-
-#if 0
-    // map code string to numeric fault code
-    psU32 code = mapCodeStrToInt(codeStr);
-    if (code == (psU32)-1) {
-        psError(PS_ERR_UNKNOWN, false, "error resolving error code");
-        return false;
-    }
-#endif
-
-    // update the database
-    psMetadata *values = psMetadataAlloc();
-    if (!psMetadataAddS8(values, PS_LIST_HEAD, "fault", 0, NULL, code)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add metadata item fault");
-        psFree(values);
-        return false;
-    }
-    psFree(values);
-
-    long rowsAffected = psDBUpdateRows(dbh, tableName, where, values); 
-    if (rowsAffected < 0) {
-        // database error
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (rowsAffected < 1) {
-        // we didn't do anything
-        psError(PS_ERR_UNKNOWN, false, "zero rows were affected - either the search criteria didn't match any rows or the field already had the value being set.");
         return false;
     }
@@ -839,7 +798,8 @@
         exp->exp_tag,
         "my recipe",
-        0xff, // XXX calc version number
-        0xff, // XXX calc version number
-        label
+        0xff,   // XXX calc version number
+        0xff,   // XXX calc version number
+        label,
+        0       // fault code
     );
 
@@ -855,5 +815,6 @@
         "my recipe",
         0xff, // XXX calc version number
-        0xff // XXX calc version number
+        0xff, // XXX calc version number
+        0       // fault code
     );
 }
