Index: trunk/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 9135)
+++ trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 9140)
@@ -17,4 +17,5 @@
 my ($detId,			# Detrend id
     $iter,			# Iteration
+    $detType,			# Detrend type
     $no_update			# Don't update the database?
     );
@@ -22,15 +23,24 @@
 	'det_id|d=s'	=> \$detId,
 	'iteration|i=s'	=> \$iter,
+	'det_type|t=s'  => \$detType,
         'no-update'     => \$no_update
 	) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options --det_id --iteration --camera --det_type",
+pod2usage( -msg => "Required options --det_id --iteration --det_type --det_type",
 	   -exitval => 3,
 	   ) unless defined $detId
-    and defined $iter;
+    and defined $iter
+    and defined $detType;
 
 
 use constant STATISTIC => 'bg'; # Background statistic to use from the database
+# Define which detrend types we normalise
+use constant NORMALIZE => {
+    'bias' => 0,
+    'dark' => 0,
+    'flat' => 1
+    }; 
+
 
 # Look for programs we need
@@ -39,4 +49,7 @@
 my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
 die "Can't find required tools.\n" if $missing_tools;
+
+die "Unrecognised detrend type: $detType\n" unless exists NORMALIZE()->{lc($detType)};
+
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -59,39 +72,59 @@
 }
 
-my %matrix; # Matrix of statistics as a function of exposures and classes
-foreach my $file (@$files) {
-    my $expTag = $file->{'exp_tag'}; # Exposure ID
-    my $classId = $file->{'class_id'}; # Class ID
-    my $stat = $file->{STATISTIC()}; # Statistic of interest
 
-    # Create matrix elements
-    $matrix{$expTag} = {} if not defined $matrix{$expId};
-    $matrix{$expTag}->{$classId} = $stat;
+my $norms;			# MDC with normalisations
+if (NORMALIZE()->{lc($detType)}) {
+
+    my %matrix; # Matrix of statistics as a function of exposures and classes
+    foreach my $file (@$files) {
+	my $expTag = $file->{'exp_tag'}; # Exposure ID
+	my $classId = $file->{'class_id'}; # Class ID
+	my $stat = $file->{STATISTIC()}; # Statistic of interest
+	
+	# Create matrix elements
+	$matrix{$expTag} = {} if not defined $matrix{$expTag};
+	$matrix{$expTag}->{$classId} = $stat;
+    }
+    
+    # Generate the input for ppNormCalc
+    my $normData;			# Normalisation data
+    foreach my $expTag (keys %matrix) {
+	$normData .= "$expTag\tMETADATA\n";
+	foreach my $classId (keys %{$matrix{$expTag}}) {
+	    $normData .= "\t" . $classId . "\tF32\t" . $matrix{$expTag}->{$classId} . "\n";
+	}
+	$normData .= "END\n\n";
+    }
+
+    # Run ppNormCalc
+    {
+	my ( $stdout, $stderr ); # Buffers for running program
+	my @command = split /\s+/, $ppNormCalc;
+	print "Running [$ppNormCalc]...\n";
+	run \@command, \$normData, \$stdout, \$stderr or
+	    die "Unable to perform ppNormCalc: $?";
+	print $stdout . "\n";
+	
+	# Parse the output
+	$norms = $mdcParser->parse($stdout)
+	    or die "unable to parse metadata config doc";
+    }
+
+} else {
+    # It's something that doesn't need normalisation --- just push in a normalisation of 1
+    my %classes;		# List of unique classes
+    foreach my $file (@$files) {
+	my $classId = $file->{'class_id'}; # Class Id
+	$classes{$classId} = 1;
+    }
+    
+    foreach my $classId (keys %classes) {
+	my %mdValue;	# Metadata value for this class id
+	$mdValue{name} = $classId;
+	$mdValue{value} = 1.0;
+	push @$norms, \%mdValue;
+    }
 }
 
-# Generate the input for ppNormCalc
-my $normData;			# Normalisation data
-foreach my $expTag (keys %matrix) {
-    $normData .= "$expTag\tMETADATA\n";
-    foreach my $classId (keys %{$matrix{$expTag}}) {
-	$normData .= "\t" . $classId . "\tF32\t" . $matrix{$expTag}->{$classId} . "\n";
-    }
-    $normData .= "END\n\n";
-}
-
-# Run ppNormCalc
-my $norms;
-{
-    my ( $stdout, $stderr ); # Buffers for running program
-    my @command = split /\s+/, $ppNormCalc;
-    print "Running [$ppNormCalc]...\n";
-    run \@command, \$normData, \$stdout, \$stderr or
-	die "Unable to perform ppNormCalc: $?";
-    print $stdout . "\n";
-
-    # Parse the output
-    $norms = $mdcParser->parse($stdout)
-        or die "unable to parse metadata config doc";
-}
 
 # Process output normalisations
