Index: /trunk/ippTools/src/warptool.c
===================================================================
--- /trunk/ippTools/src/warptool.c	(revision 11775)
+++ /trunk/ippTools/src/warptool.c	(revision 11776)
@@ -115,5 +115,5 @@
 static bool definerunMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     // required options
@@ -236,5 +236,5 @@
 static bool addinputexpMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     bool status = false;
@@ -569,5 +569,5 @@
 static bool addoverlapMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     bool status = false;
@@ -668,5 +668,5 @@
 static bool scmapMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     bool status = false;
@@ -755,5 +755,92 @@
 static bool towarpedMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    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;
+    }
+
+    // find all rawImfiles matching the default query
+    psString query = psStringCopy( 
+        "SELECT\n"
+        "   p4SkyCellMap.*\n"
+        " FROM p4Run\n"
+        " JOIN p4SkyCellMap\n"
+        "   USING(p4_id)\n"
+        " LEFT JOIN p4Scfile\n"
+        "   USING(p4_id, skycell_id, tess_id, exp_tag, p3_version)\n"
+        " WHERE\n"
+        "   p4Run.state = 'run'\n" 
+        "   AND p4Scfile.p4_id IS NULL\n"
+        "   AND p4Scfile.skycell_id IS NULL\n"
+        "   AND p4Scfile.tess_id IS NULL\n"
+        "   AND p4Scfile.exp_tag IS NULL\n"
+        "   AND p4Scfile.p3_version IS NULL\n"
+    );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    // 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) {
+        psErrorCode err = psErrorCodeLast();
+        switch (err) {
+            case PS_ERR_DB_CLIENT:
+                psError(PXTOOLS_ERR_SYS, false, "database error");
+            case PS_ERR_DB_SERVER:
+                psError(PXTOOLS_ERR_PROG, false, "database error");
+            default:
+                psError(PXTOOLS_ERR_PROG, false, "unknown error");
+        }
+
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psError(PS_ERR_UNKNOWN, false, "no p4PendingSkyCell 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, "p4PendingSkyCell", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
+    }
+
+    psFree(output);
+
     return true;
 }
@@ -762,5 +849,5 @@
 static bool addwarpedMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     bool status = false;
@@ -856,5 +943,5 @@
 static bool warpedMode(pxConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, false);
 
     psString query = psStringCopy(
