Index: /trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11359)
+++ /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 11359)
+++ /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 11359)
+++ /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 11359)
+++ /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 11359)
+++ /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 11359)
+++ /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 11359)
+++ /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
Index: /trunk/ippTasks/detrend.norm.pro
===================================================================
--- /trunk/ippTasks/detrend.norm.pro	(revision 11359)
+++ /trunk/ippTasks/detrend.norm.pro	(revision 11360)
@@ -23,4 +23,10 @@
 book init detPendingNormImfile
 book init detPendingNormExp
+
+macro detnorm.reset
+  book init detPendingNormStatImfile
+  book init detPendingNormImfile
+  book init detPendingNormExp
+end
 
 macro detnorm.status
@@ -120,5 +126,6 @@
     # XXX use ipp_filename.pl to lookup output file names
     $outroot = `ipp_datapath.pl $WORKDIR`
-    $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outroot/$CAMERA.$DET_TYPE.reject.$DET_ID.$ITERATION.log
     stdout $logfile
     stderr $logfile
@@ -234,4 +241,5 @@
     # XXX use ipp_filename.pl to lookup output file names
     $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
     $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
     stdout $logfile
@@ -345,4 +353,5 @@
     # XXX add $WORKDIR/$LOG_DIR
     $outroot = `ipp_datapath.pl $WORKDIR`
+    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
     $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
     stdout $logfile
Index: /trunk/ippTasks/detrend.process.pro
===================================================================
--- /trunk/ippTasks/detrend.process.pro	(revision 11359)
+++ /trunk/ippTasks/detrend.process.pro	(revision 11360)
@@ -23,6 +23,13 @@
 book init detPendingProcessedExp
 
+macro detproc.reset
+  book init detPendingProcessedImfile
+  book init detPendingProcessedExp
+end
+
 macro detproc.status
+  echo detPendingProcessedImfile
   book listbook detPendingProcessedImfile
+  echo detPendingProcessedExp
   book listbook detPendingProcessedExp
 end
@@ -117,8 +124,8 @@
     end
 
-    ## generate output log based on filerule
+    ## output log filename
     $outroot = `ipp_datapath.pl $WORKDIR`
     $outroot = $outroot/$EXP_TAG
-    $logfile = $outroot/$EXP_TAG.$CLASS_ID.detproc.$DET_ID.log
+    $logfile = $outroot/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
     stdout $logfile
     stderr $logfile
@@ -213,4 +220,5 @@
     if ($pageName == NULL) break
 
+    # XXX is ITERATION relevant here??
     book setword detPendingProcessedExp $pageName state RUN
     book getword detPendingProcessedExp $pageName det_id    -var DET_ID
Index: /trunk/ippTasks/detrend.reject.pro
===================================================================
--- /trunk/ippTasks/detrend.reject.pro	(revision 11359)
+++ /trunk/ippTasks/detrend.reject.pro	(revision 11360)
@@ -21,4 +21,8 @@
 
 book init detRejectExp
+
+macro detreject.reset
+  book init detRejectExp
+end
 
 macro detreject.status
@@ -101,5 +105,7 @@
     book getword detRejectExp $pageName mode      -var MODE     
     book getword detRejectExp $pageName camera    -var CAMERA   
-    book getword detRejectExp $pageName workdir   -var WORKDIR
+    # book getword detRejectExp $pageName workdir   -var WORKDIR
+    # XXX workdir is not being returned here
+    $WORKDIR = NONE
     book getword detRejectExp $pageName dbname    -var DBNAME
     set_standard_args
@@ -114,5 +120,6 @@
     # I'd like to add CAMERA to the log file...
     $outroot = `ipp_datapath.pl $WORKDIR`
-    $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.log
+    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outroot/$CAMERA.$DET_TYPE.reject.$DET_ID.$ITERATION.log
     stdout $logfile
     stderr $logfile
Index: /trunk/ippTasks/detrend.resid.pro
===================================================================
--- /trunk/ippTasks/detrend.resid.pro	(revision 11359)
+++ /trunk/ippTasks/detrend.resid.pro	(revision 11360)
@@ -22,4 +22,9 @@
 book init detPendingResidImfile
 book init detPendingResidExp
+
+macro detresid.reset
+  book init detPendingResidImfile
+  book init detPendingResidExp
+end
 
 macro detresid.status
@@ -122,5 +127,5 @@
     $outroot = `ipp_datapath.pl $WORKDIR`
     $outroot = $outroot/$EXP_TAG
-    $logfile = $outroot/$EXP_TAG.$CLASS_ID.detresid.$DET_ID.$ITERATION.log
+    $logfile = $outroot/$EXP_TAG.detresid.$DET_ID.$ITERATION.$CLASS_ID.log
     stdout $logfile
     stderr $logfile
Index: /trunk/ippTasks/detrend.stack.pro
===================================================================
--- /trunk/ippTasks/detrend.stack.pro	(revision 11359)
+++ /trunk/ippTasks/detrend.stack.pro	(revision 11360)
@@ -22,5 +22,10 @@
 book init detPendingStackedImfile
 
+macro detstack.reset
+  book init detPendingStackedImfile
+end
+
 macro detstack.status
+  echo detPendingStackedImfile
   book listbook detPendingStackedImfile
 end
@@ -115,6 +120,6 @@
     # XXX use ipp_filename.pl to lookup output file names
     $outroot = `ipp_datapath.pl $WORKDIR`
-    $outroot = $outroot/$EXP_TAG
-    $logfile = $outroot/$CAMERA.$DET_TYPE.$DET_ID.$ITERATION.$CLASS_ID.log
+    $outroot = $outroot/$CAMERA.$DET_TYPE.$DET_ID
+    $logfile = $outroot/$CAMERA.$DET_TYPE.stack.$DET_ID.$ITERATION.$CLASS_ID.log
     stdout $logfile
     stderr $logfile
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 11359)
+++ /trunk/ippTools/src/dettool.c	(revision 11360)
@@ -657,6 +657,7 @@
     {
         bool status = false;
-        psString exp_type = psMetadataLookupStr(&status, config->args, "-select_exp_type");        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_type");
+        psString exp_type = psMetadataLookupStr(&status, config->args, "-select_exp_type");        
+	if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -select_exp_type");
             return false;
         }
@@ -803,10 +804,4 @@
     }
 
-    psString exp_type = psMetadataLookupStr(&status, config->args, "-exp_type");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_type");
-        return false;
-    }
-
     psString filter = psMetadataLookupStr(&status, config->args, "-filter");
     if (!status) {
@@ -1034,5 +1029,5 @@
             camera,
             telescope,
-            exp_type,
+            "NA",
             filter,
             airmass_min,
