Index: trunk/ippTasks/addstar.pro
===================================================================
--- trunk/ippTasks/addstar.pro	(revision 35239)
+++ trunk/ippTasks/addstar.pro	(revision 35305)
@@ -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
