Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 17971)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 18009)
@@ -91,10 +91,19 @@
         { name => "n_extended",     type => "sum",   flag => "-n_extended",     dtype => "int"   },
         { name => "n_cr",           type => "sum",   flag => "-n_cr",           dtype => "int"   },
-        { name => "n_astrom",       type => "sum",   flag => "-n_astrom",       dtype => "int"   },
-
-
-# these are not defined for the database table camProcessedExp
         ];
 my $chipStats = PS::IPP::Metadata::Stats->new($CHIPSTATS); # Stats parser
+
+# values to extract from camera-level output metadata and the stats to calculate
+my $CAMSTATS =
+   [
+       #          PPSTATS KEYWORD         STATISTIC          CHIPTOOL FLAG
+      { name => "CERROR",         type => "rms",   flag => "-sigma_ra",       dtype => "float" },
+      { name => "CERROR",         type => "rms",   flag => "-sigma_dec",      dtype => "float" },
+      { name => "DT_ASTR",        type => "sum",   flag => "-dtime_astrom",   dtype => "float" },
+      { name => "NASTRO",         type => "sum",   flag => "-n_astrom",       dtype => "int"   },
+#     { name => "ZP??",           type => "mean",  flag => "-zp_mean",        dtype => "float" },
+#     { name => "ZP??",           type => "rms",   flag => "-zp_stdev",       dtype => "float" },
+   ];
+my $camStats = PS::IPP::Metadata::Stats->new($CAMSTATS); # Stats parser
 
 # Look for programs we need
@@ -174,4 +183,5 @@
 my $jpeg2      = $ipprc->filename("PPIMAGE.JPEG2",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",     $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
+my $fpaStats   = $ipprc->filename("PSASTRO.STATS",      $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
 my $logDest    = $ipprc->filename("LOG.EXP",            $outroot) or &my_die("Missing entry from camera config", $cam_id, $PS_EXIT_CONFIG_ERROR);
@@ -223,4 +233,5 @@
         $command  = "$psastro -list $list3Name $outroot";
         $command .= " -tracedest $traceDest -log $logDest";
+	$command .= " -stats $fpaStats";
         $command .= " -dbname $dbname" if defined $dbname;
 
@@ -233,4 +244,23 @@
         # XXX do we want to give an error if astrometry fails here?
         &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
+        &my_die("Unable to find expected output file: $fpaStats",   $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
+
+	# Get the statistics on the processed image
+	my $statsFile;              # File handle
+	open $statsFile, $ipprc->file_resolve($fpaStats) or &my_die("Can't open statistics file $outputStats: $!", $cam_id, $PS_EXIT_SYS_ERROR);
+	my @contents = <$statsFile>; # Contents of file
+	close $statsFile;
+
+	# parse the statistics MDC file
+	my $mdcParser = PS::IPP::Metadata::Config->new();   # Parser for metadata config files
+	my $metadata = $mdcParser->parse(join "", @contents);
+	unless ($metadata) {
+	    &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_PROG_ERROR);
+	}
+
+	# extract the stats from the metadata
+	unless ($stats->parse($metadata)) {
+	    &my_die("Failure extracting metadata from the statistics output file.\n", $exp_id, $chip_id, $class_id, $PS_EXIT_PROG_ERROR);
+	}
 
         # run addstar on the output fpaObjects (if a DVO database is defined)
@@ -266,4 +296,5 @@
 $fpaCommand .= " -dbname $dbname" if defined $dbname;
 $fpaCommand .= $chipStats->cmdflags();
+$fpaCommand .= $camStats->cmdflags();
 
 # Add the result into the database
