Index: trunk/ippScripts/scripts/detrend_process.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process.pl	(revision 8715)
+++ trunk/ippScripts/scripts/detrend_process.pl	(revision 8763)
@@ -4,9 +4,35 @@
 use strict;
 
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
 use IPC::Cmd qw( can_run run );
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::Stats;
-use Data::Dumper;
 
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+my ($det_id, $exp_id, $class, $class_id, $det_type, $input_uri, $output_uri);
+GetOptions(
+    'det_id|d=s'        => \$det_id,
+    'exp_id|e=s'        => \$exp_id,
+    'class=s'           => \$class,     # unused
+    'class_id|i=s'      => \$class_id,
+    'det_type|t=s'      => \$det_type,
+    'input_uri|u=s'     => \$input_uri,
+    'output_uri|o=s'    => \$output_uri,
+) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage(
+    -msg => "Required options: --det_id --exp_id --class_id --det_type --input_uri --output_uri",
+    -exitval => 3,
+) unless defined $det_id
+    and defined $exp_id
+    and defined $class_id
+    and defined $det_type
+    and defined $input_uri
+    and defined $output_uri;
 
 # Recipes to use, as a function of the detrend type
@@ -26,16 +52,4 @@
 use constant DELETE_STATS => 0;	# Delete the statistics file when done?
 
-# Parse the command-line arguments
-if (scalar @ARGV != 6) {
-    die "Perform detrend processing at the imfile level.\n\n" .
-	"Usage: $0 DET_ID EXP_ID CLASS_ID DETREND_TYPE INPUT.fits OUTPUT_ROOT\n\n";
-}
-my $detId = shift @ARGV;	# Detrend ID
-my $expId = shift @ARGV;	# Exposure ID
-my $classId = shift @ARGV;	# Class ID
-my $detType = shift @ARGV;	# Detrend type
-my $input = shift @ARGV;	# Input FITS file
-my $output = shift @ARGV;	# Output root name
-
 # Look for programs we need
 my $missing_tools;
@@ -45,11 +59,11 @@
 
 # Recipe to use in processing
-my $recipe = RECIPES->{$detType};
-die "Unrecognised detrend type: $detType\n" if not defined $recipe;
-die "Unrecognised detrend type: $detType\n" if not defined PREFIX->{$detType};
+my $recipe = RECIPES->{$det_type};
+die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
+die "Unrecognised detrend type: $det_type\n" if not defined PREFIX->{$det_type};
 
 ### Output file name --- must match camera configuration!
-my $outputRoot =  PREFIX->{$detType} . '_' . $output;
-my $outputName = $outputRoot . '.' . $classId ;
+my $outputRoot =  PREFIX->{$det_type} . '_' . $output_uri;
+my $outputName = $outputRoot . '.' . $class_id ;
 my $outputImage = $outputName . '.fit';
 my $outputStats = $outputName . '.stats';
@@ -57,9 +71,9 @@
 # Run ppImage
 {
-    my $command = "$ppImage -file $input $outputRoot -recipe PPIMAGE $recipe" .
+    my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
 	" -stat $outputStats"; # Command to run ppImage
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
-    die "Unable to perform ppImage on $input: $error_code\n" if not $success;
+    die "Unable to perform ppImage on $input_uri: $error_code\n" if not $success;
     die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
 }
@@ -81,6 +95,6 @@
 # Add the processed file to the database
 {
-    my $command = "$dettool -addprocessed -det_id $detId -exp_id $expId " .
-	"-class_id $classId -recip $recipe -uri $outputImage"; # Command to run dettool
+    my $command = "$dettool -addprocessed -det_id $det_id -exp_id $exp_id " .
+	"-class_id $class_id -recip $recipe -uri $outputImage"; # Command to run dettool
     $command .= " -bg " . $stats->bg_mean();
     $command .= " -bg_stdev " . $stats->bg_stdev();
@@ -89,5 +103,5 @@
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 	run(command => $command, verbose => 1);
-    die "Unable to perform dettool -addprocessed for $detId/$expId/$classId: $error_code\n"
+    die "Unable to perform dettool -addprocessed for $det_id/$exp_id/$class_id: $error_code\n"
 	if not $success;
 }
