Index: /branches/eam_branch_20080121/ippScripts/scripts/camera_exp.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/camera_exp.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/camera_exp.pl	(revision 16176)
@@ -37,5 +37,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($exp_tag, $cam_id, $recipe, $camera, $dbname, $workdir, $reduction, $dvodb, $no_update, $no_op);
+my ($exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $no_update, $no_op);
 GetOptions(
 	   'exp_tag=s'          => \$exp_tag, # Exposure identifier
@@ -44,5 +44,5 @@
 	   'camera|c=s'        => \$camera, # Camera
 	   'dbname|d=s'        => \$dbname, # Database name
-	   'workdir|w=s'       => \$workdir, # Working directory
+	   'outroot|w=s'       => \$outroot, # output file base name
 	   'reduction=s'       => \$reduction, # Reduction class		       
 	   'dvodb|w=s'         => \$dvodb,  # output DVO database
@@ -55,7 +55,9 @@
 	  -msg => "Required options: --exp_tag --cam_id --camera",
 	  -exitval => 3,
-	  ) unless defined $exp_tag
-    and defined $cam_id
-    and defined $camera;
+	  ) unless 
+    defined $exp_tag and
+    defined $cam_id and
+    defined $outroot and
+    defined $camera;
 
 $ipprc->define_camera($camera);
@@ -136,4 +138,5 @@
 }
 
+### not needed to have such an extensive temp file name.
 my ($list1File, $list1Name) = tempfile( "$exp_tag.cm.$cam_id.b1.list.XXXX", UNLINK => 1 ); # For binning 1
 my ($list2File, $list2Name) = tempfile( "$exp_tag.cm.$cam_id.b2.list.XXXX", UNLINK => 1 ); # For binning 2
@@ -162,13 +165,11 @@
 
 # Output products
-$workdir = caturi( $workdir, $exp_tag ) if defined $workdir;
-my $outputRoot = $ipprc->file_prepare( "$exp_tag.cm.$cam_id", $workdir, ${$files}[0]->{path_base} );
-
-my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
-my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
-my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT.MEF", $outputRoot); # MEF psastro output
-
-my $traceDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".trace"; # Trace messages
-my $logDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".log"; # Log messages
+$ipprc->outroot_prepare($outroot);
+
+my $jpeg1      = $ipprc->filename("PPIMAGE.JPEG1", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2", 	$outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT.MEF", $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest    = $ipprc->filename("LOG.EXP", 	        $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 
 # convert supplied DVO database name to UNIX filename
@@ -184,5 +185,5 @@
     # Make the jpeg for binning 1
     {
-	my $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
+	my $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => 1);
@@ -196,5 +197,5 @@
     # Make the jpeg for binning 2
     {
-	my $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
+	my $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
 	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run(command => $command, verbose => 1);
@@ -229,5 +230,5 @@
 	    # XXX add a ppStats call which will collect the astrometry stats
 	    my $command;
-	    $command  = "$psastro -list $list3Name $outputRoot";
+	    $command  = "$psastro -list $list3Name $outroot";
 	    $command .= " +mosastro -chipastro";
 	    $command .= " -F PSASTRO.OUTPUT PSASTRO.OUTPUT.MEF";
@@ -276,5 +277,5 @@
 $fpaCommand .= " -cam_id $cam_id";
 $fpaCommand .= " -uri UNKNOWN";
-$fpaCommand .= " -path_base $outputRoot";
+$fpaCommand .= " -path_base $outroot";
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
 $fpaCommand .= $chipStats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/chip_imfile.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/chip_imfile.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/chip_imfile.pl	(revision 16176)
@@ -33,14 +33,14 @@
 
 # Parse the command-line arguments
-my ($exp_id, $chip_id, $class_id, $uri, $exp_tag, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($exp_id, $exp_tag, $chip_id, $class_id, $uri, $camera, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
 	   'exp_id=s'      => \$exp_id,    # Exposure identifier		       
+	   'exp_tag=s'     => \$exp_tag,   # Exposure identifier		       
 	   'chip_id=s'     => \$chip_id,   # Chiptool identifier		       
 	   'class_id=s'    => \$class_id,  # Class identifier		       
 	   'uri|u=s'       => \$uri,       # Input FITS file		       
 	   'camera|c=s'    => \$camera,	   # Camera			       
+	   'outroot|w=s'   => \$outroot,   # output file base name
 	   'dbname|d=s'    => \$dbname,    # Database name
-	   'exp_tag=s'     => \$exp_tag,    # Exposure identifier		       
-	   'workdir|w=s'   => \$workdir,   # Working directory, for output files  
 	   'reduction=s'   => \$reduction, # Reduction class		       
 	   'no-update'     => \$no_update, # Don't update the database?	       
@@ -49,12 +49,13 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --exp_id --exp_tag --chip_id --class_id --uri --camera",
+pod2usage( -msg => "Required options: --exp_id --exp_tag --chip_id --class_id --uri --camera --outroot",
 	   -exitval => 3) unless
     defined $exp_id and
+    defined $exp_tag and
     defined $chip_id and
     defined $class_id and
     defined $uri and
-    defined $exp_tag and
-    defined $camera;
+    defined $camera and
+    defined $outroot;
 
 $ipprc->define_camera($camera);
@@ -100,21 +101,27 @@
 &my_die("Couldn't find input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);
 
-$workdir = caturi( $workdir, $exp_tag ) if defined $workdir;
-
-my $outputRoot  = $ipprc->file_prepare( "$exp_tag.ch.$chip_id", $workdir, $uri );
-
-my $outputImage = $ipprc->filename("PPIMAGE.CHIP",      $outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $outputMask  = $ipprc->filename("PPIMAGE.CHIP.MASK", $outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $outputWeight  = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",      $outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",  	$outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-my $outputStats = $ipprc->filename("PPIMAGE.STATS", 	$outputRoot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-
-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);
+
+## these names are used in ppImage, and thus may be URIs
+my $outputImage   = $ipprc->filename("PPIMAGE.CHIP",        $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $outputMask    = $ipprc->filename("PPIMAGE.CHIP.MASK",   $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $outputWeight  = $ipprc->filename("PPIMAGE.CHIP.WEIGHT", $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $outputBin1    = $ipprc->filename("PPIMAGE.BIN1",        $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $outputBin2    = $ipprc->filename("PPIMAGE.BIN2",  	    $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $outputStats   = $ipprc->filename("PPIMAGE.STATS", 	    $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $traceDest     = $ipprc->filename("TRACE.IMFILE", 	    $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest       = $ipprc->filename("LOG.IMFILE", 	    $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # Run ppImage
 unless ($no_op) {
-    my $command = "$ppImage -file $uri $outputRoot";
+    ## XXX can we convert ppImage log and trace to use the filerules to generate consistent names
+    ## XXX also stats: output should be implied by $outroot
+    my $command = "$ppImage -file $uri $outroot";
     $command .= " -recipe PPIMAGE $recipe";
     $command .= " -recipe PPSTATS CHIPSTATS";
@@ -130,10 +137,10 @@
     }
 
-    &my_die("Couldn't find expected output file: $outputImage\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
-    &my_die("Couldn't find expected output file: $outputMask\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-    &my_die("Couldn't find expected output file: $outputWeight\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
-    &my_die("Couldn't find expected output file: $outputBin1\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
-    &my_die("Couldn't find expected output file: $outputBin2\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
-    &my_die("Couldn't find expected output file: $outputStats\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
+    &my_die("Couldn't find expected output file: $outputImage\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
+    &my_die("Couldn't find expected output file: $outputMask\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+    &my_die("Couldn't find expected output file: $outputWeight\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
+    &my_die("Couldn't find expected output file: $outputBin1\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
+    &my_die("Couldn't find expected output file: $outputBin2\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
+    &my_die("Couldn't find expected output file: $outputStats\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStats);
 
     # Get the statistics on the processed image
@@ -162,5 +169,5 @@
 $command .= " -class_id $class_id";
 $command .= " -uri $outputImage";
-$command .= " -path_base $outputRoot";
+$command .= " -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_apply.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_apply.pl	(revision 16176)
@@ -33,5 +33,5 @@
 
 # Parse the command-line
-my ($det_id, $iter, $class_id, $value, $input_uri, $camera, $det_type, $dbname, $workdir, $no_update, $no_op);
+my ($det_id, $iter, $class_id, $value, $input_uri, $camera, $det_type, $outroot, $dbname, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,     # Detrend ID				
@@ -42,6 +42,6 @@
     'camera|c=s'        => \$camera,	 # Camera				
     'det_type|t=s'      => \$det_type,	 # Detrend type				
+    'outroot|w=s'       => \$outroot,    # output file base name
     'dbname|d=s'        => \$dbname,	 # Database name				
-    'workdir|w=s'       => \$workdir, 	 # Working directory, for output files	
     'no-update'         => \$no_update,	 # Don't update the database		
     'no-op'             => \$no_op,	 # Don't do any operations               
@@ -49,13 +49,14 @@
     
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type",
-	   -exitval => 3) 
-    unless defined $det_id
-    and defined $iter
-    and defined $class_id
-    and defined $value
-    and defined $input_uri
-    and defined $camera
-    and defined $det_type;
+pod2usage( -msg => "Required options: --det_id --iteration --class_id --value --input_uri --camera --det_type --outroot",
+	   -exitval => 3) unless 
+    defined $det_id    and 
+    defined $iter      and 
+    defined $class_id  and 
+    defined $value     and 
+    defined $input_uri and 
+    defined $camera    and 
+    defined $det_type  and
+    defined $outroot;
 
 $ipprc->define_camera($camera);
@@ -90,19 +91,22 @@
 &my_die("Couldn't find input file: $input_uri\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
 
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-
-my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir, $input_uri );
-
-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 = $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 $output    = $ipprc->filename("PPIMAGE.OUTPUT", $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $b1name    = $ipprc->filename("PPIMAGE.BIN1",   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $b2name    = $ipprc->filename("PPIMAGE.BIN2",   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $statsName = $ipprc->filename("PPIMAGE.STATS",  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $traceDest = $ipprc->filename("TRACE.IMFILE",   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest   = $ipprc->filename("LOG.IMFILE", 	   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $iter, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # Run normalisation
 unless ($no_op) {
-    my $command = "$ppImage -file $input_uri $outputRoot";
+    my $command = "$ppImage -file $input_uri $outroot";
     $command .= " -norm $value -stats $statsName";
     $command .= " -recipe PPIMAGE $RECIPE_PPIMAGE";
@@ -118,7 +122,7 @@
 	&my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $class_id, $error_code);
     }
-    &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($output);
-    &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b1name);
-    &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b2name);
+    &my_die("Can't find expected output file: $output",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($output);
+    &my_die("Can't find expected output file: $b1name",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b1name);
+    &my_die("Can't find expected output file: $b2name",    $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($b2name);
     &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $ipprc->file_resolve($statsName);
     
@@ -149,5 +153,5 @@
 $command .= " -class_id $class_id";
 $command .= " -uri $output";
-$command .= " -path_base $outputRoot";
+$command .= " -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_calc.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_calc.pl	(revision 16176)
@@ -32,10 +32,10 @@
 
 # Parse command-line arguments
-my ($det_id, $iter, $detType, $workdir, $dbname, $no_update, $no_op);
+my ($det_id, $iter, $detType, $outroot, $dbname, $no_update, $no_op);
 GetOptions(
 	'det_id|d=s'	=> \$det_id,    # Detrend id			     
 	'iteration|i=s'	=> \$iter,	# Iteration			     
 	'det_type|t=s'  => \$detType,	# Detrend type			     
-	'workdir|w=s'   => \$workdir,	# Working directory for output files 
+        'outroot|w=s'   => \$outroot,   # output file base name
  	'dbname|d=s'    => \$dbname,	# Database name			     
         'no-update'     => \$no_update,	# Don't update the database?	     
@@ -44,10 +44,11 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options --det_id --iteration --det_type",
+pod2usage( -msg => "Required options --det_id --iteration --det_type --outroot",
 	   -exitval => 3,
-	   ) 
-    unless defined $det_id
-    and defined $iter
-    and defined $detType;
+	   ) unless 
+    defined $det_id  and 
+    defined $iter    and 
+    defined $detType and
+    defined $outroot;
 
 use constant STATISTIC => 'bg'; # Background statistic to use from the database
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_exp.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_norm_exp.pl	(revision 16176)
@@ -35,5 +35,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($det_id, $iter, $det_type, $camera, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -41,6 +41,6 @@
 	   'camera|c=s'        => \$camera,
 	   'det_type|t=s'      => \$det_type,
+	   '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,
 	   'no-update'         => \$no_update,
@@ -49,10 +49,11 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --camera --det_type",
-	   -exitval => 3)
-    unless defined $det_id
-    and defined $iter
-    and defined $camera
-    and defined $det_type;
+pod2usage( -msg => "Required options: --det_id --iteration --camera --det_type --outroot",
+	   -exitval => 3) unless 
+    defined $det_id   and 
+    defined $iter     and 
+    defined $camera   and 
+    defined $det_type and
+    defined $outroot;
 
 $ipprc->define_camera($camera);
@@ -126,13 +127,18 @@
 close $list2File;
 
-# Output products
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-my $outputRoot = $ipprc->file_prepare( "$camera.$det_type.norm.$det_id.$iter", $workdir );
-my $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
-my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
+# 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 $jpeg1Name = $ipprc->filename("PPIMAGE.JPEG1", $outroot); # Binned JPEG #1
+my $jpeg2Name = $ipprc->filename("PPIMAGE.JPEG2", $outroot); # Binned JPEG #2
 
 unless ($no_op) {
     # Make the jpeg for binning 1
-    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
+    $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -140,5 +146,5 @@
     
     # Make the jpeg for binning 2
-    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
+    $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -152,5 +158,5 @@
 $command .= " -iteration $iter";
 $command .= " -recip $recipe1,$recipe2";
-$command .= " -path_base $outputRoot ";
+$command .= " -path_base $outroot ";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_exp.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_exp.pl	(revision 16176)
@@ -35,5 +35,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_id, $det_type, $exp_tag, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($det_id, $exp_id, $det_type, $exp_tag, $camera, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -42,6 +42,6 @@
     'exp_tag|=s'        => \$exp_tag,
     'camera|c=s'        => \$camera,
+    '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,
     'no-update'         => \$no_update,
@@ -50,11 +50,12 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --det_type --exp_id --exp_tag --camera",
-	   -exitval => 3) 
-    unless defined $det_id
-    and defined $det_type
-    and defined $exp_id
-    and defined $exp_tag
-    and defined $camera;
+pod2usage( -msg => "Required options: --det_id --det_type --exp_id --exp_tag --camera --outroot",
+	   -exitval => 3) unless 
+    defined $det_id   and 
+    defined $det_type and 
+    defined $exp_id   and 
+    defined $exp_tag  and 
+    defined $camera   and
+    defined $outroot;
 
 $ipprc->define_camera($camera);
@@ -129,13 +130,18 @@
 close $list2File;
 
-# Output files
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-my $outputRoot = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, ${$files}[0]->{path_base} );
-my $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
-my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
+# 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 $jpeg1 = $ipprc->filename("PPIMAGE.JPEG1", $outroot); # Binned JPEG #1
+my $jpeg2 = $ipprc->filename("PPIMAGE.JPEG2", $outroot); # Binned JPEG #2
 
 unless ($no_op) {
     # Make the jpeg for binning 1
-    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
+    $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -147,5 +153,5 @@
     
     # Make the jpeg for binning 2
-    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
+    $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -161,5 +167,5 @@
 $command .= " -det_id $det_id";
 $command .= " -exp_id $exp_id";
-$command .= " -recip $recipe1,$recipe2 -path_base $outputRoot";
+$command .= " -recip $recipe1,$recipe2 -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_imfile.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_process_imfile.pl	(revision 16176)
@@ -32,5 +32,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($det_id, $exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -41,6 +41,6 @@
     'input_uri|u=s'     => \$input_uri,
     'camera|c=s'        => \$camera,
+    '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,
@@ -49,13 +49,14 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --exp_id --class_id --det_type --exp_tag --input_uri --camera",
-	   -exitval => 3)
-    unless defined $det_id
-    and defined $exp_id
-    and defined $class_id
-    and defined $det_type
-    and defined $exp_tag
-    and defined $input_uri
-    and defined $camera;
+pod2usage( -msg => "Required options: --det_id --exp_id --class_id --det_type --exp_tag --input_uri --camera --outroot",
+	   -exitval => 3) unless 
+    defined $det_id    and
+    defined $exp_id    and 
+    defined $class_id  and 
+    defined $det_type  and 
+    defined $exp_tag   and 
+    defined $input_uri and 
+    defined $camera    and 
+    defined $outroot;
 
 # XXX this exits with status = 0 on failure
@@ -88,19 +89,22 @@
 &my_die("Couldn't find input file: $input_uri\n", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
 
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
+# outroot examples (HOST components must be set)
+# file://data/ipp004.0/gpc1/20080130
+# neb:///ipp004-v1/gpc1/20080130
+# neb:///*/gpc1/20080130 (volume not specified)
 
-my $outputRoot  = $ipprc->file_prepare( "$exp_tag/$exp_tag.detproc.$det_id", $workdir, $input_uri );
+# check for existing directory, generate if needed
+$ipprc->outroot_prepare($outroot);
 
-my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
-my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",   $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
-my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",   $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
-my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outputRoot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
-
-my $traceDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".$class_id.trace"; # Trace messages
-my $logDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".$class_id.log"; # Log messages
+my $outputImage = $ipprc->filename("PPIMAGE.OUTPUT", $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
+my $outputBin1  = $ipprc->filename("PPIMAGE.BIN1",   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
+my $outputBin2  = $ipprc->filename("PPIMAGE.BIN2",   $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
+my $outputStats = $ipprc->filename("PPIMAGE.STATS",  $outroot, $class_id) or &my_die("Missing entry from camera config", $det_id, $exp_id, $class_id, $PS_EXIT_PROG_ERROR);
+my $traceDest   = $ipprc->filename("TRACE.IMFILE",   $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
+my $logDest     = $ipprc->filename("LOG.IMFILE",     $outroot, $class_id) or &my_die("Missing entry from camera config", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
 
 # Run ppImage
 unless ($no_op) {
-    my $command = "$ppImage -file $input_uri $outputRoot";
+    my $command = "$ppImage -file $input_uri $outroot";
     $command .= " -recipe PPIMAGE $recipe";
     $command .= " -recipe PPSTATS CHIPSTATS";
@@ -141,5 +145,5 @@
 $command .= " -class_id $class_id";
 $command .= " -recip $reduction";
-$command .= " -uri $outputImage -path_base $outputRoot";
+$command .= " -uri $outputImage -path_base $outroot";
 $command .= " -dbname $dbname" if defined $dbname;
 $command .= $stats->cmdflags();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_exp.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_exp.pl	(revision 16176)
@@ -37,5 +37,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $filter, $workdir, $dbname, $no_update, $no_op);
+my ($det_id, $iter, $det_type, $camera, $outroot, $filter, $dbname, $no_update, $no_op);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -43,6 +43,6 @@
 	   'det_type|t=s'      => \$det_type,
 	   'camera=s'          => \$camera,
+	   'outroot|w=s'   => \$outroot,   # output file base name
 	   'filter=s'          => \$filter,
-	   'workdir|w=s'       => \$workdir, # Working directory for output files
 	   'dbname|d=s'        => \$dbname, # Database name
 	   'no-update'         => \$no_update,
@@ -51,10 +51,11 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --det_type --camera",
-	   -exitval => 3)
-    unless defined $det_id
-    and defined $iter
-    and defined $det_type
-    and defined $camera;
+pod2usage( -msg => "Required options: --det_id --iteration --det_type --camera --outroot",
+	   -exitval => 3) unless 
+    defined $det_id   and 
+    defined $iter     and 
+    defined $det_type and 
+    defined $camera   and
+    defined $outroot;
 
 # values to extract from output metadata and the stats to calculate
@@ -141,7 +142,13 @@
 my $reject_meanstdev = rejection_limit( 'ENSEMBLE.MEANSTDEV', $det_type, $filter );
 
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-
-my $logName = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.detreject.log", $workdir ); # Name for log
+# 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 $logName = $outroot . "log"; # Name for log
 
 my $logFile;
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_imfile.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_reject_imfile.pl	(revision 16176)
@@ -43,5 +43,5 @@
 
 # parse the command-line options
-my ($det_id, $iter, $exp_id, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $workdir, $reduction, $no_update, $no_op);
+my ($det_id, $iter, $exp_id, $exp_tag, $det_type, $camera, $filter, $reject, $outroot, $dbname, $reduction, $no_update, $no_op);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -51,8 +51,8 @@
 	   'det_type|t=s'      => \$det_type,
 	   'camera=s'          => \$camera,
+	   'outroot|w=s'       => \$outroot,   # output file base name
 	   'filter=s'          => \$filter,
 	   'reject'            => \$reject,
 	   'dbname|d=s'        => \$dbname, # Database name
-	   'workdir|w=s'       => \$workdir, # Working directory, for output files
 	   'reduction|=s'      => \$reduction,
 	   'no-update'         => \$no_update,
@@ -61,12 +61,13 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --det_type --camera",
-	   -exitval => 3)
-    unless defined $det_id
-    and defined $iter
-    and defined $exp_id
-    and defined $exp_tag
-    and defined $det_type
-    and defined $camera;
+pod2usage( -msg => "Required options: --det_id --iteration --exp_id --exp_tag --det_type --camera --outroot",
+	   -exitval => 3) unless 
+    defined $det_id   and 
+    defined $iter     and 
+    defined $exp_id   and 
+    defined $exp_tag  and 
+    defined $det_type and 
+    defined $camera   and
+    defined $outroot;
 
 # load IPP config information for the specified camera
@@ -144,10 +145,15 @@
 }
 
-# Output products
-$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, ${$files}[0]->{path_base} );
-my $jpeg1Name  = $ipprc->filename("PPIMAGE.JPEG1", $outputRoot); # Binned JPEG #1
-my $jpeg2Name  = $ipprc->filename("PPIMAGE.JPEG2", $outputRoot); # Binned JPEG #2
-my $logName    = $ipprc->filename("LOG.EXP", $outputRoot); # Name for log
+# 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 $jpeg1Name  = $ipprc->filename("PPIMAGE.JPEG1", $outroot); # Binned JPEG #1
+my $jpeg2Name  = $ipprc->filename("PPIMAGE.JPEG2", $outroot); # Binned JPEG #2
+my $logName    = $ipprc->filename("LOG.EXP",       $outroot); # Name for log
 
 my $logFile;
@@ -170,5 +176,5 @@
 unless ($no_op) {
     # Make the jpeg for binning 1
-    $command = "$ppImage -list $list1Name $outputRoot -recipe PPIMAGE $recipe1"; # Command to run
+    $command = "$ppImage -list $list1Name $outroot -recipe PPIMAGE $recipe1"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -180,5 +186,5 @@
     
     # Make the jpeg for binning 2
-    $command = "$ppImage -list $list2Name $outputRoot -recipe PPIMAGE $recipe2"; # Command to run
+    $command = "$ppImage -list $list2Name $outroot -recipe PPIMAGE $recipe2"; # Command to run
     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -502,5 +508,5 @@
 
 $command  = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_id $exp_id";
-$command .= " -recip $recipe1,$recipe2 -path_base $outputRoot ";
+$command .= " -recip $recipe1,$recipe2 -path_base $outroot ";
 $command .= ' -reject' if $reject;
 $command .= " -dbname $dbname" if defined $dbname;
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_resid.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_resid.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_resid.pl	(revision 16176)
@@ -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();
Index: /branches/eam_branch_20080121/ippScripts/scripts/detrend_stack.pl
===================================================================
--- /branches/eam_branch_20080121/ippScripts/scripts/detrend_stack.pl	(revision 16175)
+++ /branches/eam_branch_20080121/ippScripts/scripts/detrend_stack.pl	(revision 16176)
@@ -33,5 +33,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $workdir, $reduction, $no_update, $no_op, $quiet);
+my ($det_id, $iter, $class_id, $det_type, $camera, $outroot, $dbname, $reduction, $no_update, $no_op, $quiet);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -40,6 +40,6 @@
     'det_type|t=s'      => \$det_type,
     'camera|c=s'        => \$camera,
+    '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 for processing
     'no-update'         => \$no_update,
@@ -49,11 +49,12 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera", 
-	   -exitval => 3) 
-    unless defined $det_id
-    and defined $iter
-    and defined $class_id
-    and defined $det_type
-    and defined $camera;
+pod2usage( -msg => "Required options: --det_id --iteration --class_id --det_type --camera --outroot", 
+	   -exitval => 3) unless 
+    defined $det_id   and 
+    defined $iter     and 
+    defined $class_id and 
+    defined $det_type and 
+    defined $camera   and
+    defined $outroot;
 
 my $verbose = 1;
@@ -111,12 +112,17 @@
 }
 
-$workdir = caturi( $workdir, "$camera.$det_type.$det_id" ) if defined $workdir;
-
-my $outputRoot  = $ipprc->file_prepare( "$camera.$det_type.$det_id.$iter.$class_id", $workdir, ${$files}[0]->{uri} );
-my $outputStack = $outputRoot . '.fits'; # Output name
-my $outputStats = $outputRoot . '.stats'; # Statistics name
-
-my $traceDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".trace"; # Trace messages
-my $logDest = 'file:' . $ipprc->file_resolve($outputRoot) . ".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);
+
+## XXX should we be using the filerules here?
+my $outputStack = $outroot . '.fits'; # Output name
+my $outputStats = $outroot . '.stats'; # Statistics name
+my $traceDest   = $outroot . '.trace'; # Trace messages
+my $logDest     = $outroot . '.log'; # Log messages
 
 $command = "$ppMerge $outputStack"; # Command to run
Index: /branches/eam_branch_20080121/ippTasks/camera.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/camera.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/camera.pro	(revision 16176)
@@ -122,5 +122,5 @@
     book getword camPendingExp $pageName exp_tag -var EXP_TAG
     book getword camPendingExp $pageName cam_id -var CAM_ID
-    book getword camPendingExp $pageName workdir -var WORKDIR
+    book getword camPendingExp $pageName workdir -var WORKDIR_TEMPLATE
     book getword camPendingExp $pageName dvodb  -var DVODB
     book getword camPendingExp $pageName dbname -var DBNAME
@@ -130,25 +130,26 @@
     set.host.for.camera $camera FPA
 
-    # output log from filerule
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s" $outpath $EXP_TAG
-    sprintf outroot "%s/%s.cm.%s" $outpath $EXP_TAG $CAM_ID
+    # raw workdir examples:
+    # file://data/@HOST@.0/gpc1/20080130
+    # neb:///@HOST@-vol0/gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+    # out workdir examples:
+    # file://data/ipp004.0/gpc1/20080130
+    # neb:///ipp004-vol0/gpc1/20080130
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s/%s.cm.%s" $WORKDIR $EXP_TAG $EXP_TAG $CAM_ID
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.EXP --camera $CAMERA --class_id NONE --basename $outroot`
     if ("$logfile" == "") 
-      $logfile = $outroot.log
+      echo "WARNING: logfile not defined in camera.pro:146"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
 
-    $run = camera_exp.pl --exp_tag $EXP_TAG --cam_id $CAM_ID --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+    $run = camera_exp.pl --exp_tag $EXP_TAG --cam_id $CAM_ID --camera $CAMERA --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
Index: /branches/eam_branch_20080121/ippTasks/chip.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/chip.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/chip.pro	(revision 16176)
@@ -121,5 +121,5 @@
     book getword chipPendingImfile $pageName exp_tag -var EXP_TAG
     book getword chipPendingImfile $pageName chip_id -var CHIP_ID
-    book getword chipPendingImfile $pageName workdir -var WORKDIR
+    book getword chipPendingImfile $pageName workdir -var WORKDIR_TEMPLATE
     book getword chipPendingImfile $pageName class_id -var CLASS_ID
     book getword chipPendingImfile $pageName uri -var URI
@@ -130,25 +130,26 @@
     set.host.for.camera $camera $class_id
 
-    ## generate output log based on filerule
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s" $outpath $EXP_TAG
-    sprintf outroot "%s/%s.ch.%s" $outpath $EXP_TAG $CHIP_ID
+    # raw workdir examples:
+    # file://data/@HOST@.0/gpc1/20080130
+    # neb:///@HOST@-vol0/gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
+    set.workdir.by.camera $CAMERA $CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+    # out workdir examples:
+    # file://data/ipp004.0/gpc1/20080130
+    # neb:///ipp004-vol0/gpc1/20080130
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s/%s.ch.%s" $WORKDIR $EXP_TAG $EXP_TAG $CHIP_ID
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
     if ("$logfile" == "") 
-      sprintf logfile "%s.%s.log" $outroot $CLASS_ID
+      echo "WARNING: logfile not defined in chip.pro:152"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
 
-    $run = chip_imfile.pl --exp_id $EXP_ID --chip_id $CHIP_ID --class_id $CLASS_ID --exp_tag $EXP_TAG --uri $URI --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+    $run = chip_imfile.pl --exp_id $EXP_ID --chip_id $CHIP_ID --class_id $CLASS_ID --exp_tag $EXP_TAG --uri $URI --camera $CAMERA --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
Index: /branches/eam_branch_20080121/ippTasks/detrend.norm.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/detrend.norm.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/detrend.norm.pro	(revision 16176)
@@ -153,5 +153,5 @@
     book getword detPendingNormStatImfile $pageName iteration -var ITERATION
     book getword detPendingNormStatImfile $pageName camera    -var CAMERA  
-    book getword detPendingNormStatImfile $pageName workdir   -var WORKDIR
+    book getword detPendingNormStatImfile $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingNormStatImfile $pageName dbname    -var DBNAME
 
@@ -159,19 +159,18 @@
     set.host.for.camera $camera FPA
 
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.log
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s.%s.norm.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID $ITERATION
+
+    ## generate output log (NOT based on filerule?)
+    $logfile = "$outroot.log"
+    $logfile = `ipp_datapath.pl $logfile`
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_norm_calc.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --outroot $outroot
     add_standard_args run
 
@@ -271,5 +270,5 @@
     book getword detPendingNormImfile $pageName class_id  -var CLASS_ID 
     book getword detPendingNormImfile $pageName norm      -var NORM     
-    book getword detPendingNormImfile $pageName workdir   -var WORKDIR
+    book getword detPendingNormImfile $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingNormImfile $pageName dbname    -var DBNAME
 
@@ -277,20 +276,18 @@
     set.host.for.camera $camera $class_id
 
-    # XXX use ipp_filename.pl to lookup output file names
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.$CLASS_ID.log
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA $CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this stack (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s.%s.norm.%s.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID $ITERATION $CLASS_ID
+
+    ## generate output log (NOT based on filerule?)
+    $logfile = "$outroot.log"
+    $logfile = `ipp_datapath.pl $logfile`
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_norm_apply.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_norm_apply.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --value $NORM --input_uri $URI --camera $CAMERA --det_type $DET_TYPE --outroot $outroot
     add_standard_args run
     
@@ -387,5 +384,5 @@
     book getword detPendingNormExp $pageName det_type  -var DET_TYPE
     book getword detPendingNormExp $pageName camera    -var CAMERA  
-    book getword detPendingNormExp $pageName workdir   -var WORKDIR
+    book getword detPendingNormExp $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingNormExp $pageName dbname    -var DBNAME
 
@@ -393,20 +390,18 @@
     set.host.for.camera $camera FPA
 
-    # XXX add $WORKDIR/$LOG_DIR
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    $outpath = $outpath/$CAMERA.$DET_TYPE.$DET_ID
-    $logfile = $outpath/$CAMERA.$DET_TYPE.norm.$DET_ID.$ITERATION.log
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s.%s.norm.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID $ITERATION
+
+    ## generate output log (NOT based on filerule?)
+    $logfile = "$outroot.log"
+    $logfile = `ipp_datapath.pl $logfile`
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE 
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_norm_exp.pl --det_id $DET_ID --iteration $ITERATION --camera $CAMERA --det_type $DET_TYPE  --outroot $outroot
     add_standard_args run
 
Index: /branches/eam_branch_20080121/ippTasks/detrend.process.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/detrend.process.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/detrend.process.pro	(revision 16176)
@@ -143,5 +143,5 @@
     book getword detPendingProcessedImfile $pageName uri      -var URI      
     book getword detPendingProcessedImfile $pageName camera   -var CAMERA   
-    book getword detPendingProcessedImfile $pageName workdir  -var WORKDIR
+    book getword detPendingProcessedImfile $pageName workdir  -var WORKDIR_TEMPLATE
     book getword detPendingProcessedImfile $pageName dbname   -var DBNAME
     book getword detPendingProcessedImfile $pageName reduction -var REDUCTION
@@ -150,25 +150,21 @@
     set.host.for.camera $camera $class_id
 
-    ## output log filename
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s/%s" $outpath $CAMERA $DET_TYPE $DET_ID $EXP_TAG
-    sprintf outroot "%s/%s.detproc.%s" $outpath $EXP_TAG $DET_ID
+    # see chip.pro for examples
+    set.workdir.by.camera $CAMERA $CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s/%s.detproc.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
     if ("$logfile" == "") 
-      sprintf logfile "%s.%s.log" $outroot $CLASS_ID
+      echo "WARNING: logfile not defined in detrend.process.pro:161"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_process_imfile.pl --det_id $DET_ID --exp_id $EXP_ID --det_type $DET_TYPE --class_id $CLASS_ID --exp_tag $EXP_TAG --input_uri $URI --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_process_imfile.pl --det_id $DET_ID --exp_id $EXP_ID --det_type $DET_TYPE --class_id $CLASS_ID --exp_tag $EXP_TAG --input_uri $URI --camera $CAMERA --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
@@ -269,30 +265,30 @@
     book getword detPendingProcessedExp $pageName camera    -var CAMERA  
     book getword detPendingProcessedExp $pageName exp_tag   -var EXP_TAG
-    book getword detPendingProcessedExp $pageName workdir   -var WORKDIR
+    book getword detPendingProcessedExp $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingProcessedExp $pageName dbname    -var DBNAME
+    book getword detPendingProcessedExp $pageName reduction -var REDUCTION
 
     # specify choice of local or remote host based on camera and chip (class_id)
     set.host.for.camera $camera FPA
 
-    # XXX push this into the filerules?
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s/%s" $outpath $CAMERA $DET_TYPE $DET_ID $EXP_TAG
-    sprintf outroot "%s/%s.detproc.%s" $outpath $EXP_TAG $DET_ID
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s/%s.detproc.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.EXP --camera $CAMERA --class_id NONE --basename $outroot`
     if ("$logfile" == "") 
-      $logfile = $outroot.log
+      echo "WARNING: logfile not defined in detrend.process.pro:282"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_process_exp.pl --det_id $DET_ID --exp_id $EXP_ID --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
+
+    $run = detrend_process_exp.pl --det_id $DET_ID --exp_id $EXP_ID --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA --outroot $outroot
+    if ("$REDUCTION" != "NULL")
+      $run = $run --reduction $REDUCTION
     end
     add_standard_args run
Index: /branches/eam_branch_20080121/ippTasks/detrend.reject.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/detrend.reject.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/detrend.reject.pro	(revision 16176)
@@ -122,5 +122,5 @@
     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_TEMPLATE
     book getword detRejectExp $pageName dbname    -var DBNAME
 
@@ -128,19 +128,18 @@
     set.host.for.camera $camera FPA
 
-    if ("$WORKDIR" == "NULL")
-      $outroot = `pwd`
-    else
-      $outroot = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outroot "%s/%s.%s.%s" $outroot $CAMERA $DET_TYPE $DET_ID
-    sprintf logfile "%s/%s.%s.%s.%s.detreject.log" $outroot $CAMERA $DET_TYPE $DET_ID $ITERATION
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s/%s.detreject.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID $ITERATION
+
+    ## generate output log based on filerule (convert the URI to a PATH)
+    $logfile = $outroot.log
+    $logfile = `ipp_datapath.pl $logfile`
+
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outroot
 
-    $run = detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+    $run = detrend_reject_exp.pl --det_id $DET_ID --iteration $ITERATION --det_type $DET_TYPE --camera $CAMERA --outroot $outroot
     add_standard_args run
 
Index: /branches/eam_branch_20080121/ippTasks/detrend.resid.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/detrend.resid.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/detrend.resid.pro	(revision 16176)
@@ -143,5 +143,5 @@
     book getword detPendingResidImfile $pageName det_uri   -var DET_URI  
     book getword detPendingResidImfile $pageName camera    -var CAMERA   
-    book getword detPendingResidImfile $pageName workdir   -var WORKDIR
+    book getword detPendingResidImfile $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingResidImfile $pageName dbname    -var DBNAME
     book getword detPendingResidImfile $pageName reduction -var REDUCTION
@@ -150,25 +150,21 @@
     set.host.for.camera $camera $class_id
 
-    # XXX use ipp_filename.pl to lookup output file names
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s/%s" $outpath $CAMERA $DET_TYPE $DET_ID $EXP_TAG
-    sprintf outroot "%s/%s.detresid.%s.%s" $outpath $EXP_TAG $DET_ID $ITERATION
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA $CLASS_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s/%s.detresid.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID $ITERATION
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
     if ("$logfile" == "") 
-      sprintf logfile "%s.%s.log" $outroot $CLASS_ID
+      echo "WARNING: logfile not defined in detrend.resid.pro:161"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_resid.pl --det_id $DET_ID --iteration $ITERATION --exp_id $EXP_ID --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URI --input_uri $URI --camera $CAMERA --mode $MODE
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_resid.pl --det_id $DET_ID --iteration $ITERATION --exp_id $EXP_ID --exp_tag $EXP_TAG --class_id $CLASS_ID --det_type $DET_TYPE --detrend $DET_URI --input_uri $URI --camera $CAMERA --mode $MODE --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
@@ -272,5 +268,5 @@
     book getword detPendingResidExp $pageName include   -var INCLUDE 
     book getword detPendingResidExp $pageName camera    -var CAMERA  
-    book getword detPendingResidExp $pageName workdir   -var WORKDIR
+    book getword detPendingResidExp $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingResidExp $pageName dbname    -var DBNAME
 
@@ -278,22 +274,21 @@
     set.host.for.camera $camera FPA
 
-    # XXX use ipp_filename.pl to lookup output file names
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s/%s" $outpath $CAMERA $DET_TYPE $DET_ID $EXP_TAG
-    sprintf outroot "%s/%s.detresid.%s.%s" $outpath $EXP_TAG $DET_ID $ITERATION
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s/%s.detresid.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $EXP_TAG $EXP_TAG $DET_ID $ITERATION
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id NONE --basename $outroot`
+    if ("$logfile" == "") 
+      echo "WARNING: logfile not defined in detrend.process.pro:285"
+      break
+    end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
-
-    $run = detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_id $EXP_ID --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+
+    $run = detrend_reject_imfile.pl --det_id $DET_ID --iteration $ITERATION --exp_id $EXP_ID --exp_tag $EXP_TAG --det_type $DET_TYPE --camera $CAMERA --outroot $outroot
     add_standard_args run
 
Index: /branches/eam_branch_20080121/ippTasks/detrend.stack.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/detrend.stack.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/detrend.stack.pro	(revision 16176)
@@ -123,5 +123,5 @@
     book getword detPendingStackedImfile $pageName class_id  -var CLASS_ID
     book getword detPendingStackedImfile $pageName camera    -var CAMERA  
-    book getword detPendingStackedImfile $pageName workdir   -var WORKDIR
+    book getword detPendingStackedImfile $pageName workdir   -var WORKDIR_TEMPLATE
     book getword detPendingStackedImfile $pageName dbname    -var DBNAME
     book getword detPendingStackedImfile $pageName reduction -var REDUCTION
@@ -130,31 +130,28 @@
     set.host.for.camera $camera $class_id
 
-    if ("$WORKDIR" == "NULL")
-      $outpath = `pwd`
-    else
-      $outpath = `ipp_datapath.pl $WORKDIR`
-    end
-    sprintf outpath "%s/%s.%s.%s" $outpath $CAMERA $DET_TYPE $DET_ID
-    sprintf outroot "%s/%s.%s.%s.%s" $outpath $CAMERA $DET_TYPE $DET_ID $ITERATION
+    # set workdir (interpolate host; see camera.pro for examples)
+    set.workdir.by.camera $CAMERA FPA $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    ## generate outroot specific to this exposure (& chip)
+    sprintf outroot "%s/%s.%s.%s/%s.%s.%s.%s" $WORKDIR $CAMERA $DET_TYPE $DET_ID $CAMERA $DET_TYPE $DET_ID $ITERATION
+
+    ## generate output log based on filerule (convert the URI to a PATH)
     $logfile = `ipp_filename.pl --filerule LOG.IMFILE --camera $CAMERA --class_id $CLASS_ID --basename $outroot`
     if ("$logfile" == "") 
-      sprintf logfile "%s.%s.log" $outroot $CLASS_ID
+      echo "WARNING: logfile not defined in detrend.stack.pro:141"
+      break
     end
 
     stdout $logfile
     stderr $logfile
-    exec mkdir -p $outpath
 
-    # save the pageName for future reference below
-    options $pageName
-
-    $run = detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA
-    if ("$WORKDIR" != "NULL")
-      $run = $run --workdir $WORKDIR
-    end
+    $run = detrend_stack.pl --det_id $DET_ID --iteration $ITERATION --class_id $CLASS_ID --det_type $DET_TYPE --camera $CAMERA --outroot $outroot
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
     end
     add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
 
     # create the command line
Index: /branches/eam_branch_20080121/ippTasks/notes.txt
===================================================================
--- /branches/eam_branch_20080121/ippTasks/notes.txt	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/notes.txt	(revision 16176)
@@ -1,4 +1,45 @@
 
-2008.01.18
+  proposal to clean scripts/tasks up somewhat wrt names:
+
+  * scripts do NOT use workdir to change the workdir in the db
+  * thus, what is supplied is actually the outputRoot
+  * require the output root for the scripts
+  * have the calling tasks construct the outputRoot
+  ** replace -workdir with -outroot 
+
+  some filename rules :
+
+  * the db entry WORKDIR is the most abstract version:
+    path://GPC-@HOST@/20080130
+    file://data/@HOST@.0/gpc1/20080130
+    neb:///@HOST@/gpc1/20080130 
+    neb://gpc1/20080130 
+    XXX have nebulous distinguish between neb:///host/path and
+    neb://path?
+
+  * the db WORKDIR entry is carried from step to step unless
+    over-ridden with a -queue command
+
+  * psLib-based binaries (ppImage, etc) may be passed URIs, but not
+    files with the @HOST@ abstraction
+
+  * IPP perl scripts may be passed URIs, but not files with the @HOST@
+    abstraction
+
+  * nebulous : convert neb:///@HOST@/path/name
+
+  *** examples:
+
+  * this tells ppImage to use the ipp004 version for both input and output:
+  ppImage -file neb:///ipp004-v0/gpc1/20080130/o4414g0001o/o4414g0001o.XY01.fits neb:///ipp004-v0/gpc1/20080130/o4414g0001o/o4414g0001o.XY01
+  
+  * we already know the hostname at this point; include it in the call
+  chip_imfile.pl --uri neb:///ipp004-v0/gpc1/20080130/o4414g0001o/o4414g0001o.XY01.fits --workdir neb:///ipp004-v0/gpc1/20080130/
+
+
+
+
+
+2008.01.21
 
   I'm working on the summit.copy.pro interaction with nebulous (and
@@ -25,16 +66,24 @@
     host.  
 
+  * specific output filenames
+
+    In both ippTasks and ippScripts, there are references to files
+    which must correctly located on the host.
+
+  * workdir choice of output directory.   
+
+    the 
+
   * dsget output target:
 
     dsget is called by pantasks in the task 'dsget'.  currently, dsget
     accepts a --filename argument which specifies the output filename
-    to use.  we have to tell t
+    to use.  in the nebulous context, this is of the form
+    neb://top/next/stuff, without any host-specific information.  To
+    target the file instance to a specific host, we pass dsget the
+    --volume (name) argument.  The volumes refer to the specific
+    devices (potentially more than one per host), and the names can
+    then be chosen to include the host.  
   
-
-  * choice of output directory.   
-
-    the 
-
-
 2007.10.11
 
Index: /branches/eam_branch_20080121/ippTasks/pantasks.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/pantasks.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/pantasks.pro	(revision 16176)
@@ -342,28 +342,55 @@
 
 macro set.workdir.by.camera
+  if ($0 != 6)
+    echo "USAGE: set.workdir.by.camera (camera) (class_id) (template) (default) (varname)"
+    echo " uses global variable NEBULOUS to determine if nebulous is active"
+    break
+  end
+
+  local host default template camera classID varname
+  $camera = $1
+  $classID = $2
+  $template = $3
+  $default = $4
+  $varname = $5
+
+  # missing camera and/or chiphosts table results in host = NULL
+  book getword chiphosts $camera $classID -var host
+
+  if ("$host" == "NULL")
+    strsub $template @HOST@ $default -var $$varname
+  else
+    strsub $template @HOST@ $host -var $$varname
+  end
+end
+
+macro set.volume.by.camera
   if ($0 != 3)
-    echo "USAGE: set.workdir.by.camera (camera) (class_id)"
-    break
-  end
+    echo "USAGE: set.volume.by.camera (camera) (class_id) (template) (default) (varname)"
+    echo " uses global variable NEBULOUS to determine if nebulous is active"
+    break
+  end
+
+  local host default template camera classID varname
+  $camera = $1
+  $classID = $2
+  $template = $3
+  $default = $4
+  $varname = $5
 
   # missing camera and/or chiphosts table results in host = NULL
-  book getword chiphosts $1 $2 -var $host
-
-  if ($NEBULOUS)
-    if ("$host" == "NULL")
-      $workdir = $workdir_default
-      $volume  = "NULL"
-      return
-    end
-    strsub $workdir_template @HOST@ $host -var workdir
-    strsub $volume_template @HOST@ $host -var volume
-    return
-  end
-
-  if ("$host" == "NULL")
-    $workdir = $workdir_default
-    return
-  end
-  strsub $workdir_template @HOST@ $host -var workdir
+  book getword chiphosts $camera $classID -var host
+
+  if (not($NEBULOUS))
+    $$varname = "NULL"
+    return
+  end
+
+  if ("$host" == "NULL") 
+    $$varname = $default
+    return
+  end
+
+  strsub $template @HOST@ $host -var $$varname
 end
 
Index: /branches/eam_branch_20080121/ippTasks/summit.copy.pro
===================================================================
--- /branches/eam_branch_20080121/ippTasks/summit.copy.pro	(revision 16175)
+++ /branches/eam_branch_20080121/ippTasks/summit.copy.pro	(revision 16176)
@@ -19,10 +19,10 @@
 # XXX not sure how to handle the .N value if we need to use more than one
 if ($NEBULOUS)
- $workdir_default  = neb://
- $workdir_template = neb://
- $volume_default  = ipp004-v0
- $volume_template = @HOST@-v0
+ $default_host     = ipp004
+ $workdir_template = neb:///@HOST@-v0
+ $default_volume   = ipp004-v0
+ $volume_template  = 
 else
- $workdir_default  = /data/ipp004.0/
+ $default_host     = ipp004
  $workdir_template = /data/@HOST@.0/
 end
@@ -278,4 +278,7 @@
         book getword pzPendingImfile $pageName camera -var $CAMERA
 
+        set.host.by.camera $CAMERA $CLASS_ID
+        host        anyhost
+
         # 2007-08-30T05:09:59Z
         substr $DATEOBS 0 4 YEAR
@@ -284,21 +287,22 @@
 
         # we need to set the workdir based on 1) nebulous or not? 2) chip/host relationship
-        # this function uses workdir_template, workdir_default, volume_template, volume_default,
+        # this function uses workdir_template, default_host, volume_template, volume_default,
         # it sets workdir and volume
-       	set.workdir.by.camera $CAMERA $CLASS_ID
+       	set.workdir.by.camera $CAMERA $CLASS_ID $workdir_template $default_host workdir_base
+       	set.volume.by.camera $CAMERA $CLASS_ID $volume_template $default_volume volume
 
         # figure out filename
-	# XXXX this filename needs to use nebulous names
-        $FILENAME = $workdir/$CAMERA/$YEAR/$MONTH/$DAY/$EXP_NAME/$EXP_NAME.$CLASS_ID.fits
-        $FILEROOT = $workdir_template/$CAMERA/$YEAR/$MONTH/$DAY
+	# XXX may need to use sprintf here
+        $FILENAME = $workdir_base/$CAMERA/$YEAR$MONTH$DAY/$EXP_NAME/$EXP_NAME.$CLASS_ID.fits
+        $workdir = $workdir_template/$CAMERA/$YEAR$MONTH$DAY
+	# workdir examples:
+	# file://data/@HOST@.0/gpc1/20080130
+	# neb://gpc1/20080130 (need to supply volname?, or are we re-defining this each time?)
 
         book setword pzPendingImfile $pageName filename $FILENAME
-
-        set.host.by.camera $CAMERA $CLASS_ID
-        host        anyhost
 
         # store the pageName with this job
         options $pageName
-        options $FILEROOT
+        options $workdir
 
         $run = dsget --uri $URI --filename $FILENAME --bytes $BYTES 
@@ -330,6 +334,10 @@
         # these are functions of (at least) EXP_TYPE and SURVEY_ID, both of which should come from the data store
 
+	# we saved the workdir so we can pass it to pztool
+	$workdir = $options:1
+
 	# update the database with the success
-        $run = pztool -copydone -exp_name $EXP_NAME -inst $CAMERA -telescope $TELESCOPE -class $CLASS -class_id $CLASS_ID -uri $FILENAME -workdir $options:1
+	# for the moment, let's not propagate these
+        $run = pztool -copydone -exp_name $EXP_NAME -inst $CAMERA -telescope $TELESCOPE -class $CLASS -class_id $CLASS_ID -uri $FILENAME -workdir $workdir -end_stage reg
 	# tess_id, dvodb, workdir, end_stage
 
