Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 17671)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 17803)
@@ -32,5 +32,5 @@
     'outroot=s'         => \$outroot, # Output root name
     'verbose'           => \$verbose,   # Print to stdout
-    'no-update'         => \$no_update,	# Don't update the database?
+    'no-update'         => \$no_update, # Don't update the database?
     'no-op'             => \$no_op, # Don't do any operations?
     'save-temps'        => \$save_temps, # Save temporary files?
@@ -41,9 +41,9 @@
     -msg => "Required options: --stack_id --outroot",
     -exitval => 3,
-	  ) unless defined $stack_id
+          ) unless defined $stack_id
     and defined $outroot;
 
-my $STATS = 
-   [   
+my $STATS =
+   [
        #          PPSTATS KEYWORD         STATISTIC          STACKTOOL FLAG
        { name => "ROBUST_MEDIAN",   type => "mean", flag => "-bg",          dtype => "float" },
@@ -58,11 +58,11 @@
 my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
 my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
-if ($missing_tools) { 
+if ($missing_tools) {
     warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR); 
+    exit($PS_EXIT_CONFIG_ERROR);
 }
 
 # Get list of components for stacking
-my $mdcParser = PS::IPP::Metadata::Config->new;	# Parser for metadata config files
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 my $files;
 {
@@ -70,14 +70,14 @@
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform stacktool -inputskyfile: $error_code", $stack_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform stacktool -inputskyfile: $error_code", $stack_id, $error_code);
     }
 
     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
-    $files = parse_md_list($metadata) or 
-	&my_die("Unable to parse metadata list", $stack_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
+    $files = parse_md_list($metadata) or
+        &my_die("Unable to parse metadata list", $stack_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -86,26 +86,26 @@
 
 # Parse the list of input files to get the tesselation, skycell identifiers and camera
-my $skycell_id;			# Skycell identifier
-my $tess_id;			# Tesselation identifier
-my $camera;			# Camera
+my $skycell_id;                 # Skycell identifier
+my $tess_id;                    # Tesselation identifier
+my $camera;                     # Camera
 foreach my $file (@$files) {
     # skip warps which are speicified as 'ignored'
     if ($file->{ignored}) { next; }
     if (defined $tess_id) {
-	&my_die("Tesselation identifiers don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless
-	    $file->{tess_id} eq $tess_id;
+        &my_die("Tesselation identifiers don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless
+            $file->{tess_id} eq $tess_id;
     } else {
-	$tess_id = $file->{tess_id};
+        $tess_id = $file->{tess_id};
     }
     if (defined $skycell_id) {
-	&my_die("Skycell identifiers don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless
-	    $file->{skycell_id} eq $skycell_id;
+        &my_die("Skycell identifiers don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless
+            $file->{skycell_id} eq $skycell_id;
     } else {
-	$skycell_id = $file->{skycell_id};
+        $skycell_id = $file->{skycell_id};
     }
     if (defined $camera) {
-	&my_die("Cameras don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
+        &my_die("Cameras don't match", $stack_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
     } else {
-	$camera = $file->{camera};
+        $camera = $file->{camera};
     }
 }
@@ -116,7 +116,7 @@
 # Generate MDC file with the inputs
 my ($listFile, $listName) = tempfile( "$tess_id.$skycell_id.stk$stack_id.list.XXXX",
-				      UNLINK => !$save_temps );
+                                      UNLINK => !$save_temps );
 my $num = 0;
-my $inputSources;		# Sources to use as stamps
+my $inputSources;               # Sources to use as stamps
 foreach my $file (@$files) {
     if ($file->{ignored}) { next; }
@@ -125,5 +125,5 @@
     $num++;
 
-    my $image = $file->{uri};	# Image name
+    my $image = $file->{uri};   # Image name
     my $mask = $ipprc->filename( "PSWARP.OUTPUT.MASK", $file->{path_base} ); # Mask name
     my $weight = $ipprc->filename( "PSWARP.OUTPUT.WEIGHT", $file->{path_base} ); # Weight name
@@ -134,8 +134,8 @@
     &my_die("Weight $weight does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $weight );
     &my_die("PSF $psf does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $psf );
-   
+
     print $listFile "\tIMAGE\tSTR\t" . $image . "\n";
-    print $listFile "\tMASK\tSTR\t" . $mask . "\n"; 
-    print $listFile "\tWEIGHT\tSTR\t" . $weight . "\n"; 
+    print $listFile "\tMASK\tSTR\t" . $mask . "\n";
+    print $listFile "\tWEIGHT\tSTR\t" . $weight . "\n";
     print $listFile "\tPSF\tSTR\t" . $psf . "\n";
 
@@ -147,8 +147,8 @@
     # XXX details about supplying sources, etc, need to be specified in the libraries
     unless (defined $inputSources) {
-	$inputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $file->{path_base});
-	&my_die("Source file $inputSources does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $inputSources );
-    }
-	
+        $inputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $file->{path_base});
+        &my_die("Source file $inputSources does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists( $inputSources );
+    }
+
 }
 
@@ -175,8 +175,8 @@
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppStack: $error_code", $stack_id, $error_code);
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppStack: $error_code", $stack_id, $error_code);
     }
     &my_die("Couldn't find expected output file: $outputName", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
@@ -189,10 +189,10 @@
 
     # Get the statistics on the stacked image
-    my $statsFile;		# File handle
+    my $statsFile;              # File handle
     open $statsFile, $ipprc->file_resolve($outputStats) or &my_die("Can't open statistics file $outputStats: $!", $stack_id, $PS_EXIT_SYS_ERROR);
     my @contents = <$statsFile>; # Contents of file
     close $statsFile;
     my $metadata = $mdcParser->parse(join "", @contents) or
-	&my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
     $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $stack_id, $PS_EXIT_PROG_ERROR);
 }
@@ -202,28 +202,29 @@
     # Add the stack result
     {
-	my $command = "$stacktool -addsumskyfile -stack_id $stack_id -uri $outputName -path_base $outroot";
-	$command .= $stats->cmdflags();
-	$command .= " -dbname $dbname" if defined $dbname;
-	
-	my ( $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);
-	    &my_die("Unable to perform stacktool -addsumskyfile: $error_code", $stack_id, $error_code);
-	}
+        my $command = "$stacktool -addsumskyfile -stack_id $stack_id -uri $outputName -path_base $outroot";
+        $command .= $stats->cmdflags();
+        $command .= " -hostname $host" if defined $host;
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $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);
+            &my_die("Unable to perform stacktool -addsumskyfile: $error_code", $stack_id, $error_code);
+        }
     }
 
     # Register the run as completed
     {
-	my $command = "$stacktool -updaterun -stack_id $stack_id -state stop"; # Command to run stacktool
-	$command .= " -dbname $dbname" if defined $dbname;
-
-	my ( $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 stacktool -updaterun: $error_code\n");
-	    exit($error_code);
-	}
+        my $command = "$stacktool -updaterun -stack_id $stack_id -state stop"; # Command to run stacktool
+        $command .= " -dbname $dbname" if defined $dbname;
+
+        my ( $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 stacktool -updaterun: $error_code\n");
+            exit($error_code);
+        }
     }
 }
@@ -232,12 +233,13 @@
 sub my_die
 {
-    my $msg = shift;		# Warning message on die
-    my $stack_id = shift;	# Stack identifier
-    my $exit_code = shift;	# Exit code to add
+    my $msg = shift;            # Warning message on die
+    my $stack_id = shift;       # Stack identifier
+    my $exit_code = shift;      # Exit code to add
 
     warn($msg);
     if (defined $stack_id and not $no_update) {
-	my $command = "$stacktool -addsumskyfile -stack_id $stack_id -code $exit_code";
-	$command .= " -dbname $dbname" if defined $dbname;
+        my $command = "$stacktool -addsumskyfile -stack_id $stack_id -code $exit_code";
+        $command .= " -hostname $host" if defined $host;
+        $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
     }
