Index: trunk/ippTasks/survey.pro
===================================================================
--- trunk/ippTasks/survey.pro	(revision 26028)
+++ trunk/ippTasks/survey.pro	(revision 26030)
@@ -12,7 +12,17 @@
   book create SURVEY_MAGIC
 end
+book getbook SURVEY_DESTREAK -var isBook
+if ("$isBook" == "NULL")
+  book create SURVEY_DESTREAK
+end
+book getbook SURVEY_DIST -var isBook
+if ("$isBook" == "NULL")
+  book create SURVEY_DIST
+end
 
 $SURVEY_DIFF_DB = 0
 $SURVEY_MAGIC_DB = 0
+$SURVEY_DESTREAK_DB = 0
+$SURVEY_DIST_DB = 0
 
 $SURVEY_EXEC = 120
@@ -74,4 +84,57 @@
   end
   book listbook SURVEY_MAGIC
+end
+
+# user functions to manipulate destreak labels
+macro survey.add.destreak
+  if ($0 != 3)
+    echo "USAGE: survey.add.destreak (label) (workdir base)"
+    break
+  end
+  book newpage SURVEY_DESTREAK $1
+  book setword SURVEY_DESTREAK $1 WORKDIR $2
+  book setword SURVEY_DESTREAK $1 STATE PENDING
+end
+
+macro survey.del.destreak
+  if ($0 != 2)
+    echo "USAGE: survey.del.destreak (label)"
+    break
+  end
+  book delpage SURVEY_DESTREAK $1
+end
+
+macro survey.show.destreak
+  if ($0 != 1)
+    echo "USAGE: survey.show.destreak"
+    break
+  end
+  book listbook SURVEY_DESTREAK
+end
+
+# user functions to manipulate dist labels
+macro survey.add.dist
+  if ($0 != 2)
+    echo "USAGE: survey.add.dist (label)"
+    break
+  end
+  book newpage SURVEY_DIST $1
+  book setword SURVEY_DIST $1 STATE PENDING
+end
+
+macro survey.del.dist
+  if ($0 != 2)
+    echo "USAGE: survey.del.dist (label)"
+    break
+  end
+  book delpage SURVEY_DIST $1
+end
+
+macro survey.show.dist
+  if ($0 != 1)
+    echo "USAGE: survey.show.dist"
+    break
+  end
+  book listbook SURVEY_DIST
 end
 
@@ -229,2 +292,147 @@
 end
 
+task survey.destreak
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  active false
+
+  stdout $LOGDIR/survey.destreak.log
+  stderr $LOGDIR/survey.destreak.log
+
+  # generate destreak runs
+  task.exec
+    book npages SURVEY_DESTREAK -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_DESTREAK 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_DESTREAK $i -var label
+	book setword SURVEY_DESTREAK $label STATE NEW
+      end
+      book getpage SURVEY_DESTREAK 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_DESTREAK_DB ++
+      if ($SURVEY_DESTREAK_DB >= $DB:n)
+        set $SURVEY_DESTREAK_DB = 0
+      end
+    end
+
+    book setword SURVEY_DESTREAK $label STATE DONE
+    book getword SURVEY_DESTREAK $label WORKDIR -var workdir
+  
+    $run = magic_destreak_defineruns.pl --label $label --workdir $workdir/$label/
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run -dbname $DB:$SURVEY_MAGIC_DB
+      option $DB:$SURVEY_MAGIC_DB
+    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.dist
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  stdout $LOGDIR/survey.dist.log
+  stderr $LOGDIR/survey.dist.log
+
+  # generate distribution runs
+  task.exec
+    book npages SURVEY_DIST -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_DIST 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_DIST $i -var label
+	book setword SURVEY_DIST $label STATE NEW
+      end
+      book getpage SURVEY_DIST 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_DIST_DB ++
+      if ($SURVEY_DIST_DB >= $DB:n)
+        set $SURVEY_DIST_DB = 0
+      end
+    end
+
+    book setword SURVEY_DIST $label STATE DONE
+  
+    # note workdir is set by the script based on site.config
+    $run = dist_defineruns.pl --label $label
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run --dbname $DB:$SURVEY_DIST_DB
+      option $DB:$SURVEY_DIST_DB
+    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
