Index: trunk/ippTasks/detrend.resid.pro
===================================================================
--- trunk/ippTasks/detrend.resid.pro	(revision 12747)
+++ 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
