Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 11298)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $no_update);
+my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $workdir, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -27,4 +27,5 @@
     'camera|c=s'        => \$camera,
     'dbname|d=s'        => \$dbname, # Database name
+    'workdir|w=s'       => \$workdir,	# Working directory, for output files
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -75,10 +76,13 @@
 }
 
-my $example = ${$files}[0]->{uri}; # Example file
-my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+unless (defined $workdir) {
+    my $example = ${$files}[0]->{uri}; # Example file
+    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+    $workdir = $dir;
+}
 
 # Stack the files
 my $outputRoot = $camera . '.' . $det_type . '.' . $det_id . '.' . $iter . '.' . $class_id; # Root name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 my $outputStack = $outputRoot . '.fits'; # Output name
