Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11360)
@@ -24,11 +24,11 @@
 
 # Parse the command-line
-my ($detId,                     # Detrend ID
+my ($det_id,                     # Detrend ID
     $iter,  			# Iteration
-    $classId,			# Class ID
+    $class_id,			# Class ID
     $value,			# Value to multiple (for normalisation)
     $input,			# Input file
     $camera,			# Camera
-    $detType,			# Detrend type
+    $det_type,			# Detrend type
     $dbname,			# Database name
     $workdir,			# Working directory, for output files
@@ -36,11 +36,11 @@
     );
 GetOptions(
-    'det_id|d=s'        => \$detId,
+    'det_id|d=s'        => \$det_id,
     'iteration|n=s'	=> \$iter,
-    'class_id|i=s'      => \$classId,
+    'class_id|i=s'      => \$class_id,
     'value|v=s'		=> \$value,
     'input_uri|u=s'     => \$input,
     'camera|c=s'        => \$camera,
-    'det_type|t=s'      => \$detType,
+    'det_type|t=s'      => \$det_type,
     'dbname|d=s'        => \$dbname,
     'workdir|w=s'       => \$workdir, # Working directory, for output files
@@ -51,11 +51,11 @@
 pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type",
     -exitval => 3,
-    ) unless defined $detId
+    ) unless defined $det_id
     and defined $iter
-    and defined $classId
+    and defined $class_id
     and defined $value
     and defined $input
     and defined $camera
-    and defined $detType;
+    and defined $det_type;
 
 $ipprc->define_camera($camera);
@@ -83,27 +83,28 @@
 
 # Output name
-my $outputRoot = $camera . '.' . $detType . '.norm.' . $detId . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
+my $outputFile = "$camera.$det_type.norm.$det_id.$iter"; # Root name
+my $outputSubD = "$camera.$det_type.$det_id";
+my $outputRoot = File::Spec->catfile( $workdir, $outputSubD, $outputFile );
 
-my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $classId);
-my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $classId);
-my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $classId);
+my $output = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
+my $b1name = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
+my $b2name = $ipprc->filename("PPIMAGE.BIN2", $outputRoot, $class_id);
 
-my $statsName = $outputRoot . '.' . $classId . '.stats'; # Statistics file
+my $statsName = $outputRoot . '.' . $class_id . '.stats'; # Statistics file
 
 # Run normalisation
 {
     my $command = "$ppImage -file $input $outputRoot -norm $value -stat $statsName -recipe PPIMAGE " . RECIPE(); # Command to run
-    $command .= ' -isfringe' if lc($detType) eq 'fringe';
+    $command .= ' -isfringe' if lc($det_type) eq 'fringe';
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
     unless ($success) {
 	$error_code = $error_code >> 8;
-	&my_die("Unable to perform ppImage: $error_code", $detId, $iter, $classId, $error_code);
+	&my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $class_id, $error_code);
     }
-    &my_die("Can't find expected output file: $output", $detId, $iter, $classId, $PS_EXIT_SYS_ERROR) unless -e $output;
-    &my_die("Can't find expected output file: $b1name", $detId, $iter, $classId, $PS_EXIT_SYS_ERROR) unless -e $b2name;
-    &my_die("Can't find expected output file: $b2name", $detId, $iter, $classId, $PS_EXIT_SYS_ERROR) unless -e $b1name;
-    &my_die("Can't find expected output file: $statsName", $detId, $iter, $classId, $PS_EXIT_SYS_ERROR) unless -e $statsName;
+    &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $output;
+    &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b2name;
+    &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b1name;
+    &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $statsName;
 }
 
@@ -112,12 +113,12 @@
 {
     my $statsFile;		# File handle
-    open $statsFile, $statsName or &my_die("Can't open statistics file $statsName: $!\n", $detId, $iter, $classId, $PS_EXIT_SYS_ERROR);
+    open $statsFile, $statsName or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
     my @contents = <$statsFile>; # Contents of file
     close $statsFile;
     my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
     my $metadata = $mdcParser->parse(join "", @contents)
-        or &my_die("Unable to parse metadata config", $detId, $iter, $classId, $PS_EXIT_PROG_ERROR);
+        or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
-    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $detId, $iter, $classId, $PS_EXIT_PROG_ERROR);
+    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -127,5 +128,5 @@
 $b2name = $ipprc->convert_filename_relative( $b2name );
 unless ($no_update) {
-    my $command = "$dettool -addnormalizedimfile -det_id $detId -iteration $iter -class_id $classId ".
+    my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id ".
 	"-uri $output -b1_uri $b1name -b2_uri $b2name"; # Command to run
     # Add the statistics triplet
Index: trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11360)
@@ -117,6 +117,8 @@
 
 # Generate the file list, and get the statistics
-my $outputRoot = $camera . '.' . $det_type . '.norm.' . $det_id . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
+my $outputFile = "$camera.$det_type.norm.$det_id.$iter"; # Root output name
+my $outputSubD = "$camera.$det_type.$det_id";
+my $outputRoot = File::Spec->catfile( $workdir, $outputSubD, $outputFile );
+
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
Index: trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11360)
@@ -113,8 +113,8 @@
     $workdir = $dir;
 }
-
-# Generate the file list, and get the statistics
-my $outputRoot = $exp_tag . '.detproc.' . $det_id; # Root output name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
+my $outputFile = $exp_tag . '.detproc.' . $det_id; # Root name
+my $outputRoot = File::Spec->catfile( $workdir, $exp_tag, $outputFile );
+
+# output files:
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
Index: trunk/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11360)
@@ -87,9 +87,6 @@
     $workdir = $dir;
 }
-my $outputRoot = $exp_tag . '.detproc.' . $det_id; # Root name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
-print "OUTPUTROOT: $outputRoot\n";
-$input_uri = $ipprc->convert_filename_absolute( $input_uri );
-
+my $outputFile = "$exp_tag.detproc.$det_id"; # Root name
+my $outputRoot = File::Spec->catfile( $workdir, $exp_tag, $outputFile );
 my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
 my $outputBin1 = $ipprc->filename("PPIMAGE.BIN1", $outputRoot, $class_id);
@@ -97,4 +94,6 @@
 
 my $outputStats = $outputRoot . '.' . $class_id . '.stats';
+
+$input_uri = $ipprc->convert_filename_absolute( $input_uri );
 
 # Run ppImage
Index: trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11360)
@@ -95,8 +95,10 @@
 
 # Generate the file list, and get the statistics
-my $outputRoot = $exp_tag . '.detresid.' . $det_id . '.' . $iter; # Root output name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
+my $outputFile = "$exp_tag.detresid.$det_id.$iter"; # Root name
+my $outputRoot = File::Spec->catfile( $workdir, $exp_tag, $outputFile );
+
 my $list1Name = $outputRoot . '.b1.list'; # Name for the input file list for binning 1
 my $list2Name = $outputRoot . '.b2.list'; # Name for the input file list for binning 2
+
 my @means;			# Array of means
 my @variances;			# Array of variances
Index: trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_resid.pl	(revision 11360)
@@ -117,8 +117,7 @@
     $workdir = $dir;
 }
-my $outputRoot = $exp_tag . '.detresid.' . $det_id . '.' . $iter; # Root name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
-$input_uri = $ipprc->convert_filename_absolute( $input_uri );
-$detrend = $ipprc->convert_filename_absolute( $detrend ) if defined $detrend;
+
+my $outputFile = "$exp_tag.detresid.$det_id.$iter"; # Root name
+my $outputRoot = File::Spec->catfile( $workdir, $exp_tag, $outputFile );
 
 my $outputName = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id);
@@ -127,4 +126,7 @@
 
 my $outputStats = $outputRoot . '.' . $class_id . '.stats';
+
+$detrend = $ipprc->convert_filename_absolute( $detrend ) if defined $detrend;
+$input_uri = $ipprc->convert_filename_absolute( $input_uri );
 
 # Run ppImage
Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 11355)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 11360)
@@ -100,8 +100,10 @@
 
 # Stack the files
-my $outputRoot = $camera . '.' . $det_type . '.' . $det_id . '.' . $iter . '.' . $class_id; # Root name
-$outputRoot = File::Spec->catfile( $workdir, $outputRoot );
+my $outputFile = "$camera.$det_type.$det_id.$iter.$class_id"; # Root name
+my $outputSubD = "$camera.$det_type.$det_id";
+my $outputRoot = File::Spec->catfile( $workdir, $outputSubD, $outputFile );
 my $outputStack = $outputRoot . '.fits'; # Output name
 my $outputStats = $outputRoot . '.stats'; # Statistics name
+
 {
     my $command = "$ppMerge $outputStack"; # Command to run
