Index: branches/tap_branches/ippTasks/diff.pro
===================================================================
--- branches/tap_branches/ippTasks/diff.pro	(revision 25900)
+++ branches/tap_branches/ippTasks/diff.pro	(revision 27838)
@@ -15,4 +15,5 @@
 $diffSkycell_DB = 0
 $diffAdvance_DB = 0
+$diff_revert_DB = 0
 #$diffCleanup_DB = 0
 
@@ -40,4 +41,7 @@
     active true
   end
+  task diff.revert
+    active false
+  end
 end
 
@@ -53,4 +57,19 @@
     active false
   end
+  task diff.revert
+    active false
+  end
+end
+
+macro diff.revert.on
+  task diff.revert
+    active true
+  end
+end
+
+macro diff.revert.off
+  task diff.revert
+    active false
+  end
 end
 
@@ -76,4 +95,6 @@
 ### Load tasks for doing the differences
 ### Tasks are loaded into diffSkyfile.
+
+
 task	       diff.skycell.load
   host         local
@@ -139,8 +160,12 @@
 
   task.exec
+    # if we are unable to run the 'exec', use a long retry time
+    periods -exec $RUNEXEC
+
     book npages diffSkyfile -var N
     if ($N == 0) break
     if ($NETWORK == 0) break
-    
+    if ($BURNTOOLING == 1) break
+
     # look for new images in diffSkyfile (pantaskState == INIT)
     book getpage diffSkyfile 0 -var pageName -key pantaskState INIT
@@ -155,5 +180,8 @@
     book getword diffSkyfile $pageName bothways -var BOTHWAYS
     book getword diffSkyfile $pageName workdir -var WORKDIR_TEMPLATE
+    book getword diffSkyfile $pageName state -var RUN_STATE
     book getword diffSkyfile $pageName dbname -var DBNAME
+    book getword diffSkyfile $pageName reduction -var REDUCTION
+    book getword diffSkyfile $pageName diff_mode -var DIFF_MODE
 
     # set the host and workdir based on the skycell hash
@@ -165,13 +193,29 @@
     # $WORKDIR = $WORKDIR_TEMPLATE
 
+    if (($DIFF_MODE == 1)||("$DIFF_MODE" == "NULL")) 
+	$DIFF_TAG = ""
+    end
+    if ($DIFF_MODE == 2)
+	$DIFF_TAG = "WS."
+    end 
+    if ($DIFF_MODE == 3)
+	$DIFF_TAG = "SW."
+    end
+    if ($DIFF_MODE == 4)
+	$DIFF_TAG = "SS."
+    end
+
     basename $TESS_DIR -var TESS_ID
-    sprintf outroot "%s/%s/%s/%s.%s.dif.%s" $WORKDIR $TESS_ID $SKYCELL_ID $TESS_ID $SKYCELL_ID $DIFF_ID
+    sprintf outroot "%s/%s/%s/%s.%s.%sdif.%s" $WORKDIR $TESS_ID $SKYCELL_ID $TESS_ID $SKYCELL_ID $DIFF_TAG $DIFF_ID
 
     stdout $LOGDIR/diff.skycell.log
     stderr $LOGDIR/diff.skycell.log
 
-    $run = diff_skycell.pl --threads @MAX_THREADS@ --diff_id $DIFF_ID --skycell_id $SKYCELL_ID --diff_skyfile_id $DIFF_SKYFILE_ID --outroot $outroot --redirect-output
+    $run = diff_skycell.pl --threads @MAX_THREADS@ --diff_id $DIFF_ID --skycell_id $SKYCELL_ID --diff_skyfile_id $DIFF_SKYFILE_ID --outroot $outroot --redirect-output --run-state $RUN_STATE
     if ("$BOTHWAYS" == "T")
        $run = $run --inverse
+    end
+    if ("$REDUCTION" != "NULL")
+      $run = $run --reduction $REDUCTION
     end
     add_standard_args run
@@ -184,4 +228,5 @@
       echo command $run
     end
+    periods -exec 0.05
     command $run
   end
@@ -375,2 +420,53 @@
 #   end
 # end
+
+task diff.revert
+  host         local
+
+  periods      -poll 60.0
+  periods      -exec 1800.0
+  periods      -timeout 120.0
+  npending     1
+  active false
+
+  stdout NULL
+  stderr $LOGDIR/revert.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    # Only revert failures with fault=2 (SYS_ERROR), which tend to be
+    # temporary filesystem problems.  Every other fault type is
+    # interesting and should be kept for debugging (and so it doesn't
+    # continue to occur).
+    $run = difftool -revertdiffskyfile -fault 2
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$diff_revert_DB
+      $run = $run -dbname $DB:$diff_revert_DB
+      $diff_revert_DB ++
+      if ($diff_revert_DB >= $DB:n) set diff_revert_DB = 0
+    end
+    add_poll_labels 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
