Index: trunk/ippScripts/scripts/detrend_apply_norm.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_apply_norm.pl	(revision 8487)
+++ trunk/ippScripts/scripts/detrend_apply_norm.pl	(revision 8487)
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+use IPC::Cmd qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use Data::Dumper;
+
+# Parse the command-line
+die "Apply the detrend normalisations.\n\n" .
+    "Usage: $0 DET_ID ITER CLASS_ID MULTIPLICATION_VALUE INPUT OUTPUT\n\n"
+    if scalar @ARGV != 6;
+my $detId = shift @ARGV;	# Detrend ID
+my $iter = shift @ARGV;		# Iteration
+my $classId = shift @ARGV;	# Class ID
+my $value = shift @ARGV;	# Value to multiply
+my $input = shift @ARGV;	# Input file
+my $output = shift @ARGV;	# Output file
+
+# Look for programs we need
+my $missing_tools;
+my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppArith = can_run('ppArith') or (warn "Can't find ppArith" and $missing_tools = 1);
+die "Can't find required tools.\n" if $missing_tools;
+
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+# Run ppArith
+my $norms;
+{
+    my $command = "$ppArith -file1 $input -op \"*\" -constant $value -out $output"; # Command to run
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => 1);
+    die "Unable to perform ppArith: $error_code\n"
+	if not $success;
+}
+
+# Update the database
+{
+    my $command = "$dettool -addnormalizedimfile -det_id $detId -iter $iter -class_id $classId ".
+	"-uri $output"; # Command to run
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => 1);
+    die "Unable to perform dettool -addnormalizedimfile: $error_code\n"
+	if not $success;
+}
