Index: trunk/ippTasks/Makefile.am
===================================================================
--- trunk/ippTasks/Makefile.am	(revision 36647)
+++ trunk/ippTasks/Makefile.am	(revision 36852)
@@ -49,4 +49,5 @@
 	vp.pro \
 	bg.regeneration.pro \
+	remote.pro \
 	fullforce.pro
 
Index: trunk/ippTasks/remote.pro
===================================================================
--- trunk/ippTasks/remote.pro	(revision 36852)
+++ trunk/ippTasks/remote.pro	(revision 36852)
@@ -0,0 +1,379 @@
+## remote.pro : -*- sh -*-
+
+check.globals
+
+# define chips
+
+book init remotePrepRuns
+book init remoteExecRuns
+book init remotePollRuns
+
+$remote_label_iter = 0
+$remote_stage_iter = 0
+$remoteP_DB = 0
+$remoteE_DB = 0
+$remoteL_DB = 0
+
+list STAGES
+  chip
+  camera
+  warp
+  stack
+end
+
+task          remote.define.chip
+  host        local
+  periods     -poll $LOADPOLL
+  periods     -exec $LOADEXEC
+  periods     -timeout 30
+  npending    1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.define.chip
+
+    $label = $LABEL:$remote_label_iter
+
+    $stage = $STAGES:$remote_stage_iter
+    $remote_stage_iter ++
+
+    if ($remote_stage_iter >= $STAGES:n) 
+       set remote_stage_iter = 0
+       $remote_label_iter ++
+       if ($remote_label_iter >= $LABEL:n) set remote_label_iter = 0
+       echo $remote_stage_iter $remote_label_iter $label $stage
+    end
+
+    $run = remotetool -definebyquery -label $label -stage $stage -path_base neb://@HOST@.0/remote/$label
+    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
+
+
+task         remote.prep.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.prep.load
+
+    $run = remotetool -listrun -state new
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteP_DB
+      $run = $run -dbname $DB:$remoteP_DB
+      $remoteP_DB ++
+      if ($remoteP_DB >= $DB:n) set remoteP_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remotePrepRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remotePrepRuns
+
+    if ($VERBOSE > 2)
+      book listbook remotePrepRuns
+    end
+  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
+
+task           remote.prep.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     10
+
+  task.exec
+    stdout $LOGDIR/remote.prep.run
+    stderr $LOGDIR/remote.prep.run
+
+    book npages remotePrepRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remotePrepRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remotePrepRuns $pageName pantaskState RUN
+    book getword remotePrepRuns $pageName remote_id -var REMOTE_ID
+    book getword remotePrepRuns $pageName stage     -var STAGE
+    book getword remotePrepRuns $pageName path_base -var PATH_BASE
+#    book getword remotePrepRuns $pageName label     -var LABEL
+    book getword remotePrepRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    if ("$STAGE" == "chip")
+      $command = sc_prepare_chip.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "camera")
+      $command = sc_prepare_camera.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "warp")
+      $command = sc_prepare_warp.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+    if ("$STAGE" == "stack")
+      $command = sc_prepare_stack.pl --camera GPC1 --remote_id $REMOTE_ID --path_base $outroot --dbname $DBNAME
+    end
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remotePrepRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remotePrepRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remotePrepRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task         remote.exec.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.exec.load
+
+#    $end_date = `date +%Y-%m-%dT%H:%M:%S`
+    $run = remotetool -listrun -state pending 
+# -poll_end $end_date
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteE_DB
+      $run = $run -dbname $DB:$remoteE_DB
+      $remoteE_DB ++
+      if ($remoteE_DB >= $DB:n) set remoteE_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remoteExecRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remoteExecRuns
+
+    if ($VERBOSE > 2)
+      book listbook remoteExecRuns
+    end
+  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
+
+task           remote.exec.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     1
+
+  task.exec
+    stdout $LOGDIR/remote.exec.run
+    stderr $LOGDIR/remote.exec.run
+
+    book npages remoteExecRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remoteExecRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remoteExecRuns $pageName pantaskState RUN
+    book getword remoteExecRuns $pageName remote_id -var REMOTE_ID
+    book getword remoteExecRuns $pageName stage     -var STAGE
+    book getword remoteExecRuns $pageName path_base -var PATH_BASE
+#    book getword remoteExecRuns $pageName label     -var LABEL
+    book getword remoteExecRuns $pageName job_id    -var JOB_ID
+    book getword remoteExecRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    $command = sc_remote_exec.pl --remote_id $REMOTE_ID --path_base $outroot --verbose --dbname $DBNAME --camera GPC1
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remoteExecRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remoteExecRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remoteExecRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task         remote.poll.load
+  host       local
+  periods    -poll $LOADPOLL
+  periods    -exec $LOADEXEC
+  npending   1
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/remote.poll.load
+
+    $end_date = `date +%Y-%m-%dT%H:%M:%S -d '1 hour ago'`
+    $run = remotetool -listrun -state run -poll_end $end_date
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$remoteL_DB
+      $run = $run -dbname $DB:$remoteL_DB
+      $remoteL_DB ++
+      if ($remoteL_DB >= $DB:n) set remoteL_DB = 0
+    end
+
+    add_poll_labels run
+    command $run
+  end
+  # success
+  task.exit  0
+    ipptool2book stdout remotePollRuns -uniq -key remote_id -setword dbname $options:0 -setword pantaskState INIT
+    process_cleanup remotePollRuns
+
+    if ($VERBOSE > 2)
+      book listbook remotePollRuns
+    end
+  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
+
+task           remote.poll.run
+  # this probably shouldn't be local
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 60000
+  active       true
+  npending     1
+
+  task.exec
+    stdout $LOGDIR/remote.poll.run
+    stderr $LOGDIR/remote.poll.run
+
+    book npages remotePollRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    book getpage remotePollRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword remotePollRuns $pageName pantaskState RUN
+    book getword remotePollRuns $pageName remote_id -var REMOTE_ID
+    book getword remotePollRuns $pageName stage     -var STAGE
+    book getword remotePollRuns $pageName path_base -var PATH_BASE
+#    book getword remotePollRuns $pageName label     -var LABEL
+    book getword remotePollRuns $pageName job_id    -var JOB_ID
+    book getword remotePollRuns $pageName dbname    -var DBNAME
+
+    sprintf outroot "%s/remote_%s.%s" $PATH_BASE $STAGE $REMOTE_ID
+
+    # This can't have an invalid job_id
+    if ($JOB_ID == -1) break
+    $command = sc_remote_exec.pl --remote_id $REMOTE_ID --path_base $outroot --verbose --dbname $DBNAME --camera GPC1 --poll --job_id $JOB_ID
+
+    options $pageName
+    command $command
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit remotePollRuns $options:0 $JOB_STATUS
+  end
+  # locked list
+  task.exit    crash
+    process_exit remotePollRuns $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword remotePollRuns $options:0 pantaskState TIMEOUT
+  end
+end
+
