Index: /trunk/ippTasks/warp.pro
===================================================================
--- /trunk/ippTasks/warp.pro	(revision 12074)
+++ /trunk/ippTasks/warp.pro	(revision 12074)
@@ -0,0 +1,302 @@
+### This file contains panTasks definitions for performing the image warping.
+
+### This is done in two (main) steps.  After a warp (with associated warp_id) is defined,
+### overlaps between the exposure being warped and skycells are calculated (tasks in warpPendingExp).
+### Then for each skycell, the warp is made (tasks in warpPendingSkycell).
+
+
+### 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/warp
+exec mkdir -p $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init warpPendingExp
+book init warpPendingSkycell
+
+### Database lists
+$warpExp_DB = 0
+$warpSkycell_DB = 0
+
+### Check status of warping tasks
+macro warp.status
+  book listbook warpPendingExp
+  book listbook warpPendingSkycell
+end
+
+### Reset warping tasks
+macro warp.reset
+  book init warpPendingExp
+  book init warpPendingSkycell
+end
+
+### Turn warping tasks on
+macro warp.on
+  task warp.exp.load
+    active true
+  end
+  task warp.exp.run
+    active true
+  end
+  task warp.skycell.load
+    active true
+  end
+  task warp.skycell.run
+    active true
+  end
+end
+
+### Turn warping tasks off
+macro warp.off
+  task warp.exp.load
+    active false
+  end
+  task warp.exp.run
+    active false
+  end
+  task warp.skycell.load
+    active false
+  end
+  task warp.skycell.run
+    active false
+  end
+end
+
+### Load tasks for calculating the warp overlaps
+### Tasks are loaded into warpPendingExp.
+task	       warp.exp.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/warp.exp.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command warptool -tooverlap -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$warpExp_DB
+      command warptool -tooverlap -limit 20 -dbname $DB:$warpExp_DB
+      $warpExp_DB ++
+      if ($warpExp_DB >= $DB:n) set warpExp_DB = 0
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout warpPendingExp -key warp_id -uniq -setword dbname $options:0
+    if ($VERBOSE > 2)
+      book listbook warpPendingExp
+    end
+
+    # delete existing entries in the appropriate states
+    process_cleanup warpPendingExp
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+### Run tasks for calculating the warp overlaps
+### Tasks are taken from warpPendingExp.
+task	       warp.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 60
+
+  task.exec
+    book npages warpPendingExp -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in warpPendingExp (state == NULL)
+    book getpage warpPendingExp 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword warpPendingExp $pageName state RUN
+    book getword warpPendingExp $pageName warp_id -var WARP_ID
+    book getword warpPendingExp $pageName camera -var CAMERA
+    book getword warpPendingExp $pageName workdir -var WORKDIR
+    book getword warpPendingExp $pageName dbname -var DBNAME
+    set_standard_args
+
+    # specify choice of remote host
+    # XXX need to choose based on warps
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/warp$WARP_ID
+    $logfile = $outroot/overlap.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 warp_overlap.pl --warp_id $WARP_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+    end
+    command warp_imfile.pl --warp_id $WARP_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit warpPendingExp $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword warpPendingExp $options:0 state TIMEOUT
+  end
+end
+
+
+### Load tasks for doing the warps
+### Tasks are loaded into warpPendingSkycell.
+task	       warp.skycell.load
+  host         local
+
+  periods      -poll $loadpoll
+  periods      -exec $loadexec
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/warp.skycell.log
+
+  task.exec
+    if ($DB:n == 0)
+      option DEFAULT
+      command warptool -towarped -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$warpSkycell_DB
+      command warptool -towarped -limit 20 -dbname $DB:$warpSkycell_DB
+      $warpSkycell_DB ++
+      if ($warpSkycell_DB >= $DB:n) set warpSkycell_DB = 0
+    end
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout warpPendingSkycell -key warp_id:skycell_id:tess_id -uniq -setword dbname $options:0
+    if ($VERBOSE > 2)
+      book listbook warpPendingSkycell
+    end
+
+    # delete existing entries in the appropriate states
+    process_cleanup warpPendingSkycell
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+### Run tasks for calculating the warp overlaps
+### Tasks are taken from warpPendingSkycell.
+task	       warp.exp.run
+  periods      -poll $runpoll
+  periods      -exec $runexec
+  periods      -timeout 60
+
+  task.exec
+    book npages warpPendingSkycell -var N
+    if ($N == 0) break
+    if ($network == 0) break
+    
+    # look for new images in warpPendingSkycell (state == NULL)
+    book getpage warpPendingSkycell 0 -var pageName -key state NULL
+    if ($pageName == NULL) break
+
+    book setword warpPendingSkycell $pageName state RUN
+    book getword warpPendingSkycell $pageName warp_id -var WARP_ID
+    book getword warpPendingSkycell $pageName skycell_id -var SKYCELL_ID
+    book getword warpPendingSkycell $pageName tess_id -var TESS_ID
+    book getword warpPendingSkycell $pageName exp_tag -var EXP_TAG
+    book getword warpPendingSkycell $pageName camera -var CAMERA
+    book getword warpPendingSkycell $pageName workdir -var WORKDIR
+    book getword warpPendingSkycell $pageName dbname -var DBNAME
+    set_standard_args
+
+    # specify choice of remote host
+    # XXX need to choose based on warps
+    if ($parallel)
+      host anyhost
+    else
+      host local
+    end
+
+    ## generate output log based on filerule
+    $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/warp$WARP_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 warp_skycell.pl --warp_id $WARP_ID --skycell_id $SKYCELL_ID --tess_id $TESS_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+    end
+    command warp_skycell.pl --warp_id $WARP_ID --skycell_id $SKYCELL_ID --tess_id $TESS_ID --camera $CAMERA --workdir $WORKDIR $ARGS
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit warpPendingSkycell $options:0 $JOB_STATUS
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword warpPendingSkycell $options:0 state TIMEOUT
+  end
+end
+
