Index: trunk/ippTasks/survey.pro
===================================================================
--- trunk/ippTasks/survey.pro	(revision 34976)
+++ trunk/ippTasks/survey.pro	(revision 35331)
@@ -18,4 +18,5 @@
  book create SURVEY_STATICSKYSINGLE 
  book create SURVEY_SKYCAL
+ book create SURVEY_LAPGROUP
  $haveSurveyBooks = TRUE
 end
@@ -33,4 +34,5 @@
 $SURVEY_PUBLISH_DB = 0
 $SURVEY_SKYCAL_DB = 0
+$SURVEY_LAPGROUP_DB = 0
 $SURVEY_STATICSKYSINGLE_DB = 0
 $SURVEY_EXEC = 120
@@ -78,4 +80,7 @@
     active true
   end
+  task survey.lapgroup
+    active true
+  end
 end
 
@@ -118,4 +123,7 @@
   end
   task survey.skycal
+    active false
+  end
+  task survey.lapgroup
     active false
   end
@@ -494,8 +502,35 @@
 macro survey.show.skycal
   if ($0 != 1)
-    echo "USAGE: survey.show.skyacl"
+    echo "USAGE: survey.show.skycal"
     break
   end
   book listbook SURVEY_SKYCAL
+end
+
+macro survey.add.lapgroup
+  if ($0 != 3)
+    echo "USAGE: survey.add.lapgroup (label) (seq_id)"
+    break
+  end
+  book newpage SURVEY_LAPGROUP $1
+  book setword SURVEY_LAPGROUP $1 LABEL $1
+  book setword SURVEY_LAPGROUP $1 SEQ_ID $2
+  book setword SURVEY_LAPGROUP $1 STATE PENDING
+end
+
+macro survey.del.lapgroup
+  if ($0 != 2)
+    echo "USAGE: survey.del.lapgroup (label)"
+    break
+  end
+  book delpage SURVEY_LAPGROUP $1
+end
+
+macro survey.show.lapgroup
+  if ($0 != 1)
+    echo "USAGE: survey.show.lapgroup"
+    break
+  end
+  book listbook SURVEY_LAPGROUP
 end
 
@@ -1561,2 +1596,72 @@
   end
 end
+
+task survey.lapgroup
+  host local
+ 
+  periods      -poll $SURVEY_POLL
+  periods      -exec $SURVEY_EXEC
+  periods      -timeout $SURVEY_TIMEOUT
+  npending     1
+
+  stdout $LOGDIR/survey.lapgroup.log
+  stderr $LOGDIR/survey.lapgroup.log
+
+  task.exec
+    book npages SURVEY_LAPGROUP -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage SURVEY_LAPGROUP 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_LAPGROUP $i -var label
+	book setword SURVEY_LAPGROUP $label STATE NEW
+      end
+      book getpage SURVEY_LAPGROUP 0 -var label -key STATE NEW
+
+      # Select different database
+      $SURVEY_LAPGROUP ++
+      if ($SURVEY_LAPGROUP >= $DB:n) set SURVEY_LAPGROUP = 0
+    end
+
+    book setword SURVEY_LAPGROUP $label STATE DONE
+    book getword SURVEY_LAPGROUP $label SEQ_ID -var SEQ_ID
+
+    # For now the list of filters
+    $run = laptool -definegroup -seq_id $SEQ_ID -set_label $label -filter g.00000 -filter r.00000 -filter i.00000 -filter z.00000 -filter y.00000
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      $run = $run -dbname $DB:$SURVEY_LAPGROUP_DB
+      option $DB:$SURVEY_LAPGROUP_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
