Index: trunk/ippScripts/scripts/detrend_resid_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid_exp.pl	(revision 23229)
+++ trunk/ippScripts/scripts/detrend_resid_exp.pl	(revision 23295)
@@ -107,5 +107,5 @@
     }
     if (@$stdout_buf == 0) {
-	&my_die("No normalizations were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
+        &my_die("No normalizations were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     }
 
@@ -126,9 +126,9 @@
     print "saving norms to $normsName\n";
     foreach my $norm (@$normsMD) {
-	my $class_id = $norm->{class_id};
-	my $normalization = $norm->{norm};
-
-	$norms{$class_id} = $normalization;
-        printf $normsFile "$class_id F32 $normalization\n", 
+        my $class_id = $norm->{class_id};
+        my $normalization = $norm->{norm};
+
+        $norms{$class_id} = $normalization;
+        printf $normsFile "$class_id F32 $normalization\n",
     }
     close $normsFile;
@@ -153,5 +153,5 @@
     }
     if (@$stdout_buf == 0) {
-	&my_die("No imfiles were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
+        &my_die("No imfiles were found", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     }
 
@@ -168,40 +168,40 @@
     # also, write out the modified metadata set
     foreach my $mdItem (@$metadata) {
-	if ($mdItem->{class} ne "metadata") {
-	    carp "MD element ", $mdItem->{name}, " isn't of type METADATA --- ignored.\n";
-	    next;
-	}
-	my %hash;		# Hash element
-	my $mdComponents = $mdItem->{value}; # Components of the metadata
-
-	# determine the class_id for this block:
-	my $class_id;
-	foreach my $data (@$mdComponents) {
-	    unless ($data->{name} eq "class_id") { next; }
-	    $class_id = $data->{value};
-	    last;
-	}
-
-	# a new metadata block
-	print $statFile "rawResidImfile  METADATA\n";
-
-	# modify and save the data in this block:
-	foreach my $data (@$mdComponents) {
-	    my $norm = $norms{$class_id};
-
-	    # fields to modify by the normalization:
-	    if ($data->{name} eq "bg")            { $data->{value} *= $norm; }
-	    if ($data->{name} eq "bg_stdev")      { $data->{value} *= $norm; }
-	    if ($data->{name} eq "bg_mean_stdev") { $data->{value} *= $norm; }
-	    if ($data->{name} eq "bg_skewness")   { $data->{value} *= $norm; }
-	    if ($data->{name} eq "bg_kurtosis")   { $data->{value} *= $norm; }
-	    if ($data->{name} eq "bin_stdev")     { $data->{value} *= $norm; }
-
-	    # write out the metadata, save on the array of hashes
-	    print $statFile "  $data->{name}  $data->{type}  $data->{value}\n";
-	    $hash{$data->{name}} = $data->{value};
-	}
-	print $statFile "END\n";
-	push @files, \%hash;
+        if ($mdItem->{class} ne "metadata") {
+            carp "MD element ", $mdItem->{name}, " isn't of type METADATA --- ignored.\n";
+            next;
+        }
+        my %hash;               # Hash element
+        my $mdComponents = $mdItem->{value}; # Components of the metadata
+
+        # determine the class_id for this block:
+        my $class_id;
+        foreach my $data (@$mdComponents) {
+            unless ($data->{name} eq "class_id") { next; }
+            $class_id = $data->{value};
+            last;
+        }
+
+        # a new metadata block
+        print $statFile "rawResidImfile  METADATA\n";
+
+        # modify and save the data in this block:
+        foreach my $data (@$mdComponents) {
+            my $norm = $norms{$class_id};
+
+            # fields to modify by the normalization:
+            if ($data->{name} eq "bg")            { $data->{value} *= $norm; }
+            if ($data->{name} eq "bg_stdev")      { $data->{value} *= $norm; }
+            if ($data->{name} eq "bg_mean_stdev") { $data->{value} *= $norm; }
+            if ($data->{name} eq "bg_skewness")   { $data->{value} *= $norm; }
+            if ($data->{name} eq "bg_kurtosis")   { $data->{value} *= $norm; }
+            if ($data->{name} eq "bin_stdev")     { $data->{value} *= $norm; }
+
+            # write out the metadata, save on the array of hashes
+            print $statFile "  $data->{name}  $data->{type}  $data->{value}\n";
+            $hash{$data->{name}} = $data->{value};
+        }
+        print $statFile "END\n";
+        push @files, \%hash;
     }
     close $statFile;
@@ -633,4 +633,6 @@
     my $exit_code = shift; # Exit code to add
 
+    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
+
     carp($msg);
     if (defined $det_id and defined $iter and defined $exp_id and not $no_update) {
