Index: trunk/ippScripts/scripts/register_exp.pl
===================================================================
--- trunk/ippScripts/scripts/register_exp.pl	(revision 12207)
+++ trunk/ippScripts/scripts/register_exp.pl	(revision 12209)
@@ -31,9 +31,9 @@
     );
 
-my ($cache, $exptag, $workdir, $dbname, $no_update);
+my ($cache, $exp_tag, $workdir, $dbname, $no_update);
 
 GetOptions(
     'caches'        => \$cache,
-    'exp_tag|e=s'   => \$exptag,
+    'exp_tag|e=s'   => \$exp_tag,
     'workdir|w=s'   => \$workdir, # Working directory for output files
     'dbname|d=s'    => \$dbname, # Database name    
@@ -45,5 +45,5 @@
     -msg => "Required options: --exp_tag",
     -exitval => 3,
-) unless defined $exptag;
+) unless defined $exp_tag;
 
 # Define setup
@@ -103,5 +103,5 @@
 my $imfiles;
 {
-    my $command = "$regtool -processedimfile -exp_tag $exptag";
+    my $command = "$regtool -processedimfile -exp_tag $exp_tag";
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -109,5 +109,5 @@
     unless ($success) {
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        warn ("Unable to perform regtool -processedimfile on exposure id $exptag: $error_code");
+        warn ("Unable to perform regtool -processedimfile on exposure id $exp_tag: $error_code");
         exit ($error_code);
     }
@@ -116,5 +116,5 @@
     unless ($metadata) {
         warn ("Unable to parse metadata config doc");
-        &my_die ($exptag, $PS_EXIT_PROG_ERROR);
+        &my_die ($exp_tag, $PS_EXIT_PROG_ERROR);
     }
     $imfiles = parse_md_list($metadata); # Data for imfiles
@@ -138,5 +138,5 @@
         if ($values{$constant} ne $value) {
             warn ("Value of $constant for $imfile->{REGISTER_CLASSID} doesn't match previous value");
-            &my_die ($exptag, $PS_EXIT_PROG_ERROR);
+            &my_die ($exp_tag, $PS_EXIT_PROG_ERROR);
         }
     }
@@ -160,5 +160,5 @@
 if ($rnd > 0.5) {
     warn ("random failure");
-    &my_die ($exptag, $PS_EXIT_DATA_ERROR);
+    &my_die ($exp_tag, $PS_EXIT_DATA_ERROR);
 }
 }
@@ -166,10 +166,14 @@
 # Output results to the database
 unless ($no_update) {
-    my @command;
-    push @command, $regtool, '-addprocessedexp', '-exp_tag', $exptag; # Command to execute to update exposure parameters
+    my $command = "$regtool -addprocessedexp -exp_tag $exp_tag"; # Command to execute
     
     # Add the values of interest
     foreach my $constant (@{CONSTANTS()}) {
-        push @command, ( '-' . $constant ), $values{$constant};
+	my $value = $values{$constant};
+	if ($value =~ /\s/) {
+	    # Quote spaces
+	    $value = "\'$value\'";
+	}
+	$command .= " -$constant $value";
     }
     foreach my $variable (@{VARIABLES()}) {
@@ -177,42 +181,33 @@
         my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
         $stats->add_data(@$array);
-        push @command, ( '-' . $variable ), $stats->mean();
+
+	$command .= " -$variable " . $stats->mean();
     }
 
     # Add the statistics
-    {
-        my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
-        $stats->add_data(@backgrounds);
-        push @command, ( '-' . REGISTER_BG() ), $stats->mean();
-        push @command, ( '-' . REGISTER_BG_MEAN_STDEV() ), ( $stats->standard_deviation() || 0 )
-    }
-    {
-        my $stats = Statistics::Descriptive::Sparse->new; # Statistics calculator
-        $stats->add_data(@variances);
-        push @command, ( '-' . REGISTER_BG_STDEV() ), sqrt( $stats->mean() );
-    }
+    my $meanStats = Statistics::Descriptive::Sparse->new; # Statistics calculator
+    $meanStats->add_data(@backgrounds);
+    my $stdevStats = Statistics::Descriptive::Sparse->new; # Statistics calculator
+    $stdevStats->add_data(@variances);
+    my $bg = ($meanStats->mean() or 'NAN');
+    my $bg_stdev = (sqrt($stdevStats->mean()) or 'NAN');
+    my $bg_mean_stdev = ($meanStats->standard_deviation() or 'NAN');
+    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
     
     # Add the detrend flag
     foreach my $detrendType (@{DETRENDS()}) {
         if (lc($values{TYPE()}) =~ /$detrendType/) {
-            push @command, DETREND_FLAG;
+	    $command .= ' ' . DETREND_FLAG;
             last;
         }
     }
- 
-    # Quote arguments with whitespace
-    for (my $i = 0; $i < scalar @command; $i++) {
-        if ($command[$i] =~ /\s/) {
-            $command[$i] = "\'$command[$i]\'";
-        }
-    }
-
-    push @command, "-dbname", $dbname if defined $dbname;
+
+    $command .= " -dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        cache_run(command => \@command, verbose => 1);
+        cache_run(command => $command, verbose => 1);
     unless ($success) {
 	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        warn ("Unable to run regtool -addprocessedexp for $exptag: $error_code");
+        warn ("Unable to run regtool -addprocessedexp for $exp_tag: $error_code");
         exit($error_code);
     }
@@ -230,5 +225,5 @@
     unless (defined $imfile->{$name}) {
         warn ("Couldn't find value of $name for class_id=$source");
-        &my_die ($exptag, $PS_EXIT_PROG_ERROR);
+        &my_die ($exp_tag, $PS_EXIT_PROG_ERROR);
     }
     return $imfile->{$name};
