Index: trunk/ippScripts/scripts/register_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/register_imfile.pl	(revision 12115)
+++ trunk/ippScripts/scripts/register_imfile.pl	(revision 12207)
@@ -88,12 +88,4 @@
 
 
-# Switches for regtool
-use constant REGTOOL_MODE => '-addprocessedimfile'; # Mode for regtool
-use constant REGTOOL_EXPTAG => '-exp_tag'; # Switch to specify the exposure id
-use constant REGTOOL_CLASSID => '-class_id'; # Switch to specify the class id
-use constant REGTOOL_BG_MEAN => '-bg'; # Switch to add the background
-use constant REGTOOL_BG_STDEV => '-bg_stdev'; # Switch to add the bg stdev
-use constant REGTOOL_BG_MEAN_STDEV => '-bg_mean_stdev'; # Switch to add the bg mean stdev
-
 # Look for programs we need
 my $missing_tools;
@@ -158,47 +150,29 @@
 # Push the results into the database
 unless ($no_update) {
-    my @command;
-    push @command, $regtool, REGTOOL_MODE(), REGTOOL_EXPTAG(), $exp_tag, REGTOOL_CLASSID(), $class_id; # Command to run regtool
+    my $command = "$regtool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id"; # Command to run regtool
 
     foreach my $constant (keys %{CONSTANTS()}) {
-        push @command, CONSTANTS->{$constant}, ($stats->data($constant))->{value};
-
-    }
+	my $value = ($stats->data($constant))->{value};
+	if ($value =~ /\s/) {
+	    # Quote arguments with whitespace
+            $value = "\'$value\'";
+        }
+        $command .=  ' ' . CONSTANTS->{$constant} . ' ' . $value;
+    }
+
     foreach my $variable (keys %{VARIABLES()}) {
         # Just use the mean value
-        push @command, VARIABLES->{$variable}, ($stats->data($variable))->{mean};
-    }
-    
-    push @command, REGTOOL_BG_MEAN();
-    if (defined $stats->bg_mean()) {
-        push @command, $stats->bg_mean();
-    } else {
-        push @command, "NAN";
-    }
-    push @command, REGTOOL_BG_STDEV();
-    if (defined($stats->bg_stdev())) {
-        push @command, $stats->bg_stdev();
-    } else {
-        # Will not be defined if there is only a single imfile
-        push @command, 0;
-    }
-    push @command,  REGTOOL_BG_MEAN_STDEV();
-    if (defined $stats->bg_mean_stdev()) {
-        push @command, $stats->bg_mean_stdev();
-    } else {
-        push @command, "0.0";
-    }
-
-    # 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 .= ' ' . VARIABLES->{$variable} . ' ' . ($stats->data($variable))->{mean};
+    }
+
+    my $bg = ($stats->bg_mean() or 'NAN');
+    my $bg_stdev = ($stats->bg_stdev() or 'NAN');
+    my $bg_mean_stdev = ($stats->bg_mean_stdev() or 'NAN');
+    $command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
+
+    $command .= "-dbname $dbname" if defined $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => \@command, verbose => 1);
+        run(command => $command, verbose => 1);
 
     unless ($success) {
