Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11298)
@@ -24,4 +24,5 @@
     $detType,			# Detrend type
     $dbname,			# Database name
+    $workdir,			# Working directory, for output files
     $no_update			# Don't update the database
     );
@@ -35,4 +36,5 @@
     'det_type|t=s'      => \$detType,
     'dbname|d=s'        => \$dbname,
+    'workdir|w=s'       => \$workdir, # Working directory, for output files
     'no-update'         => \$no_update
     ) or pod2usage( 2 );
@@ -60,10 +62,13 @@
 die "Can't find required tools.\n" if $missing_tools;
 
-my ($vol, $dir, $file) = File::Spec->splitpath( $input );
+unless (defined $workdir) {
+    my ($vol, $dir, $file) = File::Spec->splitpath( $input );
+    $workdir = $dir;
+}
 $input = $ipprc->convert_filename_absolute( $input );
 
 # Output name
 my $outputRoot = $camera . '.' . $detType . '.norm.' . $detId . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 
Index: trunk/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 11298)
@@ -40,11 +40,11 @@
 # Define which detrend types we normalise
 use constant NORMALIZE => {
-    'bias' => 0,
-    'dark' => 0,
-    'shutter' => 0,
-    'flat' => 1,
+    'bias'     => 0,
+    'dark'     => 0,
+    'shutter'  => 0,
+    'flat'     => 1,
     'domeflat' => 1,
-    'skyflat' => 1,
-    'fringe' => 0,
+    'skyflat'  => 1,
+    'fringe'   => 0,
     }; 
 
Index: trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11298)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $dbname, $no_update);
+my ($det_id, $iter, $det_type, $camera, $dbname, $workdir, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -26,4 +26,5 @@
     'det_type|t=s'      => \$det_type,
     'dbname|d=s'        => \$dbname, # Database name
+    'workdir|w=s'       => \$workdir,	# Working directory, for output files
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -92,10 +93,13 @@
 }
 
-my $example = ${$files}[0]->{b1_uri}; # Example file, for path
-my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+unless (defined $workdir) {
+    my $example = ${$files}[0]->{b1_uri}; # Example file, for path
+    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+    $workdir = $dir;
+}
 
 # Generate the file list, and get the statistics
 my $outputRoot = $camera . '.' . $det_type . '.norm.' . $det_id . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute( $outputRoot );
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
@@ -114,5 +118,5 @@
 close $list2File;
 
-# Output products --- need to synch with the camera configuration!
+# Output products
 my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
 my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
Index: trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11298)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_tag, $camera, $dbname, $no_update);
+my ($det_id, $exp_tag, $camera, $dbname, $workdir, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -25,4 +25,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 );
@@ -90,10 +91,13 @@
 }
 
-my $example = ${$files}[0]->{b1_uri}; # Example filename
-my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+unless (defined $workdir) {
+    my $example = ${$files}[0]->{b1_uri}; # Example filename
+    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+    $workdir = $dir;
+}
 
 # Generate the file list, and get the statistics
 my $outputRoot = $exp_tag . '.detproc.' . $det_id; # Root output name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
Index: trunk/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11298)
@@ -18,5 +18,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_tag, $class_id, $det_type, $input_uri, $camera, $bdname, $no_update);
+my ($det_id, $exp_tag, $class_id, $det_type, $input_uri, $camera, $bdname, $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 );
@@ -66,7 +67,10 @@
 
 ### Output file name
-my ($vol, $dir, $file) = File::Spec->splitpath( $input_uri );
+unless (defined $workdir) {
+    my ($vol, $dir, $file) = File::Spec->splitpath( $input_uri );
+    $workdir = $dir;
+}
 my $outputRoot = $exp_tag . '.detproc.' . $det_id; # Root name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute( $outputRoot );
 $input_uri = $ipprc->convert_filename_absolute( $input_uri );
Index: trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11298)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $no_update);
+my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $no_update);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -29,4 +29,5 @@
 	   'reject'            => \$reject
 	   'dbname|d=s'        => \$dbname, # Database name
+	   'workdir|w=s'       => \$workdir, # Working directory, for output files
 	   'no-update'         => \$no_update,
 	   ) or pod2usage( 2 );
@@ -68,10 +69,13 @@
 }
 
-my $example = ${$files}[0]->{b1_uri}; # Example file
-my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+unless (defined $workdir) {
+    my $example = ${$files}[0]->{b1_uri}; # Example file
+    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+    $workdir = $dir;
+}
 
 # Generate the file list, and get the statistics
 my $outputRoot = $exp_tag . '.detresid.' . $det_id . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 11297)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 11298)
@@ -20,5 +20,5 @@
 
 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend,
-        $input_uri, $camera, $mode, $dbname, $no_update);
+        $input_uri, $camera, $mode, $dbname, $workdir, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -32,4 +32,5 @@
     'mode|m=s'          => \$mode,
     'dbname|d=s'        => \$dbname, # Database name
+    'workdir|w=s'       => \$workdir,	# Working directory, for output files
     'no-update'         => \$no_update,
 ) or pod2usage( 2 );
@@ -99,7 +100,10 @@
 
 ### Output file names --- must match camera configuration!
-my ($vol, $dir, $file) = File::Spec->splitpath( $input_uri );
+unless (defined $workdir) {
+    my ($vol, $dir, $file) = File::Spec->splitpath( $input_uri );
+    $workdir = $dir;
+}
 my $outputRoot = $exp_tag . '.detresid.' . $det_id . '.' . $iter; # Root name
-$outputRoot = File::Spec->catpath( $vol, $dir, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute( $outputRoot );
 $input_uri = $ipprc->convert_filename_absolute( $input_uri );
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
Index: trunk/ippScripts/scripts/phase2.pl
===================================================================
--- trunk/ippScripts/scripts/phase2.pl	(revision 11297)
+++ trunk/ippScripts/scripts/phase2.pl	(revision 11298)
@@ -22,6 +22,6 @@
     $input,			# Input FITS file
     $camera,			# Camera
-    $outpath,			# Outpath
     $dbname,			# Database name
+    $workdir,			# Working directory, for output files
     $no_update			# Don't update the database?
     );
@@ -31,6 +31,6 @@
     'uri|u=s'       => \$input,
     'camera|c=s'    => \$camera,
-    'outpath|o=s'   => \$outpath,
     'dbname|d=s'    => \$dbname, # Database name
+    'workdir|w=s'   => \$workdir,
     'no-update'     => \$no_update
 ) or pod2usage( 2 );
@@ -43,5 +43,4 @@
     and defined $classId 
     and defined $input
-    and defined $outpath
     and defined $camera;
 
@@ -54,10 +53,12 @@
 die "Can't find required tools.\n" if $missing_tools;
 
-# XXX old verion Output file name
-# XXX old version (drop) : my ($vol, $dir, $file) = File::Spec->splitpath( $input );
+unless (defined $workdir) {
+    my ($vol, $dir, $file) = File::Spec->splitpath( $input );
+    $workdir = $dir;
+}
 
 ### Output file name --- must match camera configuration!
 my $outputRoot =  $expTag . '.p2';
-$outputRoot = File::Spec->catpath( $outpath, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 $input = $ipprc->convert_filename_absolute ( $input );
Index: trunk/ippScripts/scripts/phase3.pl
===================================================================
--- trunk/ippScripts/scripts/phase3.pl	(revision 11297)
+++ trunk/ippScripts/scripts/phase3.pl	(revision 11298)
@@ -19,10 +19,10 @@
 use Pod::Usage qw( pod2usage );
 
-my ($exp_tag, $camera, $outpath, $dbname, $no_update);
+my ($exp_tag, $camera, $outpath, $dbname, $workdir, $no_update);
 GetOptions(
     'exp_tag|e=s'       => \$exp_tag,
     'camera|c=s'        => \$camera,
-    'outpath|o=s'       => \$outpath,
     'dbname|d=s'        => \$dbname, # Database name
+    'workdir|w=s'       => \$workdir,
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -98,11 +98,13 @@
 }
 
-# XXX old verison, drop
-#my $example = ${$files}[0]->{b1_uri}; # Example filename
-#my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+unless (defined $workdir) {
+    my $example = ${$files}[0]->{b1_uri}; # Example filename
+    my ($vol, $dir, $file) = File::Spec->splitpath( $example );
+    $workdir = $dir;
+}
 
 # Generate the file list, and get the statistics
 my $outputRoot = $exp_tag . '.p3'; # Root output name
-$outputRoot = File::Spec->catpath( $outpath, $outputRoot );
+$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
 $outputRoot = $ipprc->convert_filename_absolute($outputRoot);
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
