Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 19701)
+++ trunk/ippTools/share/Makefile.am	(revision 19702)
@@ -79,4 +79,6 @@
      difftool_skyfile.sql \
      difftool_todiffskyfile.sql \
+     faketool_change_exp_state.sql \
+     faketool_change_imfile_data_state.sql \
      faketool_completely_processed_exp.sql \
      faketool_donecleanup.sql \
Index: trunk/ippTools/share/chiptool_change_exp_state.sql
===================================================================
--- trunk/ippTools/share/chiptool_change_exp_state.sql	(revision 19701)
+++ trunk/ippTools/share/chiptool_change_exp_state.sql	(revision 19702)
@@ -1,4 +1,4 @@
 -- change state of chipRun from goto_cleaned to cleaned or goto_purged to purged
--- when all of the consituant imfiles are in the rgith state
+-- when all of the constituant imfiles are in the right state
 -- arguments are new state (cleaned or purged) chip_id and new state again for 
 -- the chipProcessedImfile sub query
Index: trunk/ippTools/share/faketool_change_exp_state.sql
===================================================================
--- trunk/ippTools/share/faketool_change_exp_state.sql	(revision 19702)
+++ trunk/ippTools/share/faketool_change_exp_state.sql	(revision 19702)
@@ -0,0 +1,15 @@
+-- change state of fakeRun from goto_cleaned to cleaned or goto_purged to purged
+-- when all of the constituant imfiles are in the right state
+-- arguments are new state (cleaned or purged) fake_id and new state again for 
+-- the fakeProcessedImfile sub query
+UPDATE fakeRun
+    SET state = '%s'
+    WHERE
+    fakeRun.fake_id = %lld
+    AND (SELECT
+        COUNT(fake_id)
+        FROM fakeProcessedImfile
+        WHERE
+            fakeProcessedImfile.fake_id = fakeRun.fake_id
+            AND data_state != '%s'
+        ) = 0
Index: trunk/ippTools/share/faketool_change_imfile_data_state.sql
===================================================================
--- trunk/ippTools/share/faketool_change_imfile_data_state.sql	(revision 19702)
+++ trunk/ippTools/share/faketool_change_imfile_data_state.sql	(revision 19702)
@@ -0,0 +1,14 @@
+-- handle changes in data_state. Used for the modes tocleanedimfile and topurgedimfile
+-- args are new data_state, fake_id, class_id, and current expected state for fakeRun
+UPDATE fakeProcessedImfile
+    SET 
+    data_state = '%s'
+WHERE
+    fake_id = %lld
+    AND class_id = '%s'
+    -- only update if fakeRun.state has the expected value
+    AND (
+        SELECT state from fakeRun where fakeRun.fake_id = fakeProcessedImfile.fake_id
+    ) = '%s'
+    
+
Index: trunk/ippTools/src/faketool.c
===================================================================
--- trunk/ippTools/src/faketool.c	(revision 19701)
+++ trunk/ippTools/src/faketool.c	(revision 19702)
@@ -48,4 +48,7 @@
 static bool pendingcleanupimfileMode(pxConfig *config);
 static bool donecleanupMode(pxConfig *config);
+static bool tocleanedimfileMode(pxConfig *config);
+static bool tofullimfileMode(pxConfig *config);
+static bool topurgedimfileMode(pxConfig *config);
 
 static bool fakeProcessedCompleteExp(pxConfig *config);
@@ -83,4 +86,8 @@
         MODECASE(FAKETOOL_MODE_PENDINGCLEANUPIMFILE,    pendingcleanupimfileMode);
         MODECASE(FAKETOOL_MODE_DONECLEANUP,             donecleanupMode);
+        MODECASE(FAKETOOL_MODE_TOCLEANEDIMFILE,         tocleanedimfileMode);
+        MODECASE(FAKETOOL_MODE_TOFULLIMFILE,            tofullimfileMode);
+        MODECASE(FAKETOOL_MODE_TOPURGEDIMFILE,          topurgedimfileMode);
+ 
         default:
             psAbort("invalid option (this should not happen)");
@@ -1129,2 +1136,68 @@
     return true;
 }
+
+// update fakeProcessedImfile.data_state to given value.
+// afterwards, if all imfiles in the exposure have the new state, update the state for the exposure as well
+// shared code for the modes -tocleanedimfile -tofullimfile -topurgedimfile
+
+static bool change_imfile_data_state(pxConfig *config, psString data_state, psString run_state)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // fake_id, class_id are required
+    PXOPT_LOOKUP_S64(fake_id, config->args, "-fake_id", true, false);
+    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
+
+    psString query = pxDataGet("faketool_change_imfile_data_state.sql");
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // note only updates if fakeRun.state = run_state
+    if (!p_psDBRunQuery(config->dbh, query, data_state, fake_id, class_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);
+
+    if (psDBAffectedRows(config->dbh) < 1) {
+        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
+        return false;
+    }
+    
+    query = pxDataGet("faketool_change_exp_state.sql");
+    if (!p_psDBRunQuery(config->dbh, query, data_state, fake_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 tocleanedimfileMode(pxConfig *config)
+{
+    return change_imfile_data_state(config, "cleaned", "goto_cleaned");
+}
+static bool tofullimfileMode(pxConfig *config)
+{
+    return change_imfile_data_state(config, "full", "update");
+}
+static bool topurgedimfileMode(pxConfig *config)
+{
+    return change_imfile_data_state(config, "purged", "goto_purged");
+}
Index: trunk/ippTools/src/faketool.h
===================================================================
--- trunk/ippTools/src/faketool.h	(revision 19701)
+++ trunk/ippTools/src/faketool.h	(revision 19702)
@@ -41,4 +41,7 @@
     FAKETOOL_MODE_PENDINGCLEANUPIMFILE,
     FAKETOOL_MODE_DONECLEANUP,
+    FAKETOOL_MODE_TOCLEANEDIMFILE,
+    FAKETOOL_MODE_TOFULLIMFILE,
+    FAKETOOL_MODE_TOPURGEDIMFILE,
 } FAKETOOLMode;
 
Index: trunk/ippTools/src/faketoolConfig.c
===================================================================
--- trunk/ippTools/src/faketoolConfig.c	(revision 19701)
+++ trunk/ippTools/src/faketoolConfig.c	(revision 19702)
@@ -278,4 +278,20 @@
     psMetadataAddBool(donecleanupArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
     psMetadataAddU64(donecleanupArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
+    // -tocleanedimfile
+    psMetadata *tocleanedimfileArgs = psMetadataAlloc();
+    psMetadataAddS64(tocleanedimfileArgs, PS_LIST_TAIL, "-fake_id", 0,          "fake ID to update", 0);
+    psMetadataAddStr(tocleanedimfileArgs, PS_LIST_TAIL, "-class_id",  0,        "class ID to update", NULL);
+
+    // -tofullimfile
+    psMetadata *tofullimfileArgs = psMetadataAlloc();
+    psMetadataAddS64(tofullimfileArgs, PS_LIST_TAIL, "-fake_id", 0,          "fake ID to update", 0);
+    psMetadataAddStr(tofullimfileArgs, PS_LIST_TAIL, "-class_id",  0,        "class ID to update", NULL);
+
+    // -topurgedimfile
+    psMetadata *topurgedimfileArgs = psMetadataAlloc();
+    psMetadataAddS64(topurgedimfileArgs, PS_LIST_TAIL, "-fake_id", 0,          "fake ID to update", 0);
+    psMetadataAddStr(topurgedimfileArgs, PS_LIST_TAIL, "-class_id",  0,        "class ID to update", NULL);
+
+
 
     psMetadata *argSets = psMetadataAlloc();
@@ -297,4 +313,8 @@
     PXOPT_ADD_MODE("-pendingcleanupimfile",  "show runs that need to be cleaned up", FAKETOOL_MODE_PENDINGCLEANUPIMFILE, pendingcleanupimfileArgs);
     PXOPT_ADD_MODE("-donecleanup",           "show runs that have been cleaned",     FAKETOOL_MODE_DONECLEANUP,          donecleanupArgs);
+    PXOPT_ADD_MODE("-tocleanedimfile",      "set imfile state to cleaned",           FAKETOOL_MODE_TOCLEANEDIMFILE,      tocleanedimfileArgs);
+    PXOPT_ADD_MODE("-tofullimfile",        "set imfile state to full",               FAKETOOL_MODE_TOFULLIMFILE,         tofullimfileArgs);
+    PXOPT_ADD_MODE("-topurgedimfile",      "set imfile state to purged",             FAKETOOL_MODE_TOPURGEDIMFILE,       topurgedimfileArgs);
+
 
     if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
