Index: trunk/ippScripts/scripts/ipp_serial_detrend.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_serial_detrend.pl	(revision 11414)
+++ trunk/ippScripts/scripts/ipp_serial_detrend.pl	(revision 11847)
@@ -8,4 +8,17 @@
 use PS::IPP::Metadata::List qw( parse_md_list );
 use Data::Dumper;
+
+my ($dbname,			# Database name to use
+    $workdir,			# Working directory
+    );
+GetOptions(
+	   'dbname|d=s'  => \$dbname,
+	   'workdir|w=s' => \$workdir,
+) or pod2usage( 2 );
+
+pod2usage(
+	  -msg => "Required options: --dbname",
+	  -exitval => 3,
+	  ) unless defined $dbname;
 
 my $mdcParser = PS::IPP::Metadata::Config->new;	# Metadata config parser
@@ -53,5 +66,6 @@
 		my $camera = $item->{camera};
 		
-		my $command = "$detrend_process_imfile --det_id $det_id --exp_tag $exp_tag --class $class --class_id $class_id --det_type $det_type --input_uri $uri --camera $camera";
+		my $command = "$detrend_process_imfile --det_id $det_id --exp_tag $exp_tag --class $class --class_id $class_id --det_type $det_type --input_uri $uri --camera $camera --dbname $dbname";
+		$command .= " --workdir $workdir" if defined $workdir;
 		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 		    run( command => $command, verbose => 1 );
@@ -79,5 +93,6 @@
 	my $det_id = $item->{det_id};
 
-	my $command = "$detrend_process_exp --det_id $det_id --exp_tag $exp_tag --camera $camera";
+	my $command = "$detrend_process_exp --det_id $det_id --exp_tag $exp_tag --camera $camera --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -102,5 +117,6 @@
 	my $camera = $item->{camera};
 
-	my $command = "$detrend_stack --det_id $det_id --iteration $iteration --class_id $class_id --det_type $det_type --camera $camera";
+	my $command = "$detrend_stack --det_id $det_id --iteration $iteration --class_id $class_id --det_type $det_type --camera $camera --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -123,5 +139,6 @@
 	my $det_type = $item->{det_type};
 
-	my $command = "$detrend_norm_calc --det_id $det_id --iteration $iteration --det_type $det_type";
+	my $command = "$detrend_norm_calc --det_id $det_id --iteration $iteration --det_type $det_type --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -148,5 +165,6 @@
 	my $camera = $item->{camera};
 
-	my $command = "$detrend_norm_apply --det_id $det_id --iteration $iteration --class_id $class_id --value $value --input_uri $uri --camera $camera --det_type $det_type";
+	my $command = "$detrend_norm_apply --det_id $det_id --iteration $iteration --class_id $class_id --value $value --input_uri $uri --camera $camera --det_type $det_type --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -173,5 +191,6 @@
 	my $camera = $item->{camera};
 
-	my $command = "$detrend_norm_exp --det_id $det_id --iteration $iteration --camera $camera --det_type $det_type";
+	my $command = "$detrend_norm_exp --det_id $det_id --iteration $iteration --camera $camera --det_type $det_type --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -210,6 +229,7 @@
 		my $mode = $item->{mode};
 
-		my $command = "$detrend_resid --det_id $det_id --iteration $iteration --exp_tag $exp_tag --class_id $class_id --det_type $det_type --camera $camera --input_uri $uri --mode $mode";
+		my $command = "$detrend_resid --det_id $det_id --iteration $iteration --exp_tag $exp_tag --class_id $class_id --det_type $det_type --camera $camera --input_uri $uri --mode $mode --dbname $dbname";
 		$command .= " --detrend $detrend" if defined $detrend;
+		$command .= " --workdir $workdir" if defined $workdir;
 
 		my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -240,5 +260,6 @@
 	my $det_type = $item->{det_type};
 
-	my $command = "$detrend_reject_imfile --det_id $det_id --iteration $iteration --exp_tag $exp_tag --det_type $det_type --camera $camera";
+	my $command = "$detrend_reject_imfile --det_id $det_id --iteration $iteration --exp_tag $exp_tag --det_type $det_type --camera $camera --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
@@ -262,5 +283,6 @@
 	my $det_type = $item->{det_type};
 
-	my $command = "$detrend_reject_exp --det_id $det_id --iteration $iteration --det_type $det_type --camera $camera";
+	my $command = "$detrend_reject_exp --det_id $det_id --iteration $iteration --det_type $det_type --camera $camera --dbname $dbname";
+	$command .= " --workdir $workdir" if defined $workdir;
     	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	    run( command => $command, verbose => 1 );
