Index: trunk/ippTasks/detrend.stack.pro
===================================================================
--- trunk/ippTasks/detrend.stack.pro	(revision 23480)
+++ trunk/ippTasks/detrend.stack.pro	(revision 28557)
@@ -35,6 +35,19 @@
 end
 
+macro detstack.revert.off
+  task detrend.stack.revert
+    active false
+  end
+end
+
+macro detstack.revert.on
+  task detrend.stack.revert
+    active true
+  end
+end
+
 # this variable will cycle through the known database names
 $detPendingStackedImfile_DB = 0
+$detPendingStackedImfile_revert_DB = 0
 
 # select images ready for detrend_stack.pl
@@ -165,2 +178,49 @@
   end
 end
+
+
+task detrend.stack.revert
+  host         local
+
+  periods      -poll 60.0
+  periods      -exec 1800.0
+  periods      -timeout 120.0
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/revert.log
+
+  task.exec
+  
+    $run = dettool -revertstacked -all 
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingStackedImfile_revert_DB
+      $run = $run -dbname $DB:$detPendingStackedImfile_revert_DB
+      $detPendingStackedImfile_revert_DB ++
+      if ($detPendingStackedImfile_revert_DB >= $DB:n) set detPendingStackedImfile_revert_DB = 0
+    end
+    echo $run
+    command $run
+  end
+
+  # success
+  task.exit    0
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
