Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 14265)
+++ trunk/ippTools/src/dettool.c	(revision 14266)
@@ -41,10 +41,10 @@
 static bool inputMode(pxConfig *config);
 static bool rawMode(pxConfig *config);
-// imfile
+// processedimfile
 static bool toprocessedimfileMode(pxConfig *config);
 static bool addprocessedimfileMode(pxConfig *config);
 static bool processedimfileMode(pxConfig *config);
 static bool revertprocessedimfileMode(pxConfig *config);
-// exp
+// processedexp
 static bool toprocessedexpMode(pxConfig *config);
 static bool addprocessedexpMode(pxConfig *config);
@@ -74,6 +74,8 @@
 static bool toresidimfileMode(pxConfig *config);
 static bool addresidimfileMode(pxConfig *config);
+static bool residimfileMode(pxConfig *config);
+static bool revertresidimfileMode(pxConfig *config);
+// residexp
 static bool toresidexpMode(pxConfig *config);
-static bool residimfileMode(pxConfig *config);
 static bool addresidexpMode(pxConfig *config);
 static bool residexpMode(pxConfig *config);
@@ -161,14 +163,17 @@
         MODECASE(DETTOOL_MODE_ADDRESIDIMFILE,   addresidimfileMode);
         MODECASE(DETTOOL_MODE_RESIDIMFILE,      residimfileMode);
-
+        MODECASE(DETTOOL_MODE_REVERTRESIDIMFILE,revertresidimfileMode);
+        // residexp
         MODECASE(DETTOOL_MODE_TORESIDEXP,       toresidexpMode);
         MODECASE(DETTOOL_MODE_ADDRESIDEXP,      addresidexpMode);
         MODECASE(DETTOOL_MODE_RESIDEXP,         residexpMode);
+        MODECASE(DETTOOL_MODE_UPDATERESIDEXP,   updateresidexpMode);
+        // detrunsummary
         MODECASE(DETTOOL_MODE_TODETRUNSUMMARY,  todetrunsummaryMode);
-        MODECASE(DETTOOL_MODE_UPDATERESIDEXP,   updateresidexpMode);
         MODECASE(DETTOOL_MODE_ADDDETRUNSUMMARY, adddetrunsummaryMode);
         MODECASE(DETTOOL_MODE_DETRUNSUMMARY,    detrunsummaryMode);
         MODECASE(DETTOOL_MODE_UPDATEDETRUN,     updatedetrunMode);
         MODECASE(DETTOOL_MODE_RERUN,            rerunMode);
+        // register
         MODECASE(DETTOOL_MODE_REGISTER_DETREND, register_detrendMode);
         MODECASE(DETTOOL_MODE_REGISTER_DETREND_IMFILE, register_detrend_imfileMode);
@@ -5091,4 +5096,37 @@
 }
 
+
+static bool revertresidimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psString query = pxDataGet("dettool_revertresidimfile.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidImfile");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    if (psDBAffectedRows(config->dbh) < 1) {
+        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
+        return false;
+    }
+
+    return true;
+}
+
+
 static bool toresidexpMode(pxConfig *config)
 {
