Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 15616)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 16196)
@@ -32,5 +32,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($det_id, $iter, $exp_id, $exp_tag, $class_id, $det_type, $detrend, $input_uri, $camera, $mode, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -44,6 +44,6 @@
     'camera|c=s'        => \$camera,
     'mode|m=s'          => \$mode,
+    'outroot|w=s'       => \$outroot,   # output file base name
     'dbname|d=s'        => \$dbname, # Database name
-    'workdir|w=s'       => \$workdir,	# Working directory, for output files
     'reduction=s'       => \$reduction,	# Reduction class
     'no-update'         => \$no_update,
@@ -52,16 +52,17 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend (not for 'verify' mode)",
-	   -exitval => 3)
-    unless defined $det_id
-    and defined $iter
-    and defined $exp_id
-    and defined $exp_tag
-    and defined $class_id
-    and defined $det_type
-    and defined $input_uri
-    and defined $camera
-    and defined $mode
-    and (defined $detrend or lc($mode) eq 'verify');
+pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --class_id --det_type --camera --input_uri --mode --detrend --outroot (not for 'verify' mode)",
+	   -exitval => 3) unless 
+    defined $det_id    and 
+    defined $iter      and 
+    defined $exp_id    and 
+    defined $exp_tag   and 
+    defined $class_id  and 
+    defined $det_type  and 
+    defined $input_uri and 
+    defined $camera    and 
+    defined $mode      and 
+    defined $outroot   and 
+    (defined $detrend or lc($mode) eq 'verify');
 
 $ipprc->define_camera($camera);
@@ -130,19 +131,22 @@
 $ppImage .= " -dbname $dbname" if defined $dbname;
 
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-
-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);
-my $bin2Name    = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
-my $outputStats = $ipprc->filename("PPIMAGE.STATS", $outputRoot, $class_id);
-
-my $traceDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".$class_id.trace"; # Trace messages
-my $logDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".$class_id.log"; # Log messages
+# outroot examples (HOST components must be set)
+# file://data/ipp004.0/gpc1/20080130
+# neb:///ipp004-v1/gpc1/20080130
+# neb:///*/gpc1/20080130 (volume not specified)
+
+# check for existing directory, generate if needed
+$ipprc->outroot_prepare($outroot);
+
+my $outputName  = $ipprc->filename("PPIMAGE.OUTPUT", $outroot, $class_id);
+my $bin1Name    = $ipprc->filename("PPIMAGE.BIN1",   $outroot, $class_id);
+my $bin2Name    = $ipprc->filename("PPIMAGE.BIN2",   $outroot, $class_id);
+my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outroot, $class_id);
+my $traceDest   = $ipprc->filename("TRACE.IMFILE",   $outroot, $class_id);
+my $logDest     = $ipprc->filename("LOG.IMFILE",     $outroot, $class_id);
 
 # Run ppImage & ppStats
 unless ($no_op) {
-    my $command = "$ppImage -file $input_uri $outputRoot";
+    my $command = "$ppImage -file $input_uri $outroot";
     $command .= " -recipe PPIMAGE $recipe";
     $command .= " -recipe PPSTATS RESIDUAL";
@@ -205,5 +209,5 @@
 $command .= " -recip $recipe";
 $command .= " -uri $outputName";
-$command .= " -path_base $outputRoot";
+$command .= " -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
