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)
 {
Index: trunk/ippTools/src/dettool.h
===================================================================
--- trunk/ippTools/src/dettool.h	(revision 14266)
+++ trunk/ippTools/src/dettool.h	(revision 14268)
@@ -62,6 +62,7 @@
     DETTOOL_MODE_REVERTRESIDIMFILE,
     DETTOOL_MODE_TORESIDEXP,
+    DETTOOL_MODE_ADDRESIDEXP,
     DETTOOL_MODE_RESIDEXP,
-    DETTOOL_MODE_ADDRESIDEXP,
+    DETTOOL_MODE_REVERTRESIDEXP,
     DETTOOL_MODE_TODETRUNSUMMARY,
     DETTOOL_MODE_UPDATERESIDEXP,
Index: trunk/ippTools/src/dettoolConfig.c
===================================================================
--- trunk/ippTools/src/dettoolConfig.c	(revision 14266)
+++ trunk/ippTools/src/dettoolConfig.c	(revision 14268)
@@ -855,4 +855,15 @@
             "use the simple output format", false);
 
+    // -revertresidexp
+    psMetadata *revertresidexpArgs = psMetadataAlloc();
+    psMetadataAddStr(revertresidexpArgs, PS_LIST_TAIL, "-det_id", 0,
+            "search by detrend ID (required)", NULL);
+    psMetadataAddS32(revertresidexpArgs, PS_LIST_TAIL, "-iteration", 0,
+            "search by iteration number", 0);
+    psMetadataAddStr(revertresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,
+            "search by detrend ID", NULL);
+    psMetadataAddS16(revertresidexpArgs, PS_LIST_TAIL, "-code",  0,
+            "search by fault code", 0);
+
     // -todetrunsummary
     psMetadata *todetrunsummaryArgs = psMetadataAlloc();
@@ -1054,4 +1065,5 @@
     PXTOOL_ADD_MODE("-addresidexp",     "", DETTOOL_MODE_ADDRESIDEXP,  addresidexpArgs);
     PXTOOL_ADD_MODE("-residexp",        "", DETTOOL_MODE_RESIDEXP,     residexpArgs);
+    PXTOOL_ADD_MODE("-revertresidexp",  "", DETTOOL_MODE_REVERTRESIDEXP, revertresidexpArgs);
     PXTOOL_ADD_MODE("-todetrunsummary",  "", DETTOOL_MODE_TODETRUNSUMMARY,  todetrunsummaryArgs);
     PXTOOL_ADD_MODE("-updateresidexp", "", DETTOOL_MODE_UPDATERESIDEXP,updateresidexpArgs);
