Index: /trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 11297)
@@ -23,4 +23,5 @@
     $camera,			# Camera
     $detType,			# Detrend type
+    $dbname,			# Database name
     $no_update			# Don't update the database
     );
@@ -33,4 +34,5 @@
     'camera|c=s'        => \$camera,
     'det_type|t=s'      => \$detType,
+    'dbname|d=s'        => \$dbname,
     'no-update'         => \$no_update
     ) or pod2usage( 2 );
@@ -115,4 +117,7 @@
     }
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
+
+    $command .= " -dbname $dbname" if defined $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
Index: /trunk/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 11297)
@@ -18,4 +18,5 @@
     $iter,			# Iteration
     $detType,			# Detrend type
+    $dbname,			# Database name
     $no_update			# Don't update the database?
     );
@@ -24,4 +25,5 @@
 	'iteration|i=s'	=> \$iter,
 	'det_type|t=s'  => \$detType,
+	'dbname|d=s'    => \$dbname,# Database name
         'no-update'     => \$no_update
 	) or pod2usage( 2 );
@@ -63,4 +65,5 @@
 {
     my $command = "$dettool -processedimfile -det_id $detId"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my @command = split /\s+/, $command;
     my ( $stdin, $stdout, $stderr ); # Buffers for running program
@@ -150,4 +153,5 @@
 	my $command = "$dettool -addnormalizedstat -det_id $detId -iteration $iter -class_id $className ".
 	    "-norm $normalisation"; # Command to run
+	$command .= " -dbname $dbname" if defined $dbname;
 	my @command = split /\s+/, $command;
 
Index: /trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 11297)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $no_update);
+my ($det_id, $iter, $det_type, $camera, $dbname, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -25,4 +25,5 @@
     'camera|c=s'        => \$camera,
     'det_type|t=s'      => \$det_type,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -55,4 +56,5 @@
 {
     my $command = "$dettool -normalizedimfile -det_id $det_id -iteration $iter"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -139,4 +141,5 @@
 	"-recip " . RECIPE1() . "," . RECIPE2() . " -b1_uri $jpeg1Name -b2_uri $jpeg2Name " .
 	"-bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
Index: /trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 11297)
@@ -19,9 +19,10 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_tag, $camera, $no_update);
+my ($det_id, $exp_tag, $camera, $dbname, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
     'exp_tag|e=s'       => \$exp_tag,
     'camera|c=s'        => \$camera,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -53,4 +54,5 @@
 {
     my $command = "$dettool -processedimfile -det_id $det_id -exp_tag $exp_tag"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -139,4 +141,5 @@
 	"-recip " . RECIPE1() . "," . RECIPE2() . " -b1_uri $jpeg1 -b2_uri $jpeg2 " .
 	"-bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
Index: /trunk/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 11297)
@@ -18,5 +18,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $exp_tag, $class_id, $det_type, $input_uri, $camera, $no_update);
+my ($det_id, $exp_tag, $class_id, $det_type, $input_uri, $camera, $bdname, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -26,4 +26,5 @@
     'input_uri|u=s'     => \$input_uri,
     'camera|c=s'        => \$camera,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -122,4 +123,5 @@
     }
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: /trunk/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 11297)
@@ -18,5 +18,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $filter, $no_update);
+my ($det_id, $iter, $det_type, $camera, $filter, $dbname, $no_update);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -25,4 +25,5 @@
 	   'camera=s'          => \$camera,
 	   'filter=s'          => \$filter,
+	   'dbname|d=s'        => \$dbname, # Database name
 	   'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -48,4 +49,5 @@
 {
     my $command = "$dettool -residexp -det_id $det_id -iteration $iter"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -105,4 +107,6 @@
     $expTag = $expTags[$i];	# Exposure ID
     $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_tag $expTag"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
+
     $reject = 0;		# Reject this exposure?
 
@@ -197,5 +201,6 @@
 	" -bg_mean_stdev " . $meanStats->standard_deviation();
     $command .= " -accept" if $master;
-    
+    $command .= " -dbname $dbname" if defined $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -211,4 +216,6 @@
 	$command .= ' -again';
     }
+    
+    $command .= " -dbname $dbname" if defined $dbname;
     
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: /trunk/ippScripts/scripts/detrend_reject_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_reject_imfile.pl	(revision 11297)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $no_update, $reject);
+my ($det_id, $iter, $exp_tag, $det_type, $camera, $filter, $reject, $dbname, $no_update);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -25,8 +25,9 @@
 	   'exp_tag|e=s'       => \$exp_tag,
 	   'det_type|t=s'      => \$det_type,
-	   'no-update'         => \$no_update,
 	   'camera=s'          => \$camera,
 	   'filter=s'          => \$filter,
 	   'reject'            => \$reject
+	   'dbname|d=s'        => \$dbname, # Database name
+	   'no-update'         => \$no_update,
 	   ) or pod2usage( 2 );
 
@@ -58,4 +59,5 @@
 {
     my $command = "$dettool -residimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -239,4 +241,5 @@
 	"-bg $mean -bg_stdev $stdev -bg_mean_stdev $meanStdev";	# Command to run
     $command .= ' -reject' if $reject;
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
Index: /trunk/ippScripts/scripts/detrend_resid.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_resid.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_resid.pl	(revision 11297)
@@ -20,5 +20,5 @@
 
 my ($det_id, $iter, $exp_tag, $class_id, $det_type, $detrend,
-        $input_uri, $camera, $mode, $no_update);
+        $input_uri, $camera, $mode, $dbname, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -31,4 +31,5 @@
     'camera|c=s'        => \$camera,
     'mode|m=s'          => \$mode,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update,
 ) or pod2usage( 2 );
@@ -155,4 +156,5 @@
 	"-b2_uri $bin2Name"; # Command to run dettool
     $command .= " -bg " . $stats->bg_mean();
+    $command .= " -dbname $dbname" if defined $dbname;
 
     if (defined($stats->bg_mean_stdev())) {
Index: /trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- /trunk/ippScripts/scripts/detrend_stack.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/detrend_stack.pl	(revision 11297)
@@ -19,5 +19,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $class_id, $det_type, $camera, $no_update);
+my ($det_id, $iter, $class_id, $det_type, $camera, $dbname, $no_update);
 GetOptions(
     'det_id|d=s'        => \$det_id,
@@ -26,4 +26,5 @@
     'det_type|t=s'      => \$det_type,
     'camera|c=s'        => \$camera,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -65,4 +66,5 @@
 {
     my $command = "$dettool -processedimfile -det_id $det_id -class_id $class_id -included"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -128,4 +130,5 @@
     }
     $command .= ' -bg_mean_stdev ' . $stats->bg_mean_stdev();
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
Index: /trunk/ippScripts/scripts/phase0_exp.pl
===================================================================
--- /trunk/ippScripts/scripts/phase0_exp.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/phase0_exp.pl	(revision 11297)
@@ -30,4 +30,5 @@
     'caches'        => \$cache,
     'exp_tag|e=s'   => \$exptag,
+    'dbname|d=s'    => \$dbname,# Database name    
     'no-update'     => \$no_update
 ) or pod2usage( 2 );
@@ -96,4 +97,5 @@
 {
     my $command = "$p0tool -processedimfile -exp_tag $exptag";
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         cache_run(command => $command, verbose => 1);
@@ -199,4 +201,6 @@
     }
 
+    push @command, "-dbname", $dbname if defined $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         cache_run(command => \@command, verbose => 1);
@@ -243,5 +247,7 @@
     my $exit_code = $_[1];
     if ($exp_tag) {
-        system ("$p0tool -addprocessedexp -exp_tag $exp_tag -code $exit_code");
+	my $command = "$p0tool -addprocessedexp -exp_tag $exp_tag -code $exit_code";
+	$command .= " -dbname $dbname" if defined $dbname;
+        system($command);
     }
     exit $exit_code;
Index: /trunk/ippScripts/scripts/phase0_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/phase0_imfile.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/phase0_imfile.pl	(revision 11297)
@@ -31,5 +31,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($cache, $exp_tag, $class_id, $uri, $workdir, $no_update);
+my ($cache, $exp_tag, $class_id, $uri, $workdir, $dbname, $no_update);
 
 GetOptions(
@@ -38,5 +38,6 @@
     'class_id|i=s'  => \$class_id,
     'uri|u=s'       => \$uri,
-    'workdir|w=s'   => \$workdir,
+    'workdir|w=s'   => \$workdir, # Working directory for output files
+    'dbname|d=s'    => \$dbname,# Database name
     'no-update'     => \$no_update
 ) or pod2usage( 2 );
@@ -185,4 +186,6 @@
     }
 
+    push @command, "-dbname", $dbname if defined $dbname;
+
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => \@command, verbose => 1);
@@ -219,5 +222,7 @@
     my $exit_code = $_[2];
     if ($exp_tag && $class_id) {
-        system ("$p0tool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code");
+	my $command = "$p0tool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code";
+	$command .= " -dbname $dbname" if defined $dbname;
+        system ($command);
     }
     exit $exit_code;
Index: /trunk/ippScripts/scripts/phase2.pl
===================================================================
--- /trunk/ippScripts/scripts/phase2.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/phase2.pl	(revision 11297)
@@ -23,4 +23,5 @@
     $camera,			# Camera
     $outpath,			# Outpath
+    $dbname,			# Database name
     $no_update			# Don't update the database?
     );
@@ -31,4 +32,5 @@
     'camera|c=s'    => \$camera,
     'outpath|o=s'   => \$outpath,
+    'dbname|d=s'    => \$dbname, # Database name
     'no-update'     => \$no_update
 ) or pod2usage( 2 );
@@ -102,5 +104,5 @@
 $outputBin2  = $ipprc->convert_filename_relative( $outputBin2 );
 unless ($no_update) {
-    # Command to run dettool
+    # Command to run p2tool
     my $command = "$p2tool -addprocessedimfile";
     $command .= " -exp_tag $expTag";
@@ -113,4 +115,5 @@
     $command .= " -bg_stdev " . $stats->bg_stdev();
     $command .= " -bg_mean_stdev " . $stats->bg_mean_stdev();
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
Index: /trunk/ippScripts/scripts/phase3.pl
===================================================================
--- /trunk/ippScripts/scripts/phase3.pl	(revision 11296)
+++ /trunk/ippScripts/scripts/phase3.pl	(revision 11297)
@@ -19,9 +19,10 @@
 use Pod::Usage qw( pod2usage );
 
-my ($exp_tag, $camera, $outpath, $no_update);
+my ($exp_tag, $camera, $outpath, $dbname, $no_update);
 GetOptions(
     'exp_tag|e=s'       => \$exp_tag,
     'camera|c=s'        => \$camera,
-    'outpath|o=s'   => \$outpath,
+    'outpath|o=s'       => \$outpath,
+    'dbname|d=s'        => \$dbname, # Database name
     'no-update'         => \$no_update
 ) or pod2usage( 2 );
@@ -52,4 +53,5 @@
 {
     my $command = "$p3tool -pendingimfile -exp_tag $exp_tag"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
@@ -149,4 +151,5 @@
 	"-bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev " .
 	"-sigma_ra 0.0 -sigma_dec 0.0 -nastro 0 -zp_mean 0.0 -zp_stdev 0.0"; # Command to run
+    $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
