Index: /trunk/tools/eam/rawfix.20230221/src/advance.rawfix.sh
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/advance.rawfix.sh	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/advance.rawfix.sh	(revision 42440)
@@ -2,5 +2,5 @@
 
 if ($#argv < 1) then
-  echo "USAGE: advance.rawfix.sh all"
+  echo "USAGE: advance.rawfix.sh all (Nmax)"
   echo "USAGE: advance.rawfix.sh night (YYYYMMDD)"
   exit 2
@@ -9,13 +9,41 @@
 set mode = $1
 
+## include a max number of active programs
 if ($mode == "all") then
+  if ($#argv != 2) then
+    echo "USAGE: advance.rawfix.sh all (Nmax)"
+    exit 2
+  endif
+
+  set nMax = $2
+  set nActive  = 0
+  set nAdvance = 0
   set nights = `./check.rawfix.sh all | awk '(NR > 1){print $1}'`
   foreach f ($nights)
-    echo -n "$f "
     ./advance.rawfix.sh night $f 
+    set myResult = $status
+    if ($myResult == 1) continue
+    if ($myResult == 2) continue
+    if ($myResult == 3) continue
+    if ($myResult == 4) then
+      @ nActive ++
+    endif
+    if ($myResult == 5) then
+      @ nActive ++
+      @ nAdvance ++
+    endif
+    if ($nActive >= $nMax) then
+      echo "advance $nAdvance nights, total of $nActive active nights"
+      exit 0
+    endif
   end
+  echo "advance $nAdvance nights, total of $nActive active nights"
   exit 0
 endif
 
+# advance STAGE0.done to STAGE1.new
+# if already in STAGEx.new, return 4
+# if setting to STAGEx.new, return 5
+# otherwise, return 3
 if ($mode == "night") then
   if ($#argv != 2) then
@@ -29,4 +57,5 @@
 
   set tgtstate = "NONE"
+  if ($mystate == "new")             set tgtstate = "ckchip.new"
   if ($mystate == "ckchip.done")     set tgtstate = "fixchip.new"
   if ($mystate == "fixchip.done")    set tgtstate = "md5sum.new"    
@@ -37,14 +66,29 @@
   if ($mystate == "md5chk_s2.done")  set tgtstate = "fixchip_s3.new"   
   if ($mystate == "fixchip_s3.done") set tgtstate = "ckchip_s3.new"    
+  if ($mystate == "ckchip_s3.done")  set tgtstate = "DONE" 
 
-  if ($tgtstate == "NONE") then
-    echo "nothing to advance"
-    exit 0
-  endif
+  if ($mystate == "ckchip.new")      set tgtstate = "ACTIVE"
+  if ($mystate == "fixchip.new")     set tgtstate = "ACTIVE"
+  if ($mystate == "md5sum.new")      set tgtstate = "ACTIVE"
+  if ($mystate == "md5chk.new")      set tgtstate = "ACTIVE"
+  if ($mystate == "fixchip_s2.new")  set tgtstate = "ACTIVE"
+  if ($mystate == "md5sum_s2.new")   set tgtstate = "ACTIVE"
+  if ($mystate == "md5chk_s2.new")   set tgtstate = "ACTIVE"
+  if ($mystate == "fixchip_s3.new")  set tgtstate = "ACTIVE"
+  if ($mystate == "ckchip_s3.new")   set tgtstate = "ACTIVE"
 
+  echo "$night : $mystate : $tgtstate"
+
+  # do not set these two states
+  if ($tgtstate == "NONE") exit 3
+  if ($tgtstate == "ACTIVE") exit 4
+
+  # only set these states
   ./update.rawfix.sh $night $tgtstate
-  exit 0
+
+  if ($tgtstate == "DONE") exit 1
+  exit 5
 endif
 
-echo "ERROR: unknown mode: $mode
+echo "ERROR: unknown mode: $mode"
 exit 2
Index: /trunk/tools/eam/rawfix.20230221/src/create.rawfix.sh
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/create.rawfix.sh	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/create.rawfix.sh	(revision 42440)
@@ -9,5 +9,5 @@
   create database $DBNAME;
   use $DBNAME;
-  create table nights (night_id BIGINT AUTO_INCREMENT, dateobs char(64), state char(64), primary key (night_id));
+  create table nights (night_id BIGINT AUTO_INCREMENT, dateobs char(64), state char(64), primary key (night_id), unique (dateobs));
 EOF
 
Index: /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/queue.rawfix.sh	(revision 42440)
@@ -1,8 +1,11 @@
 #!/bin/csh
 
-if ($#argv != 1) then
-  echo "USAGE: queue.rawfix.sh (mjddate)"
+if ($#argv != 2) then
+  echo "USAGE: queue.rawfix.sh (list) (filename)"
+  echo "USAGE: queue.rawfix.sh (night) (YYYYMMDD)"
   exit 2
 endif
+
+set mode = $1
 
 # make the rawfix database to track rawfix operations
@@ -12,6 +15,22 @@
 set DBPASS = "dvo"
 
-## XXX validate the format (YYYYMMDD)?
-set mynight = $1
+if ($mode == "list") then
+  set filename = $2
 
-mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME -e "insert into nights (dateobs, state) values ('$mynight', 'new')"
+  # just a big list of dates?
+  foreach night (`cat $filename`)
+    queue.rawfix.sh night $night
+  end
+  exit 0
+endif
+
+if ($mode == "night") then
+  ## XXX validate the format (YYYYMMDD)?
+  set mynight = $2
+  
+  mysql -h $DBHOST -u $DBUSER -p$DBPASS $DBNAME -e "insert into nights (dateobs, state) values ('$mynight', 'new')"
+  exit 0
+endif
+
+echo "ERROR: unknown mode $mode"
+exit 2
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.advance.pt	(revision 42440)
@@ -1,2 +1,4 @@
+
+$MAX_ACTIVE_NIGHTS = 2
 
 ## regularly run the command advance.rawfits.sh
@@ -13,5 +15,6 @@
 
   task.exec
-    command advance.rawfix.sh all
+    # 
+    command advance.rawfix.sh all $MAX_ACTIVE_NIGHTS
   end
 
@@ -19,5 +22,4 @@
   # by already-running load tasks
   task.exit 0
-    echo "done with advance"    
   end
 
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip.pt	(revision 42440)
@@ -78,7 +78,7 @@
 
     # this is the first place in the proces that this location is known
-    mkdir  $DATEOBS
-    stdout $DATEOBS/log.ckchip.v0  
-    stderr $DATEOBS/log.ckchip.v0
+    mkdir  $mypath/$DATEOBS
+    stdout $mypath/$DATEOBS/log.ckchip.runhosts.v0  
+    stderr $mypath/$DATEOBS/log.ckchip.runhosts.v0  
 
     substr $DATEOBS 0 4 YEAR
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip_s3.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip_s3.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.ckchip_s3.pt	(revision 42440)
@@ -61,7 +61,4 @@
   npending 1
 
-  stdout $LOGDIR/ckchip_s3.run.stdout.log  
-  stderr $LOGDIR/ckchip_s3.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -75,4 +72,7 @@
     book getpage ckchip_s3.book 0 -var pageName -key pantaskState INIT
     if ("$pageName" == "NULL") break
+
+    stdout $mypath/$DATEOBS/log.ckchip_s3.runhosts.v0  
+    stderr $mypath/$DATEOBS/log.ckchip_s3.runhosts.v0  
 
     book setword ckchip_s3.book $pageName pantaskState RUN
@@ -89,10 +89,6 @@
   end
 
-  ## XX delete the page from the book if done?
+  # SUCCESS 
   task.exit 0
-    queuepush stdout "------- end of stdout ---------"
-    queuesave stdout $options:0/log.ckchip_s3.v1
-    queuepush stderr "------- end of stderr ---------"
-    queuesave stderr $options:0/log.ckchip_s3.v1
     book setword ckchip_s3.book $options:0 pantaskState DONE
     exec update.rawfix.sh $options:0 ckchip_s3.done
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip.pt	(revision 42440)
@@ -60,7 +60,4 @@
   npending 1
 
-  stdout $LOGDIR/fixchip.run.stdout.log  
-  stderr $LOGDIR/fixchip.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s2.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s2.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s2.pt	(revision 42440)
@@ -60,7 +60,4 @@
   npending 1
 
-  stdout $LOGDIR/fixchip_s2.run.stdout.log  
-  stderr $LOGDIR/fixchip_s2.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -83,4 +80,8 @@
     substr $DATEOBS 6 2 DAY
     sprintf FULLDATE "%s/%s/%s" $YEAR $MONTH $DAY
+
+    # does the output go here?
+    stdout $mypath/$DATEOBS/log.fixchip_s2.runhosts.v0  
+    stderr $mypath/$DATEOBS/log.fixchip_s2.runhosts.v0  
 
     command fix_chip_locations_stage2.pl --dateobs $FULLDATE --chiplist gpc1.chips.txt --stage v0
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s3.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s3.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.fixchip_s3.pt	(revision 42440)
@@ -60,7 +60,4 @@
   npending 1
 
-  stdout $LOGDIR/fixchip_s3.run.stdout.log  
-  stderr $LOGDIR/fixchip_s3.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -83,4 +80,8 @@
     substr $DATEOBS 6 2 DAY
     sprintf FULLDATE "%s/%s/%s" $YEAR $MONTH $DAY
+
+    # does the output go here?
+    stdout $mypath/$DATEOBS/log.fixchip_s3.runhosts.v0  
+    stderr $mypath/$DATEOBS/log.fixchip_s3.runhosts.v0  
 
     command fix_chip_locations_stage3.pl --dateobs $FULLDATE --chiplist gpc1.chips.txt
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk.pt	(revision 42440)
@@ -59,7 +59,4 @@
   npending 1
 
-  stdout $LOGDIR/md5chk.run.stdout.log  
-  stderr $LOGDIR/md5chk.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -83,6 +80,7 @@
     sprintf FULLDATE "%s/%s/%s" $YEAR $MONTH $DAY
 
-    # send output to a file in the DATEOBS directory
-    stdout $DATEOBS/md5chk.log  
+    # does the output go here?
+    stdout $mypath/$DATEOBS/log.md5chk.v0  
+    stderr $mypath/$DATEOBS/log.md5chk.v0  
 
     command check_md5s_dateobs.pl --dateobs $FULLDATE
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk_s2.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk_s2.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.md5chk_s2.pt	(revision 42440)
@@ -59,7 +59,4 @@
   npending 1
 
-  stdout $LOGDIR/md5chk_s2.run.stdout.log  
-  stderr $LOGDIR/md5chk_s2.run.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -83,6 +80,7 @@
     sprintf FULLDATE "%s/%s/%s" $YEAR $MONTH $DAY
 
-    # send output to a file in the DATEOBS directory
-    stdout $DATEOBS/md5chk_s2.log  
+    # does the output go here?
+    stdout $mypath/$DATEOBS/log.md5chk_s2.v0  
+    stderr $mypath/$DATEOBS/log.md5chk_s2.v0  
 
     command check_md5s_dateobs.pl --dateobs $FULLDATE
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum.pt	(revision 42440)
@@ -82,5 +82,5 @@
 
     # write an entry point in the log for this night
-    sprintf tmpline "%s/%s/md5sum.runhosts.log" $mypath $DATEOBS
+    sprintf tmpline "%s/%s/log.md5sum.runhosts.v0" $mypath $DATEOBS
     date -var mydate
     exec echo "# start runhosts $mydate" >> $tmpline
@@ -143,4 +143,5 @@
     # save DATEOBS so we can find the md5sum.book entry
 
+    # does the output go here?
     stdout $mypath/$DATEOBS/log.md5sum.runhosts.v0  
     stderr $mypath/$DATEOBS/log.md5sum.runhosts.v0  
@@ -268,5 +269,5 @@
   if ("$1" != "OK")
     book setword md5sum.book $options:1 pantasksQuality $1
-    sprintf tmpline "%s/%s/md5sum.runhosts.log" $mypath $options:1
+    sprintf tmpline "%s/%s/log.md5sum.runhosts.v0" $mypath $options:1
     exec echo "failure $1 $options:0" >> $tmpline
   else
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum_s2.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum_s2.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.md5sum_s2.pt	(revision 42440)
@@ -82,5 +82,5 @@
 
     # write an entry point in the log for this night
-    sprintf tmpline "%s/%s/md5sum_s2.runhosts.log" $mypath $DATEOBS
+    sprintf tmpline "%s/%s/log.md5sum_s2.runhosts.v0" $mypath $DATEOBS
     date -var mydate
     exec echo "# start runhosts $mydate" >> $tmpline
@@ -124,7 +124,4 @@
   periods      -timeout 60
 
-  stdout $LOGDIR/md5sum_s2.runhosts.stdout.log  
-  stderr $LOGDIR/md5sum_s2.runhosts.stderr.log
-
   task.exec
     # if we are unable to run the 'exec', use a long retry time
@@ -145,4 +142,8 @@
     option $pageName $DATEOBS
     # save DATEOBS so we can find the md5sum_s2.book entry
+
+    # does the output go here?
+    stdout $mypath/$DATEOBS/log.md5sum_s2.runhosts.v0  
+    stderr $mypath/$DATEOBS/log.md5sum_s2.runhosts.v0  
 
     # XXX TEST: $USE_HOST = ipp060
@@ -270,5 +271,5 @@
   if ("$1" != "OK")
     book setword md5sum_s2.book $options:1 pantasksQuality $1
-    sprintf tmpline "%s/%s/md5sum_s2.runhosts.log" $mypath $options:1
+    sprintf tmpline "%s/%s/log.md5sum_s2.runhosts.v0" $mypath $options:1
     exec echo "failure $1 $options:0" >> $tmpline
   else
Index: /trunk/tools/eam/rawfix.20230221/src/rawfix.pt
===================================================================
--- /trunk/tools/eam/rawfix.20230221/src/rawfix.pt	(revision 42439)
+++ /trunk/tools/eam/rawfix.20230221/src/rawfix.pt	(revision 42440)
@@ -23,13 +23,13 @@
 # order is this file is not determinative, only the
 # change of state from STAGE1.new -> STAGE1.done -> STAGE2.new
-# input rawfix.advance.pt
+input rawfix.advance.pt
 input rawfix.ckchip.pt
-# input rawfix.fixchip.pt
-# input rawfix.md5sum.pt
-# input rawfix.md5chk.pt
-# input rawfix.fixchip_s2.pt
-# input rawfix.md5sum_s2.pt
-# input rawfix.md5chk_s2.pt
-# input rawfix.fixchip_s3.pt
+input rawfix.fixchip.pt
+input rawfix.md5sum.pt
+input rawfix.md5chk.pt
+input rawfix.fixchip_s2.pt
+input rawfix.md5sum_s2.pt
+input rawfix.md5chk_s2.pt
+input rawfix.fixchip_s3.pt
 
 # no need to run rsync if we use the b-node working directory:
