Index: branches/eam_branch_20080121/ippTasks/detrend.stack.pro
===================================================================
--- branches/eam_branch_20080121/ippTasks/detrend.stack.pro	(revision 16175)
+++ branches/eam_branch_20080121/ippTasks/detrend.stack.pro	(revision 16176)
@@ -123,5 +123,5 @@
     book getword detPendingStackedImfile $pageName class_id  -var CLASS_ID
     book getword detPendingStackedImfile $pageName camera    -var CAMERA  
-    book getword detPendingStackedImfile $pageName workdir   -var WORKDIR
+    book getword detPendingStackedImfile $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingStackedImfile $pageName dbname    -var DBNAME
     book getword detPendingStackedImfile $pageName reduction -var REDUCTION
@@ -130,31 +130,28 @@
     set.host.for.camera $camera $class_id
 
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s" $outpath $CAMERA $DET_TYPE $DET_ID
-    sprintf outroot "%s/%s.%s.%s.%s" $outpath $CAMERA $DET_TYPE $DET_ID $ITERATION
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s.%s.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID $ITERATION
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
     if ("$logfile" == "") 
-      sprintf logfile "%s.%s.log" $outroot $CLASS_ID
+      echo "WARNING: logfile not defined in detrend.stack.pro:141"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
 
-    # save the pageName for future reference below
-    options $pageName
-
-    $run = detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+    $run = detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
     end
     add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
 
     # create the command line
