Index: trunk/ippTools/src/warptool.c
===================================================================
--- trunk/ippTools/src/warptool.c	(revision 19416)
+++ trunk/ippTools/src/warptool.c	(revision 19522)
@@ -50,4 +50,8 @@
 static bool pendingcleanupwarpMode(pxConfig *config);
 static bool donecleanupMode(pxConfig *config);
+static bool tocleanedskyfileMode(pxConfig *config);
+static bool topurgedskyfileMode(pxConfig *config);
+static bool tofullskyfileMode(pxConfig *config);
+static bool updateskyfileMode(pxConfig *config);
 
 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile);
@@ -91,4 +95,8 @@
         MODECASE(WARPTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupwarpMode);
         MODECASE(WARPTOOL_MODE_DONECLEANUP,        donecleanupMode);
+        MODECASE(WARPTOOL_MODE_TOCLEANEDSKYFILE,   tocleanedskyfileMode);
+        MODECASE(WARPTOOL_MODE_TOPURGEDSKYFILE,    topurgedskyfileMode);
+        MODECASE(WARPTOOL_MODE_TOFULLSKYFILE,      tofullskyfileMode);
+        MODECASE(WARPTOOL_MODE_UPDATESKYFILE,      updateskyfileMode);
 
         default:
@@ -1502,2 +1510,84 @@
     return true;
 }
+
+// update warpSkyfile.data_state to given value.
+// afterwards, if all skfyiles in the run have the new state, update the state for the run as well
+// shared code for the modes -tocleanedskyfile -tofullskyfile -topurgedskyfile
+
+static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // warp_id, skycell_id are required
+    PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
+    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
+
+    psString query = pxDataGet("warptool_change_skyfile_data_state.sql");
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // note only updates if warpRun.state = run_state
+    if (!p_psDBRunQuery(config->dbh, query, data_state, warp_id, skycell_id, run_state)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        // rollback
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    psFree(query);
+
+    query = pxDataGet("warptool_change_run_state.sql");
+    if (!p_psDBRunQuery(config->dbh, query, data_state, warp_id, data_state)) {
+        // rollback
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    return true;
+}
+static bool tocleanedskyfileMode(pxConfig *config)
+{
+    return change_skyfile_data_state(config, "cleaned", "goto_cleaned");
+}
+static bool tofullskyfileMode(pxConfig *config)
+{
+    return change_skyfile_data_state(config, "full", "update");
+}
+static bool topurgedskyfileMode(pxConfig *config)
+{
+    return change_skyfile_data_state(config, "purged", "goto_purged");
+}
+
+static bool updateskyfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // warp_id, skycell_id, code are required
+    PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
+    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
+    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+
+    psString query = pxDataGet("warptool_updateskyfile.sql");
+
+    // note only updates if warpRun.state = run_state
+    if (!p_psDBRunQuery(config->dbh, query, code, warp_id, skycell_id)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    psFree(query);
+
+    return true;
+}
