Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 19693)
+++ 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 19693)
+++ 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'
+    
+
