Index: trunk/ippScripts/scripts/phase0imfile.pl
===================================================================
--- trunk/ippScripts/scripts/phase0imfile.pl	(revision 8240)
+++ trunk/ippScripts/scripts/phase0imfile.pl	(revision 8255)
@@ -10,6 +10,11 @@
 use constant RECIPE => "PPSTATS_PHASE0_IMFILE"; # Recipe to use for ppStats
 
-use constant IMFILE_BG => 'background';	# Key for the background out of p0search -pendingimfile
-use constant IMFILE_BGSD => 'background_stdev';	# Key for the background standard deviation
+# Switches for p0search
+use constant P0SEARCH_MODE => '-updateimfile'; # Mode for p0search
+use constant P0SEARCH_EXPID => '-exp_id'; # Switch to specify the exposure id
+use constant P0SEARCH_CLASSID => '-class_id'; # Switch to specify the class id
+use constant P0SEARCH_BG => '-bg'; # Switch to add the background
+use constant P0SEARCH_BGSD => '-background_stdev'; # Switch to add the bg stdev
+use constant P0SEARCH_EXPTIME => '-exp_time'; # Switch to add the exposure time
 
 if (scalar @ARGV == 0 || scalar @ARGV > 3) {
@@ -35,7 +40,7 @@
 my $parsed;			# Parsed metadata
 {
-    my $command = "$ppStats $file"; # Command to run ppStats
+    my $command = "$ppStats $file -recipe PPSTATS " . RECIPE; # Command to run ppStats
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => 0);
+	run(command => $command, verbose => 1);
     die "Unable to perform ppStats on exposure id $expid: $error_code\n" if not $success;
     $parsed = $mdcParser->parse(join "", @$stdout_buf);
@@ -44,6 +49,8 @@
 my $bg = 0;			# Mean background level
 my $sd = 0;			# Mean standard deviation
+my $expTime = 0;		# Mean exposure time
 my $bgNum = 0;			# Number of background entries
 my $sdNum = 0;			# Number of standard deviation entries
+my $expTimeNum = 0;		# Number of exposure time entries
 foreach my $fpaItem (@$parsed) {
     if ($fpaItem->{class} eq "metadata") {
@@ -64,4 +71,7 @@
 			    $bgNum++;
 			}
+		    } elsif ($cellItem->{name} =~ /CELL\.EXPOSURE/) {
+			$expTime += $cellItem->{value};
+			$expTimeNum++;
 		    }
 		}
@@ -70,14 +80,17 @@
     }
 }
+die "Unable to find statistics.\n" if ($bgNum == 0 or $sdNum == 0);
 $bg /= $bgNum;
 $sd /= $sdNum;
+die "Unable to find exposure times.\n" if ($expTimeNum == 0);
+$expTime /= $expTimeNum;
 
 # Push the results into the database
 {
-    my $command = "$p0search -updateimfile -exp_id $expid -class_id $classid -background $bg " .
-	"-background_stdev $sd"; # Command to run p0search
+    my $command = "$p0search " . P0SEARCH_MODE . " " . P0SEARCH_EXPID() . " $expid " .
+	P0SEARCH_CLASSID() . " $classid " . P0SEARACH_BG() ." $bg " . P0SEARCH_BGSD() ." $sd " .
+	P0SEARCH_EXPTIME() . " $expTime"; # Command to run p0search
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => 0);
+	run(command => $command, verbose => 1);
     die "Unable to perform p0search -updateimfile: $error_code\n" if not $success;
 }
-
