Index: trunk/ippTasks/diff.pro
===================================================================
--- trunk/ippTasks/diff.pro	(revision 12078)
+++ trunk/ippTasks/diff.pro	(revision 12078)
@@ -0,0 +1,172 @@
+### This file contains panTasks definitions for performing the image differencing.
+
+### After a difference (with associated diff_id) is defined, the difference is performed
+### (tasks in diffPendingSkycell).
+
+
+### Setups
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/diff
+exec mkdir -p $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init diffPendingSkycell
+
+### Database lists
+$diffSkycell_DB = 0
+
+### Check status of diffing tasks
+macro diff.status
+  book listbook diffPendingSkycell
+end
+
+### Reset diffing tasks
+macro diff.reset
+  book init diffPendingSkycell
+end
+
+### Turn diffing tasks on
+macro diff.on
+  task diff.skycell.load
+    active true
+  end
+  task diff.skycell.run
+    active true
+  end
+end
+
+### Turn diffing tasks off
+macro diff.off
+  task diff.skycell.load
+    active false
+  end
+  task diff.skycell.run
+    active false
+  end
+end
+
+
+### Load tasks for doing the differences
+### Tasks are loaded into diffPendingSkycell.
+task	       diff.skycell.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/diff.skycell.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command difftool -todiffed -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$diffSkycell_DB
+      command difftool -todiffskyfile -limit 20 -dbname $DB:$diffSkycell_DB
+      $diffSkycell_DB ++
+      if ($diffSkycell_DB >= $DB:n) set diffSkycell_DB = 0
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout diffPendingSkycell -key diff_id -uniq -setword dbname $options:0
+    if ($VERBOSE > 2)
+      book listbook diffPendingSkycell
+    end
+
+    # delete existing entries in the appropriate states
+    process_cleanup diffPendingSkycell
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+### Run tasks for calculating the diff overlaps
+### Tasks are taken from diffPendingSkycell.
+task	       diff.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 60
+
+  task.exec
+    book npages diffPendingSkycell -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in diffPendingSkycell (state == NULL)
+    book getpage diffPendingSkycell 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword diffPendingSkycell $pageName state RUN
+    book getword diffPendingSkycell $pageName diff_id -var DIFF_ID
+    book getword diffPendingSkycell $pageName camera -var CAMERA
+    book getword diffPendingSkycell $pageName workdir -var WORKDIR
+    book getword diffPendingSkycell $pageName dbname -var DBNAME
+    set_standard_args
+
+    # specify choice of remote host
+    # XXX need to choose based on diffs
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/diff$DIFF_ID
+    $logfile = $outroot/skycell.log
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $outroot
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command diff_skycell.pl --diff_id $DIFF_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+    end
+    command diff_skycell.pl --diff_id $DIFF_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit diffPendingSkycell $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword diffPendingSkycell $options:0 state TIMEOUT
+  end
+end
+
Index: trunk/ippTasks/stack.pro
===================================================================
--- trunk/ippTasks/stack.pro	(revision 12078)
+++ trunk/ippTasks/stack.pro	(revision 12078)
@@ -0,0 +1,172 @@
+### This file contains panTasks definitions for performing the image stacking.
+
+### After a stack (with associated stack_id) is defined, the stack is performed
+### (tasks in stackPendingSkycell).
+
+
+### Setups
+if ($?network == 0)
+  $network = 1
+end
+if ($?parallel == 0)
+  $parallel = 0
+end
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+
+$LOGSUBDIR = $LOGDIR/stack
+exec mkdir -p $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init stackPendingSkycell
+
+### Database lists
+$stackSkycell_DB = 0
+
+### Check status of stacking tasks
+macro stack.status
+  book listbook stackPendingSkycell
+end
+
+### Reset stacking tasks
+macro stack.reset
+  book init stackPendingSkycell
+end
+
+### Turn stacking tasks on
+macro stack.on
+  task stack.skycell.load
+    active true
+  end
+  task stack.skycell.run
+    active true
+  end
+end
+
+### Turn stacking tasks off
+macro stack.off
+  task stack.skycell.load
+    active false
+  end
+  task stack.skycell.run
+    active false
+  end
+end
+
+
+### Load tasks for doing the stack
+### Tasks are loaded into stackPendingSkycell.
+task	       stack.skycell.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/stack.skycell.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command stacktool -tostacked -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$stackSkycell_DB
+      command stacktool -tostackskyfile -limit 20 -dbname $DB:$stackSkycell_DB
+      $stackSkycell_DB ++
+      if ($stackSkycell_DB >= $DB:n) set stackSkycell_DB = 0
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout stackPendingSkycell -key stack_id -uniq -setword dbname $options:0
+    if ($VERBOSE > 2)
+      book listbook stackPendingSkycell
+    end
+
+    # delete existing entries in the appropriate states
+    process_cleanup stackPendingSkycell
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+### Run tasks for calculating the stack overlaps
+### Tasks are taken from stackPendingSkycell.
+task	       stack.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 60
+
+  task.exec
+    book npages stackPendingSkycell -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in stackPendingSkycell (state == NULL)
+    book getpage stackPendingSkycell 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword stackPendingSkycell $pageName state RUN
+    book getword stackPendingSkycell $pageName stack_id -var STACK_ID
+    book getword stackPendingSkycell $pageName camera -var CAMERA
+    book getword stackPendingSkycell $pageName workdir -var WORKDIR
+    book getword stackPendingSkycell $pageName dbname -var DBNAME
+    set_standard_args
+
+    # specify choice of remote host
+    # XXX need to choose based on stacks
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/stack$STACK_ID
+    $logfile = $outroot/skycell.log
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $outroot
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command stack_skycell.pl --stack_id $STACK_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+    end
+    command stack_skycell.pl --stack_id $STACK_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit stackPendingSkycell $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword stackPendingSkycell $options:0 state TIMEOUT
+  end
+end
+
