Index: /trunk/ippTasks/survey.pro
===================================================================
--- /trunk/ippTasks/survey.pro	(revision 28834)
+++ /trunk/ippTasks/survey.pro	(revision 28835)
@@ -30,4 +30,6 @@
  book create SURVEY_DIST
  book create SURVEY_ADDSTAR   
+ book create SURVEY_CHIP_BG
+ book create SURVEY_WARP_BG
  $haveSurveyBooks = TRUE
 end
@@ -40,4 +42,6 @@
 $SURVEY_DIST_DB = 0
 $SURVEY_ADDSTAR_DB = 0
+$SURVEY_CHIP_BG_DB = 0
+$SURVEY_WARP_BG_DB = 0
 
 $SURVEY_EXEC = 120
@@ -67,4 +71,10 @@
     active true
   end
+  task survey.chip.bg
+    active true
+  end
+  task survey.warp.bg
+    active true
+  end
 end
 
@@ -89,4 +99,10 @@
   end
   task survey.dist
+    active false
+  end
+  task survey.chip.bg
+    active false
+  end
+  task survey.warp.bg
     active false
   end
@@ -286,4 +302,57 @@
 end
 
+# user functions to manipulate chip_bg labels
+macro survey.add.chip.bg
+  if ($0 != 3)
+    echo "USAGE: survey.add.chip.bg (label) (dist_group)"
+    break
+  end
+  book newpage SURVEY_CHIP_BG $1
+  book setword SURVEY_CHIP_BG $1 DIST_GROUP $2
+  book setword SURVEY_CHIP_BG $1 STATE PENDING
+end
+
+macro survey.del.chip.bg
+  if ($0 != 2)
+    echo "USAGE: survey.del.chip.bg (label)"
+    break
+  end
+  book delpage SURVEY_CHIP_BG $1
+end
+
+macro survey.show.chip.bg
+  if ($0 != 1)
+    echo "USAGE: survey.show.chip.bg"
+    break
+  end
+  book listbook SURVEY_CHIP_BG
+end
+
+# user functions to manipulate warp_bg labels
+macro survey.add.warp.bg
+  if ($0 != 3)
+    echo "USAGE: survey.add.warp.bg (label) (dist_group)"
+    break
+  end
+  book newpage SURVEY_WARP_BG $1
+  book setword SURVEY_WARP_BG $1 DIST_GROUP $2
+  book setword SURVEY_WARP_BG $1 STATE PENDING
+end
+
+macro survey.del.warp.bg
+  if ($0 != 2)
+    echo "USAGE: survey.del.warp.bg (label)"
+    break
+  end
+  book delpage SURVEY_WARP_BG $1
+end
+
+macro survey.show.warp.bg
+  if ($0 != 1)
+    echo "USAGE: survey.show.warp.bg"
+    break
+  end
+  book listbook SURVEY_WARP_BG
+end
 
 task survey.diff
@@ -815,2 +884,142 @@
   end
 end
+
+task survey.chip.bg
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  stdout $LOGDIR/survey.chip.bg.log
+  stderr $LOGDIR/survey.chip.bg.log
+
+  # generate chip_bg runs
+  task.exec
+    book npages SURVEY_CHIP_BG -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_CHIP_BG 0 -var label -key STATE NEW
+    if ("$label" == "NULL")
+      # All labels have been done --- reset
+#      echo "Resetting labels"
+      for i 0 $N
+        book getpage SURVEY_CHIP_BG $i -var label
+	book setword SURVEY_CHIP_BG $label STATE NEW
+      end
+      book getpage SURVEY_CHIP_BG 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_CHIP_BG ++
+      if ($SURVEY_CHIP_BG >= $DB:n) set SURVEY_CHIP_BG = 0
+    end
+
+    book setword SURVEY_CHIP_BG $label STATE DONE
+    book getword SURVEY_CHIP_BG $label DIST_GROUP -var dist_group
+  
+    $run = bgtool -definechip -label $label -set_dist_group $dist_group
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run -dbname $DB:$SURVEY_CHIP_BG
+      option $DB:$SURVEY_CHIP_BG
+    end
+    
+    echo $run
+    command $run
+  end
+
+  # success
+  task.exit    0
+#    echo "Success"
+  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 survey.warp.bg
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  stdout $LOGDIR/survey.warp.bg.log
+  stderr $LOGDIR/survey.warp.bg.log
+
+  # generate warp_bg runs
+  task.exec
+    book npages SURVEY_WARP_BG -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_WARP_BG 0 -var label -key STATE NEW
+    if ("$label" == "NULL")
+      # All labels have been done --- reset
+#      echo "Resetting labels"
+      for i 0 $N
+        book getpage SURVEY_WARP_BG $i -var label
+	book setword SURVEY_WARP_BG $label STATE NEW
+      end
+      book getpage SURVEY_WARP_BG 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_WARP_BG ++
+      if ($SURVEY_WARP_BG >= $DB:n) set SURVEY_WARP_BG = 0
+    end
+
+    book setword SURVEY_WARP_BG $label STATE DONE
+    book getword SURVEY_WARP_BG $label DIST_GROUP -var dist_group
+  
+    $run = bgtool -definewarp -warp_label $label -set_dist_group $dist_group
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run -dbname $DB:$SURVEY_WARP_BG
+      option $DB:$SURVEY_WARP_BG
+    end
+    
+    echo $run
+    command $run
+  end
+
+  # success
+  task.exit    0
+#    echo "Success"
+  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
