Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 14266)
+++ trunk/ippTools/src/dettool.c	(revision 14268)
@@ -51,5 +51,5 @@
 static bool processedexpMode(pxConfig *config);
 static bool revertprocessedexpMode(pxConfig *config);
-// stacked[imfile]
+// stackedimfile
 static bool tostackedMode(pxConfig *config);
 static bool addstackedMode(pxConfig *config);
@@ -80,10 +80,13 @@
 static bool addresidexpMode(pxConfig *config);
 static bool residexpMode(pxConfig *config);
+static bool revertresidexpMode(pxConfig *config);
+static bool updateresidexpMode(pxConfig *config);
+// detrunsummary
 static bool todetrunsummaryMode(pxConfig *config);
-static bool updateresidexpMode(pxConfig *config);
 static bool adddetrunsummaryMode(pxConfig *config);
 static bool detrunsummaryMode(pxConfig *config);
 static bool updatedetrunMode(pxConfig *config);
 static bool rerunMode(pxConfig *config);
+// register
 static bool register_detrendMode(pxConfig *config);
 static bool register_detrend_imfileMode(pxConfig *config);
@@ -168,4 +171,5 @@
         MODECASE(DETTOOL_MODE_ADDRESIDEXP,      addresidexpMode);
         MODECASE(DETTOOL_MODE_RESIDEXP,         residexpMode);
+        MODECASE(DETTOOL_MODE_REVERTRESIDEXP,   revertresidexpMode);
         MODECASE(DETTOOL_MODE_UPDATERESIDEXP,   updateresidexpMode);
         // detrunsummary
@@ -5610,4 +5614,37 @@
 }
 
+
+static bool revertresidexpMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psString query = pxDataGet("dettool_revertresidexp.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidExp");
+        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 todetrunsummaryMode(pxConfig *config)
 {
