Index: trunk/ippScripts/scripts/sc_prepare_camera.pl
===================================================================
--- trunk/ippScripts/scripts/sc_prepare_camera.pl	(revision 37942)
+++ trunk/ippScripts/scripts/sc_prepare_camera.pl	(revision 38000)
@@ -14,4 +14,5 @@
 use Data::Dumper;
 use File::Basename;
+use File::Temp qw( tempfile );
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
@@ -30,4 +31,5 @@
 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
 my $camtool    = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 
 if ($missing_tools) {
@@ -88,4 +90,5 @@
 my ($workdir,$exp_tag,$reduction);
 {
+###    $command    = "$camtool -processedexp -cam_id $cam_id "; ### THIS LINE ONLY TO TEST!  
     my $command = "$camtool -pendingexp -cam_id $cam_id ";
     $command   .= " -dbname $dbname " if defined($dbname);
@@ -142,4 +145,30 @@
     my $pre_cmd_cmfs = "ls -1 ${remote_chip_path}*.cmf > ${remote_outroot}.cmflist";
     my $pre_cmd_masks= "ls -1 ${remote_chip_path}*.mk.fits > ${remote_outroot}.masklist";
+
+    # Despite the previous comment, we do care about the output of pendingimfile, as that 
+    # contains information for the exposure.
+    my ($statFile, $statName) = tempfile( "/tmp/cm.$cam_id.stats.XXXX", UNLINK => 1 );
+    foreach my $line (@$stdout_buf) {
+        print $statFile $line;
+    }
+    close $statFile;
+    
+    # parse the stats in the metadata file
+    $command = "$ppStatsFromMetadata $statName - CAMERA_EXP_IMFILE";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        warn("Unable to perform ppStatsFromMetadata: $error_code\n");
+        exit($error_code);
+    }
+
+    my $results = '';
+    foreach my $line (@$stdout_buf) {
+        $results .= " $line";
+    }
+    chomp($results);
+
+
 
     my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
@@ -163,4 +192,5 @@
     $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;
     $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
+    $camtool_post_cmd  .=  " $results "; # Add exposure information
     my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo ";
     my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - CAMERA_EXP_FPA >> ${remote_outroot}.dbinfo ";
