Index: trunk/ippTasks/addstar.pro
===================================================================
--- trunk/ippTasks/addstar.pro	(revision 38479)
+++ trunk/ippTasks/addstar.pro	(revision 38480)
@@ -8,17 +8,28 @@
 
 if ($?ADDSTAGES:n == 0)       set ADDSTAGES:n = 0
+if ($?MULTIADDSTAGES:n == 0)       set MULTIADDSTAGES:n = 0
 
 
 
 book init addPendingExp
-
+book init addPendingMultiExp
+
+    
 macro addstar.status
   book listbook addPendingExp
 end
 
+macro addstar.multi.status
+    book listbook addPendingMultiExp
+end    
+    
 macro addstar.reset
   book init addPendingExp
 end
 
+macro addstar.multi.reset
+  book init addPendingMultiExp
+end	
+    
 macro addstar.on
   task addstar.exp.load
@@ -27,5 +38,11 @@
   task addstar.exp.run
     active true
-  end
+    end
+  task addstar.multiexp.load
+    active true
+  end
+  task addstar.multiexp.run
+    active true
+  end    
 end
 
@@ -35,4 +52,10 @@
   end
   task addstar.exp.run
+    active false
+  end
+  task addstar.multiexp.load
+    active false
+  end
+  task addstar.multiexp.run
     active false
   end
@@ -109,4 +132,6 @@
 end
 
+
+    
 macro del.addstages
   if ($0 != 2)
@@ -139,4 +164,61 @@
 end
 
+macro add.multiaddstages
+  if ($0 != 2)
+    echo "USAGE: add.multiaddstages (multiaddstages)"
+    break
+  end
+  if ($?MULTIADDSTAGES:n == 0)
+    list MULTIADDSTAGES -add $1
+    return
+  end
+
+  local found
+  $found = 0
+  for i 0 $MULTIADDSTAGES:n
+    if ($MULTIADDSTAGES:$i == $1) 
+      $found = 1
+      echo "$MULTIADDSTAGES:$i set"
+      last
+    end
+  end
+  
+  if ($found == 0)
+    list MULTIADDSTAGES -add $1
+  end
+end
+
+
+    
+macro del.multiaddstages
+  if ($0 != 2)
+    echo "USAGE: del.multiaddstages (multiaddstages)"
+    break
+  end
+  if ($?MULTIADDSTAGES:n == 0)
+    return
+  end
+
+  list MULTIADDSTAGES -del $1
+end
+
+macro show.multiaddstages
+  if ($0 != 1)
+    echo "USAGE: show.multiaddstages"
+    break
+  end
+  if ($?MULTIADDSTAGES:n == 0)
+    echo "no addstar stages defined"
+  end
+  if ($MULTIADDSTAGES:n == 0)
+    echo "no addstar stages defined"
+  end
+
+  local i
+  for i 0 $MULTIADDSTAGES:n
+    echo $MULTIADDSTAGES:$i
+  end
+end
+
 macro stuff
    echo $LOADEXEC_ADD
@@ -147,5 +229,9 @@
 $addstar_DB = 0 
 $addstar_stages_DB = 0
-#this may not work for more databases (addstar) will do that later)
+
+$addstar_multi_DB = 0 
+$addstar_multi_stages_DB = 0
+
+    #this may not work for more databases (addstar) will do that later)
 $addstar_revert_DB_C = 0
 $addstar_revert_DB_S = 0
@@ -225,4 +311,70 @@
 end
 
+
+# select images ready for addstar analysis
+# new entries are added to addPendingExp
+# skip already-present entries
+task	       addstar.multiexp.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC_ADD
+  periods      -timeout 300
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/addstar.multiexp.log
+
+  task.exec
+    #if no stages defined we can't run
+    if ($MULTIADDSTAGES:n == 0) echo "what" 
+ #   if ($MULTIADDSTAGES:n == 0) break
+    $run = addtool -pendingexp
+    
+    #option $ADDSTAGES:$addstar_stages_DB
+    $run = $run -stage $MULTIADDSTAGES:$addstar_multi_stages_DB -multimode  
+    option $DB:$addstar_multi_DB
+    $run = $run -dbname $DB:$addstar_multi_DB
+    $addstar_multi_stages_DB ++
+      if ($addstar_multi_stages_DB >= $MULTIADDSTAGES:n)
+         set addstar_multi_stages_DB = 0
+         $addstar_multi_DB ++
+         if ($addstar_multi_DB >= $DB:n) set addstar_multi_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
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout addPendingMultiExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook addPendingMultiExp
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup addPendingMultiExp
+  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
 task	       addstar.exp.run
@@ -366,4 +518,147 @@
 end
 
+
+    
+# run the addstar script on pending exposures
+task	       addstar.multiexp.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 1200
+
+  ## we want only a single outstanding addstar job.  
+  host         local
+  npending     1
+
+  task.exec
+    book npages addPendingMultiExp -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    
+    # look for new images in addPendingExp (pantaskState == INIT)
+    book getpage addPendingMultiExp 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword addPendingMultiExp $pageName pantaskState RUN
+    book getword addPendingMultiExp $pageName camera -var CAMERA
+    book getword addPendingMultiExp $pageName exp_tag -var EXP_TAG
+    book getword addPendingMultiExp $pageName add_id -var ADD_ID
+    book getword addPendingMultiExp $pageName stage_extra1 -var STAGE_EXTRA1
+    book getword addPendingMultiExp $pageName stageroot -var STAGEROOT
+    book getword addPendingMultiExp $pageName stage -var STAGE
+    book getword addPendingMultiExp $pageName stage_id -var STAGE_ID
+    book getword addPendingMultiExp $pageName workdir -var WORKDIR_TEMPLATE
+    book getword addPendingMultiExp $pageName reduction -var REDUCTION
+    book getword addPendingMultiExp $pageName dvodb  -var DVODB
+    book getword addPendingMultiExp $pageName minidvodb  -var MINIDVODB
+    book getword addPendingMultiExp $pageName minidvodb_name  -var MINIDVODB_NAME
+    book getword addPendingMultiExp $pageName minidvodb_group  -var MINIDVODB_GROUP
+    book getword addPendingMultiExp $pageName image_only -var IMAGE_ONLY
+    book getword addPendingMultiExp $pageName dbname -var DBNAME
+
+    # specify choice of remote host based on camera and chip (class_id)
+    # set.host.for.camera $CAMERA FPA
+
+    # set the WORKDIR variable
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    # notes on how this works:
+    # -- raw workdir examples:
+    # file://data/@HOST@.0/gpc1/20080130
+    # neb:///@HOST@-vol0/gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
+    # -- out workdir examples:
+    # file://data/ipp004.0/gpc1/20080130
+    # neb:///ipp004-vol0/gpc1/20080130
+
+    ## generate outroot specific to this exposure (& chip)
+
+    if ("$STAGE" == "cam")
+	sprintf outroot "%s/%s/%s.add.%s" $WORKDIR $EXP_TAG $EXP_TAG $ADD_ID
+    end
+    if ("$STAGE" == "staticsky")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+    if ("$STAGE" == "stack")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+    if ("$STAGE" == "skycal")
+        sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+    if ("$STAGE" == "diff")
+        sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+    if ("$STAGE" == "fullforce")
+        sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+
+  
+
+    stdout $LOGDIR/addstar.multiexp.log
+    stderr $LOGDIR/addstar.multiexp.log
+
+    $run = addstar_multi_run.pl --add_id $ADD_ID --camera $CAMERA --dvodb $DVODB --stage $STAGE --stageroot $STAGEROOT --outroot $outroot --redirect-output
+    if ("$REDUCTION" != "NULL")
+      $run = $run --reduction $REDUCTION
+    end
+    if ("$STAGE" == "staticsky")
+      $run = $run --stage_extra1 $STAGE_EXTRA1  --stage_id $STAGE_ID
+    end
+    if ("$STAGE" == "cam") 
+      $run = $run --stage_id $STAGE_ID
+    end
+   if ("$STAGE" == "skycal")
+      $run = $run --stage_id $STAGE_ID
+    end
+   if ("$STAGE" == "diff")
+      $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1
+    end
+   if ("$STAGE" == "fullforce")
+      $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1
+    end
+
+
+
+    if ("$IMAGE_ONLY" == "T")
+      $run = $run --image-only
+    end
+    if ("$MINIDVODB" == "T")
+    $run = $run --minidvodb
+    $run = $run --minidvodb_group $MINIDVODB_GROUP
+	if (("$MINIDVODB_NAME" != "NULL") && ("$MINIDVODB_NAME" != "(null)"))
+           $run = $run --minidvodb_name $MINIDVODB_NAME 
+    #have addstar_run.pl grab the 'active' name if it is NULL
+	end
+    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
+
+  # success
+  task.exit default
+    process_exit addPendingMultiExp $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    showcommand crash
+    echo "hostname: $JOB_HOSTNAME"
+    book setword addPendingMultiExp $options:0 pantaskState CRASH
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+    book setword addPendingMultiExp $options:0 pantaskState TIMEOUT
+  end
+end
+    
 task addstar.revert.cam
   host         local
