Index: branches/eam_branches/ipp-20130307/ippTasks/addstar.pro
===================================================================
--- branches/eam_branches/ipp-20130307/ippTasks/addstar.pro	(revision 35267)
+++ branches/eam_branches/ipp-20130307/ippTasks/addstar.pro	(revision 35350)
@@ -6,4 +6,9 @@
 check.globals
 
+
+if ($?ADDSTAGES:n == 0)       set ADDSTAGES:n = 0
+
+
+
 book init addPendingExp
 
@@ -17,14 +22,5 @@
 
 macro addstar.on
-  task addstar.exp.load.stack
-    active true
-  end
-  task addstar.exp.load.cam
-    active true
-  end
-  task addstar.exp.load.staticsky
-    active true  
-  end
-  task addstar.exp.load.skycal
+  task addstar.exp.load
     active true
   end
@@ -35,14 +31,5 @@
 
 macro addstar.off
-  task addstar.exp.load.stack
-    active false
-  end
-  task addstar.exp.load.cam
-    active false
-  end
-  task addstar.exp.load.staticsky
-    active false
-  end
-  task addstar.exp.load.skycal
+  task addstar.exp.load
     active false
   end
@@ -83,6 +70,69 @@
 
 
+#addstar stages
+
+macro add.addstages
+  if ($0 != 2)
+    echo "USAGE: add.addstages (addstages)"
+    break
+  end
+  if ($?ADDSTAGES:n == 0)
+    list ADDSTAGES -add $1
+    return
+  end
+
+  local found
+  $found = 0
+  for i 0 $ADDSTAGES:n
+    if ($ADDSTAGES:$i == $1) 
+      $found = 1
+      echo "$ADDSTAGES:$i set"
+      last
+    end
+  end
+  
+  if ($found == 0)
+    list ADDSTAGES -add $1
+  end
+end
+
+macro del.addstages
+  if ($0 != 2)
+    echo "USAGE: del.addstages (addstages)"
+    break
+  end
+  if ($?ADDSTAGES:n == 0)
+    return
+  end
+
+  list ADDSTAGES -del $1
+end
+
+macro show.addstages
+  if ($0 != 1)
+    echo "USAGE: show.addstages"
+    break
+  end
+  if ($?ADDSTAGES:n == 0)
+    echo "no addstar stages defined"
+  end
+  if ($ADDSTAGES:n == 0)
+    echo "no addstar stages defined"
+  end
+
+  local i
+  for i 0 $ADDSTAGES:n
+    echo $ADDSTAGES:$i
+  end
+end
+
+macro stuff
+   echo $LOADEXEC_ADD
+   echo $LOADPOLL
+end
+
 # this variable will cycle through the known database names
 $addstar_DB = 0 
+$addstar_stages_DB = 0
 #this may not work for more databases (addstar) will do that later)
 $addstar_revert_DB_C = 0
@@ -92,6 +142,6 @@
 $addstar_revert_DB_SC = 0 
 
-$LOADEXEX_ADD = 300
-
+#$LOADEXEC_ADD = 300
+$LOADEXEC_ADD = 10
 
 
@@ -99,5 +149,5 @@
 # new entries are added to addPendingExp
 # skip already-present entries
-task	       addstar.exp.load.stack
+task	       addstar.exp.load
   host         local
 
@@ -111,17 +161,24 @@
 
   task.exec
-   # if ($LABEL:n == 0) break
-    $run = addtool -pendingexp -stage stack
-    if ($DB:n == 0)
-      option DEFAULT
-    else
-      # save the DB name for the exit tasks
-      option $DB:$addstar_DB
-      $run = $run -dbname $DB:$addstar_DB
-      $addstar_DB ++
-      if ($addstar_DB >= $DB:n) set addstar_DB = 0
-    end
+    #if no stages defined we can't run
+    if ($ADDSTAGES:n == 0) echo "what" 
+ #   if ($ADDSTAGES:n == 0) break
+    $run = addtool -pendingexp
+    
+    #option $ADDSTAGES:$addstar_stages_DB
+    $run = $run -stage $ADDSTAGES:$addstar_stages_DB  
+    option $DB:$addstar_DB
+    $run = $run -dbname $DB:$addstar_DB
+    $addstar_stages_DB ++
+      if ($addstar_stages_DB >= $ADDSTAGES:n)
+         set addstar_stages_DB = 0
+         $addstar_DB ++
+         if ($addstar_DB >= $DB:n) set addstar_DB = 0
+         #go to next stage. if run out of stages, go to 0 stage and
+         #cycle through dbname, if run out of dbnames, go to 0 dbname
+      end
     add_poll_args run
     add_poll_labels run
+    echo $run
     command $run
   end
@@ -153,168 +210,4 @@
   end
 end
-
-task	       addstar.exp.load.cam
-  host         local
-
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC_ADD
-  periods      -timeout 300
-  npending     1
-
-  stdout NULL
-  stderr $LOGDIR/addstar.exp.log
-
-  task.exec
-   # if ($LABEL:n == 0) break
-    $run = addtool -pendingexp -stage cam
-    if ($DB:n == 0)
-      option DEFAULT
-    else
-      # save the DB name for the exit tasks
-      option $DB:$addstar_DB
-      $run = $run -dbname $DB:$addstar_DB
-      $addstar_DB ++
-      if ($addstar_DB >= $DB:n) set addstar_DB = 0
-    end
-    add_poll_args run
-    add_poll_labels run
-    command $run
-  end
-
-  # success
-  task.exit    0
-    # convert 'stdout' to book format
-    ipptool2book stdout addPendingExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
-    if ($VERBOSE > 2)
-      book listbook addPendingExp
-    end
-
-    # delete existing entries in the appropriate pantaskStates
-    process_cleanup addPendingExp
-  end
-
-  # default exit status
-  task.exit    default
-    showcommand failure
-  end
-
-  task.exit    crash
-    showcommand crash
-  end
-
-  # operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-task	       addstar.exp.load.staticsky
-  host         local
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC_ADD
-  periods      -timeout 300
-  npending     1
-
-  stdout NULL
-  stderr $LOGDIR/addstar.exp.log
-
-  task.exec
-   # if ($LABEL:n == 0) break
-    $run = addtool -pendingexp -stage staticsky
-    if ($DB:n == 0)
-      option DEFAULT
-    else
-      # save the DB name for the exit tasks
-      option $DB:$addstar_DB
-      $run = $run -dbname $DB:$addstar_DB
-      $addstar_DB ++
-      if ($addstar_DB >= $DB:n) set addstar_DB = 0
-    end
-    add_poll_args run
-    add_poll_labels run
-    command $run
-  end
-
-  # success
-  task.exit    0
-    # convert 'stdout' to book format
-    ipptool2book stdout addPendingExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
-    if ($VERBOSE > 2)
-      book listbook addPendingExp
-    end
-
-    # delete existing entries in the appropriate pantaskStates
-    process_cleanup addPendingExp
-  end
-
-  # default exit status
-  task.exit    default
-    showcommand failure
-  end
-
-  task.exit    crash
-    showcommand crash
-  end
-
-  # operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-task           addstar.exp.load.skycal
-  host         local
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC_ADD
-  periods      -timeout 300
-  npending     1
-
-  stdout NULL
-  stderr $LOGDIR/addstar.exp.log
-
-  task.exec
-   # if ($LABEL:n == 0) break                                                                                 
-    $run = addtool -pendingexp -stage skycal
-    if ($DB:n == 0)
-      option DEFAULT
-    else
-      # save the DB name for the exit tasks                                                                   
-      option $DB:$addstar_DB
-      $run = $run -dbname $DB:$addstar_DB
-      $addstar_DB ++
-      if ($addstar_DB >= $DB:n) set addstar_DB = 0
-    end
-    add_poll_args run
-    add_poll_labels run
-    command $run
-  end
-
-  # success                                                                                                   
-  task.exit    0
-    # convert 'stdout' to book format                                                                         
-    ipptool2book stdout addPendingExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
-    if ($VERBOSE > 2)
-      book listbook addPendingExp
-    end
-
-    # delete existing entries in the appropriate pantaskStates                                                
-    process_cleanup addPendingExp
-  end
-
-  # default exit status                                                                                       
-  task.exit    default
-    showcommand failure
-  end
-
-  task.exit    crash
-    showcommand crash
-  end
-
-  # operation times out?                                                                                      
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
 
 # run the addstar script on pending exposures
Index: branches/eam_branches/ipp-20130307/ippTasks/lapgroup.pro
===================================================================
--- branches/eam_branches/ipp-20130307/ippTasks/lapgroup.pro	(revision 35350)
+++ branches/eam_branches/ipp-20130307/ippTasks/lapgroup.pro	(revision 35350)
@@ -0,0 +1,161 @@
+## lapgroup.pro : tasks for lap group management : -*- sh -*-
+
+# test for required global variables
+check.globals
+
+$LOGSUBDIR = $LOGDIR/lapgroup
+mkdir $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init pendinglapGroup
+
+### Database lists
+$lapgroup_DB = 0
+
+### Check status of lapgroup tasks
+macro lapgroup.status
+  book listbook pendinglapGroup
+end
+
+### Reset lapgroup tasks
+macro lapgroup.reset
+  book init pendinglapGroup
+end
+
+### Turn lapgroup tasks on
+macro lapgroup.on
+  task lapgroup.load
+    active true
+  end
+  task lapgroup.run
+    active true
+  end
+end
+
+### Turn lapgroup tasks off
+macro lapgroup.off
+  task lapgroup.load
+    active false
+  end
+  task lapgroup.run
+    active false
+  end
+end
+
+### Load jobs for lapGroup
+### Tasks are loaded into pendinglapGroup.
+task	       lapgroup.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec 30
+  periods      -timeout 60
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/lapgroup.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    $run = laptool -pendinggroup
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$lapgroup_DB
+      $run = $run -dbname $DB:$lapgroup_DB
+      $lapgroup_DB ++
+      if ($lapgroup_DB >= $DB:n) set lapgroup_DB = 0
+    end
+    add_poll_args run
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout pendinglapGroup -key seq_id:tess_id:projection_cell -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook pendinglapGroup
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup pendinglapGroup
+  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	       lapgroup.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 120
+  npending     1
+
+  task.exec
+    book npages pendinglapGroup -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    # look for new entries in pendinglapGroup (pantaskState == INIT)
+    book getpage pendinglapGroup 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword pendinglapGroup $pageName pantaskState RUN
+    book getword pendinglapGroup $pageName seq_id -var SEQ_ID
+    book getword pendinglapGroup $pageName tess_id -var TESS_ID
+    book getword pendinglapGroup $pageName projection_cell -var PROJECTION_CELL
+    book getword pendinglapGroup $pageName label -var LABEL
+    book getword pendinglapGroup $pageName dist_group -var DIST_GROUP
+    book getword pendinglapGroup $pageName dbname -var DBNAME
+
+    stdout $LOGSUBDIR/lapgroup.log
+    stderr $LOGSUBDIR/lapgroup.log
+
+    host anyhost
+
+    $run = queuestaticsky.pl --seq_id $SEQ_ID --tess_id $TESS_ID --projection_cell $PROJECTION_CELL --label $LABEL --dist_group $DIST_GROUP
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit pendinglapGroup $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    showcommand crash
+    echo "hostname: $JOB_HOSTNAME"
+    book setword pendinglapGroup $options:0 pantaskState CRASH
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword pendinglapGroup $options:0 pantaskState TIMEOUT
+  end
+end
+
Index: branches/eam_branches/ipp-20130307/ippTasks/minidvodb.pro
===================================================================
--- branches/eam_branches/ipp-20130307/ippTasks/minidvodb.pro	(revision 35267)
+++ branches/eam_branches/ipp-20130307/ippTasks/minidvodb.pro	(revision 35350)
@@ -145,4 +145,5 @@
   book setword MINIDVODB_PREMERGE $1 MINIDVODB_GROUP $1
   book setword MINIDVODB_PREMERGE $1 DVODB $3
+  book setword MINIDVODB_PREMERGE $1 CAMERA $5
   book setword MINIDVODB_PREMERGE $1 STATE PENDING
   #active  
@@ -443,9 +444,10 @@
     book getword minidvodbPreMergelist $pageName minidvodb_group -var MINIDVODB_GROUP
     book getword minidvodbPreMergelist $pageName minidvodb_path -var MINIDVODB_PATH
+    book getword minidvodbPreMergelist $pageName camera -var CAMERA
     book getword minidvodbPreMergelist $pageName state -var STATE
     stdout $LOGDIR/minidvodb.premerge.run.log
     stderr $LOGDIR/minidvodb.premerge.run.log
 
-    $run = minidvodb_premerge.pl --camera GPC1 --minidvodb $MINIDVODB_PATH --minidvodb_group $MINIDVODB_GROUP --minidvodb_id $MINIDVODB_ID
+    $run = minidvodb_premerge.pl --camera $CAMERA --minidvodb $MINIDVODB_PATH --minidvodb_group $MINIDVODB_GROUP --minidvodb_id $MINIDVODB_ID
     
   if ($DB:n == 0)
Index: branches/eam_branches/ipp-20130307/ippTasks/release.pro
===================================================================
--- branches/eam_branches/ipp-20130307/ippTasks/release.pro	(revision 35350)
+++ branches/eam_branches/ipp-20130307/ippTasks/release.pro	(revision 35350)
@@ -0,0 +1,167 @@
+## release.pro : tasks for release management : -*- sh -*-
+
+# test for required global variables
+check.globals
+
+$LOGSUBDIR = $LOGDIR/release
+mkdir $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init pendingrelGroup
+
+### Database lists
+$relgroup_DB = 0
+
+### Check status of release tasks
+macro release.status
+  book listbook pendingrelGroup
+end
+
+### Reset release tasks
+macro release.reset
+  book init pendingrelgroup
+end
+
+### Turn release tasks on
+macro release.on
+  task relgroup.load
+    active true
+  end
+  task relgroup.run
+    active true
+  end
+end
+
+### Turn release tasks off
+macro release.off
+  task relgroup.load
+    active false
+  end
+  task relgroup.run
+    active false
+  end
+end
+
+### Load jobs for relGroup
+### Tasks are loaded into pendingrelGroup.
+task	       relgroup.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec 30
+  periods      -timeout 60
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/relgroup.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    $run = releasetool -pendingrelgroup
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$relgroup_DB
+      $run = $run -dbname $DB:$relgroup_DB
+      $relgroup_DB ++
+      if ($relgroup_DB >= $DB:n) set relgroup_DB = 0
+    end
+    add_poll_args run
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout pendingrelGroup -key group_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook pendingrelGroup
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup pendingrelGroup
+  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	       relgroup.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 120
+  npending     1
+
+  task.exec
+    book npages pendingrelGroup -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+    # look for new entries in pendingrelGroup (pantaskState == INIT)
+    book getpage pendingrelGroup 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword pendingrelGroup $pageName pantaskState RUN
+    book getword pendingrelGroup $pageName group_id -var GROUP_ID
+    book getword pendingrelGroup $pageName rel_id -var REL_ID
+    book getword pendingrelGroup $pageName group_type -var GROUP_TYPE
+    book getword pendingrelGroup $pageName lap_id -var LAP_ID
+    book getword pendingrelGroup $pageName group_name -var GROUP_NAME
+    book getword pendingrelGroup $pageName release_name -var RELEASE_NAME
+    book getword pendingrelGroup $pageName dbname -var DBNAME
+
+    stdout $LOGSUBDIR/relgroup.log
+    stderr $LOGSUBDIR/relgroup.log
+
+    host anyhost
+
+    $run = relgroup_exp_list.pl --group_id $GROUP_ID --group_type $GROUP_TYPE --release_name $RELEASE_NAME
+    if ("$GROUP_TYPE" == "lap") 
+        $run = $run --lap_id $LAP_ID
+    else 
+        $run = $run --group_name $GROUP_NAME
+    end
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit pendingrelGroup $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    showcommand crash
+    echo "hostname: $JOB_HOSTNAME"
+    book setword pendingrelGroup $options:0 pantaskState CRASH
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword pendingrelGroup $options:0 pantaskState TIMEOUT
+  end
+end
+
Index: branches/eam_branches/ipp-20130307/ippTasks/survey.pro
===================================================================
--- branches/eam_branches/ipp-20130307/ippTasks/survey.pro	(revision 35267)
+++ branches/eam_branches/ipp-20130307/ippTasks/survey.pro	(revision 35350)
@@ -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
