Index: /trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 13682)
+++ /trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 13683)
@@ -138,7 +138,14 @@
 # Output products
 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-my $outputRoot = $ipprc->file_prepare( "$exp_tag.detresid.$det_id.$iter", $workdir, ${$files}[0]->{path_base} );
-my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
-my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
+my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detresid.$det_id.$iter", $workdir, ${$files}[0]->{path_base} );
+my $jpeg1Name  = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
+my $jpeg2Name  = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
+my $logName    = $ipprc->filename("LOG.EXP", $outputRoot); # Name for log
+
+my $logFile;
+unless ($no_op) {
+    # XXX this will fail if the file exists (because of Nebulous rules)
+    $logFile = $ipprc->file_create_open( $logName );
+}
 
 # Recipes to use in processing
@@ -189,11 +196,4 @@
 my $reject_exp_bin_sn       = rejection_limit( 'EXP.BIN.SN',       $det_type, $filter );
 
-my $logName = caturi( $workdir, "$exp_tag.detreject.$det_id.$iter.log" ); # Name for log
-my $logFile;
-unless ($no_op) {
-    # XXX this will fail if the file exists (because of Nebulous rules)
-    $logFile = $ipprc->file_create_open( $logName );
-}
-
 # Reject based on the stats of the imfiles
 # it is VALID to reject on more than one criterion
Index: /trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_resid.pl	(revision 13682)
+++ /trunk/ippScripts/scripts/detrend_resid.pl	(revision 13683)
@@ -119,5 +119,5 @@
 $workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
 
-my $outputRoot = $ipprc->file_prepare( "$exp_tag.detresid.$det_id.$iter", $workdir, $input_uri );
+my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detresid.$det_id.$iter", $workdir, $input_uri );
 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
 my $bin1Name =  $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
Index: /trunk/ippTasks/detrend.norm.pro
===================================================================
--- /trunk/ippTasks/detrend.norm.pro	(revision 13682)
+++ /trunk/ippTasks/detrend.norm.pro	(revision 13683)
@@ -164,13 +164,13 @@
 
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outroot/norm.$DET_ID.$ITERATION.log
+      $outpath = `pwd`
+    else
+      $outpath = `ipp_datapath.pl $WORKDIR`
+    end
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.log
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     $run = detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE
@@ -287,13 +287,13 @@
     # XXX use ipp_filename.pl to lookup output file names
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outroot/norm.$DET_ID.$ITERATION.$CLASS_ID.log
+      $outpath = `pwd`
+    else
+      $outpath = `ipp_datapath.pl $WORKDIR`
+    end
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.$CLASS_ID.log
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     $run = detrend_norm_apply.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
@@ -407,13 +407,13 @@
     # XXX add $WORKDIR/$LOG_DIR
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outroot/norm.$DET_ID.$ITERATION.log
+      $outpath = `pwd`
+    else
+      $outpath = `ipp_datapath.pl $WORKDIR`
+    end
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.log
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     $run = detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE 
Index: /trunk/ippTasks/detrend.process.pro
===================================================================
--- /trunk/ippTasks/detrend.process.pro	(revision 13682)
+++ /trunk/ippTasks/detrend.process.pro	(revision 13683)
@@ -227,5 +227,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq -setword dbname $options:0
+    ipptool2book stdout detPendingProcessedExp -key det_id:exp_tag -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingProcessedExp
@@ -262,8 +262,6 @@
     if ($pageName == NULL) break
 
-    # XXX is ITERATION relevant here??
     book setword detPendingProcessedExp $pageName state RUN
     book getword detPendingProcessedExp $pageName det_id    -var DET_ID
-    book getword detPendingProcessedExp $pageName iteration -var ITERATION
     book getword detPendingProcessedExp $pageName det_type  -var DET_TYPE
     book getword detPendingProcessedExp $pageName exp_tag   -var EXP_TAG
@@ -286,5 +284,5 @@
     end
     $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID/$EXP_TAG
-    $outroot = $outpath/$EXP_TAG.detproc.$DET_ID.$ITERATION
+    $outroot = $outpath/$EXP_TAG.detproc.$DET_ID
     $logfile = `ipp_filename.pl --filerule LOG.EXP --camera $CAMERA --class_id NONE --basename $outroot`
     if ("$logfile" == "") 
Index: /trunk/ippTasks/detrend.reject.pro
===================================================================
--- /trunk/ippTasks/detrend.reject.pro	(revision 13682)
+++ /trunk/ippTasks/detrend.reject.pro	(revision 13683)
@@ -138,5 +138,5 @@
     end
     $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outroot/reject.$DET_ID.$ITERATION.log
+    $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.detreject.log
     stdout $logfile
     stderr $logfile
Index: /trunk/ippTasks/detrend.resid.pro
===================================================================
--- /trunk/ippTasks/detrend.resid.pro	(revision 13682)
+++ /trunk/ippTasks/detrend.resid.pro	(revision 13683)
@@ -154,13 +154,18 @@
     # XXX use ipp_filename.pl to lookup output file names
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID/$EXP_TAG
-    $logfile = $outroot/detresid.$DET_ID.$ITERATION.$CLASS_ID.log
+      $outpath = `pwd`
+    else
+      $outpath = `ipp_datapath.pl $WORKDIR`
+    end
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID/$EXP_TAG
+    $outroot = $outpath/$EXP_TAG.detresid.$DET_ID.$ITERATION
+    $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
+    if ("$logfile" == "") 
+      $logfile = $outroot.$CLASS_ID.log
+    end
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     $run = detrend_resid.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URI --input_uri $URI --camera $CAMERA --mode $MODE
@@ -277,13 +282,15 @@
     # XXX use ipp_filename.pl to lookup output file names
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID/$EXP_TAG
-    $logfile = $outroot/detresid.$DET_ID.$ITERATION.log
+      $outpath = `pwd`
+    else
+      $outpath = `ipp_datapath.pl $WORKDIR`
+    end
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID/$EXP_TAG
+    $outroot = $outpath/$EXP_TAG.detresid.$DET_ID.$ITERATION
+    $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     $run = detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA
Index: /trunk/ippTasks/detrend.stack.pro
===================================================================
--- /trunk/ippTasks/detrend.stack.pro	(revision 13682)
+++ /trunk/ippTasks/detrend.stack.pro	(revision 13683)
@@ -134,13 +134,18 @@
 
     if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
+      $outpath = `pwd`
     else
-      $outroot = `ipp_datapath.pl $WORKDIR`
+      $outpath = `ipp_datapath.pl $WORKDIR`
     end
-    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outroot/detstack.$DET_ID.$ITERATION.$CLASS_ID.log
+    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
+    $outroot = $outpath/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION
+    $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
+    if ("$logfile" == "") 
+      $logfile = $outroot.$CLASS_ID.log
+    end
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
+    exec mkdir -p $outpath
 
     # save the pageName for future reference below
