Index: trunk/ippTasks/detrend.norm.pro
===================================================================
--- trunk/ippTasks/detrend.norm.pro	(revision 9506)
+++ trunk/ippTasks/detrend.norm.pro	(revision 10692)
@@ -2,11 +2,11 @@
 ## this file contains the tasks for running the detrend normalization stage
 
-## these tasks use the queue DetrendNormalize
-## the DetrendNormalize queue contains:
+## these tasks use the queue DetrendNorm
+## the DetrendNorm queue contains:
 ## STATE DET_ID ITER
 
-queueinit DetrendNormalize
+queueinit DetrendNorm
 queueinit DetrendNormStat
-queueinit DetrendNormalizeExposures
+queueinit DetrendNormExp
 if ($?network == 0)
   $network = 1
@@ -14,4 +14,28 @@
 if ($?parallel == 0)
   $parallel = 0
+end
+
+$DetrendNormFail = 0
+$DetrendNormStatFail = 0
+$DetrendNormExpFail = 0
+
+if ($?VERBOSE == 0)
+  echo "VERBOSE not defined: load pantasks.pro first"
+  break
+end
+if ($?LOGDIR == 0)
+  echo "LOGDIR not defined: load pantasks.pro first"
+  break
+end
+$LOGSUBDIR = $LOGDIR/detrend
+exec mkdir -p $LOGSUBDIR
+
+macro detnorm.status
+  queueprint DetrendNorm
+  queueprint DetrendNormStat
+  queueprint DetrendNormExp
+  echo "DetrendNormFail: $DetrendNormFail"
+  echo "DetrendNormStatFail: $DetrendNormStatFail"
+  echo "DetrendNormExpFail: $DetrendNormExpFail"
 end
 
@@ -20,5 +44,4 @@
 # compare the new list with the ones already selected
 task	       dettool.normstat.load
-  command      dettool -tonormalizedstat -simple
   host         local
 
@@ -27,6 +50,10 @@
   periods      -timeout 30
 
-  stdout dettool.normstat.log
-  stderr dettool.normstat.log
+  stdout $LOGSUBDIR/dettool.normstat.log
+  stderr $LOGSUBDIR/dettool.normstat.log
+
+  task.exec
+    command      dettool -tonormalizedstat -simple -limit {$DetrendNormStatFail + 20}
+  end
 
   # success
@@ -41,4 +68,7 @@
     for i 0 $Nqueue
       queuepop stdout -var line
+      if ($VERBOSE > 2)
+        echo $line
+      end
       list word -split $line
       $DET_ID   = $word:0
@@ -56,10 +86,14 @@
   # default exit status
   task.exit    default
-    echo       "detrend.norm: failure"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    echo       "detrend.norm: timeout"
+    if ($VERBOSE) 
+      echo       "detrend.norm: failure"
+    end
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE) 
+      echo       "detrend.norm: timeout"
+    end
   end
 end
@@ -73,5 +107,4 @@
   task.exec
     queuesize DetrendNormStat -var N
-   
     if ($N == 0) break
     if ($network == 0) break
@@ -95,6 +128,6 @@
 
     # XXX add $WORKDIR/$LOG_DIR
-    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
-    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -107,5 +140,7 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER --det_type $DET_TYPE
+    if ($VERBOSE > 1)
+      echo command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER --det_type $DET_TYPE
+    end
     command detrend_norm_calc.pl --det_id $DET_ID --iteration $ITER --det_type $DET_TYPE
   end
@@ -118,18 +153,25 @@
   # default exit status
   task.exit    default
+    if ($VERBOSE)
+      echo "failure detrend_norm_calc.pl $options:0"
+    end
     queuepush DetrendNormStat -replace -key 1:3 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
+    $DetrendNormStatFail ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE)
+      echo "failure detrend_norm_calc.pl $options:0"
+    end
     queuepush DetrendNormStat -replace -key 1:3 "TIMEOUT $options:0"
+   $DetrendNormStatFail ++
   end
 end
 
 # select images ready for copy 
-# new entries are added to queue DetrendNormalize
+# new entries are added to queue DetrendNorm
 # compare the new list with the ones already selected
 task	       dettool.norm.load
-  command      dettool -tonormalize -simple
   host         local
 
@@ -138,6 +180,10 @@
   periods      -timeout 30
 
-  stdout dettool.norm.log
-  stderr dettool.norm.log
+  stdout $LOGSUBDIR/dettool.norm.log
+  stderr $LOGSUBDIR/dettool.norm.log
+
+  task.exec
+    command      dettool -tonormalize -simple -limit {$DetrendNormFail + 20}
+  end
 
   # success
@@ -152,4 +198,7 @@
     for i 0 $Nqueue
       queuepop stdout -var line
+      if ($VERBOSE > 2)
+        echo $line
+      end
       list word -split $line
       $DET_TYPE = $word:0
@@ -160,9 +209,9 @@
       $CLASS_ID = $word:5
       $NORM     = $word:6
-      queuepush DetrendNormalize -uniq -key 4:5 "NEW $DET_TYPE $CAMERA $URI $DET_ID $ITER $CLASS_ID $NORM"
+      queuepush DetrendNorm -uniq -key 4:5 "NEW $DET_TYPE $CAMERA $URI $DET_ID $ITER $CLASS_ID $NORM"
     end
 
     # delete existing entries which are DONE
-    queuedrop DetrendNormalize -key 0 DONE
+    queuedrop DetrendNorm -key 0 DONE
   end
 
@@ -170,10 +219,14 @@
   # default exit status
   task.exit    default
-    echo       "detrend.norm: failure"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    echo       "detrend.norm: timeout"
+    if ($VERBOSE) 
+      echo       "detrend.norm: failure"
+    end
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE) 
+      echo       "detrend.norm: timeout"
+    end
   end
 end
@@ -186,19 +239,18 @@
 
   task.exec
-    queuesize DetrendNormalize -var N
-   
+    queuesize DetrendNorm -var N
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendNormalize queue
+    # look for new images on the internal DetrendNorm queue
     # caution with these 'if' statements: syntax errors 
     # will make the task fail without given a good status
-    queuepop DetrendNormalize -var line -key 0 NEW
+    queuepop DetrendNorm -var line -key 0 NEW
     if ("$line" == "NULL") break
 
     strpop line state
-    queuepush DetrendNormalize -replace -key 4:5 "RUN $line"
-
-    # the DetrendNormalize queue contains:
+    queuepush DetrendNorm -replace -key 4:5 "RUN $line"
+
+    # the DetrendNorm queue contains:
     # STATE DET_ID ITER
     list word -split $line
@@ -211,8 +263,6 @@
     $NORM     = $word:6
 
-    $LOG_DIR = `dirname $URI`
-
-    stdout $WORKDIR/$LOG_DIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
-    stderr $WORKDIR/$LOG_DIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -225,5 +275,7 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
+    if ($VERBOSE > 1)
+      echo command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
+    end
     command detrend_norm_apply.pl --det_id $DET_ID --iteration $ITER --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
   end
@@ -231,23 +283,30 @@
   # success
   task.exit 0
-    queuepush DetrendNormalize -replace -key 4:5 "DONE $options:0"
-  end
-
-  # default exit status
-  task.exit    default
-    queuepush DetrendNormalize -replace -key 4:5 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    queuepush DetrendNormalize -replace -key 4:5 "TIMEOUT $options:0"
+    queuepush DetrendNorm -replace -key 4:5 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    if ($VERBOSE)
+      echo "failure detrend_norm_apply.pl $options:0"
+    end
+    queuepush DetrendNorm -replace -key 4:5 "FAIL $options:0"
+    $DetrendNormFail ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE)
+      echo "failure detrend_norm_apply.pl $options:0"
+    end
+    queuepush DetrendNorm -replace -key 4:5 "TIMEOUT $options:0"
+    $DetrendNormFail ++
   end
 end
 
 # select images ready for copy 
-# new entries are added to queue DetrendNormalizeExposures
+# new entries are added to queue DetrendNormExp
 # compare the new list with the ones already selected
 task	       dettool.normexp.load
-  command      dettool -tonormalizedexp -simple
   host         local
 
@@ -256,6 +315,10 @@
   periods      -timeout 30
 
-  stdout dettool.normexp.log
-  stderr dettool.normexp.log
+  stdout $LOGSUBDIR/dettool.normexp.log
+  stderr $LOGSUBDIR/dettool.normexp.log
+
+  task.exec
+    command      dettool -tonormalizedexp -simple -limit {$DetrendNormExpFail + 20}
+  end
 
   # success
@@ -270,4 +333,7 @@
     for i 0 $Nqueue
       queuepop stdout -var line
+      if ($VERBOSE > 2)
+        echo $line
+      end
       list word -split $line
       $DET_ID   = $word:0
@@ -278,9 +344,9 @@
       #$EXP_TYPE = $word:5
       #$IMFILES  = $word:6
-      queuepush DetrendNormalizeExposures -uniq -key 1:2 "NEW $DET_ID $ITER $DET_TYPE $CAMERA"
+      queuepush DetrendNormalizeExp -uniq -key 1:2 "NEW $DET_ID $ITER $DET_TYPE $CAMERA"
     end
 
     # delete existing entries which are DONE
-    queuedrop DetrendNormalizeExposures -key 0 DONE
+    queuedrop DetrendNormExp -key 0 DONE
   end
 
@@ -288,10 +354,14 @@
   # default exit status
   task.exit    default
-    echo       "detrend.norm: failure"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    echo       "detrend.norm: timeout"
+    if ($VERBOSE) 
+      echo       "detrend.norm: failure"
+    end
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE) 
+      echo       "detrend.norm: timeout"
+    end
   end
 end
@@ -304,19 +374,19 @@
 
   task.exec
-    queuesize DetrendNormalizeExposures -var N
+    queuesize DetrendNormExp -var N
    
     if ($N == 0) break
     if ($network == 0) break
     
-    # look for new images on the internal DetrendNormalizeExposures queue
+    # look for new images on the internal DetrendNormExp queue
     # caution with these 'if' statements: syntax errors 
     # will make the task fail without given a good status
-    queuepop DetrendNormalizeExposures -var line -key 0 NEW
+    queuepop DetrendNormExp -var line -key 0 NEW
     if ("$line" == "NULL") break
 
     strpop line state
-    queuepush DetrendNormalizeExposures -replace -key 1:2 "RUN $line"
-
-    # the DetrendNormalizeExposures queue contains:
+    queuepush DetrendNormExp -replace -key 1:2 "RUN $line"
+
+    # the DetrendNormExp queue contains:
     # STATE DET_ID ITER
     list word -split $line
@@ -330,6 +400,6 @@
 
     # XXX add $WORKDIR/$LOG_DIR
-    stdout $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
-    stderr $CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stdout $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
+    stderr $LOGSUBDIR/$CAMERA.$DET_TYPE.$DET_ID.$ITER.log
 
     # specify choice of remote host:
@@ -342,5 +412,7 @@
     # create example job options as a demonstration
     options "$line"
-    echo command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITER --camera $CAMERA --det_type $DET_TYPE
+    if ($VERBOSE > 1)
+      echo command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITER --camera $CAMERA --det_type $DET_TYPE
+    end
     command detrend_norm_exp.pl --det_id $DET_ID --iteration $ITER --camera $CAMERA --det_type $DET_TYPE
   end
@@ -348,15 +420,23 @@
   # success
   task.exit 0
-    queuepush DetrendNormalizeExposures -replace -key 1:2 "DONE $options:0"
-  end
-
-  # default exit status
-  task.exit    default
-    queuepush DetrendNormalizeExposures -replace -key 1:2 "FAIL $options:0"
-  end
-
-  # operation times out?
-  task.exit    timeout
-    queuepush DetrendNormalizeExposures -replace -key 1:2 "TIMEOUT $options:0"
-  end
-end
+    queuepush DetrendNormExp -replace -key 1:2 "DONE $options:0"
+  end
+
+  # default exit status
+  task.exit    default
+    if ($VERBOSE)
+      echo "failure detrend_norm_exp.pl $options:0"
+    end
+    queuepush DetrendNormExp -replace -key 1:2 "FAIL $options:0"
+   $DetrendNormExpFail ++
+  end
+
+  # operation times out?
+  task.exit    timeout
+    if ($VERBOSE)
+      echo "failure detrend_norm_exp.pl $options:0"
+    end
+    queuepush DetrendNormExp -replace -key 1:2 "TIMEOUT $options:0"
+   $DetrendNormExpFail ++
+  end
+end
