Index: trunk/ippScripts/scripts/skycell_jpeg.pl
===================================================================
--- trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 34800)
+++ trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 35853)
@@ -17,4 +17,5 @@
 my ($help,$masks);
 my ($tempFile,$tempName,$maskFile,$maskName);
+$verbose = 0;
 my $ppSkycell = can_run('ppSkycell') or (warn "Can't find ppSkycell" and $missing_tools = 1);
 my $warptool  = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
@@ -38,5 +39,5 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2) if @ARGV;
 pod2usage(
-    -msg => "Required options: --stage --stage_id --path_base\nHelpful options: --camera --dbname",
+    -msg => "Required options: --stage --stage_id --outroot\nHelpful options: --camera --dbname",
     -exitval => 3,
     ) unless
@@ -100,12 +101,12 @@
 	    }		
 	}
-	print "$skycell_id $projection_cell\n";	
+#	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PSWARP.OUTPUT", $path_base, $skycell_id);
-	print "$file $state $quality\n";
+#	print "$file $state $quality\n";
 	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base, $skycell_id);
-	    print "$mask\n";
+#	    print "$mask\n";
 	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
@@ -118,5 +119,5 @@
 	}
 	$command .= " ${outroot}.${projection_cell} ";
-	print "$command\n";
+#	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
 	unless ($success) {
@@ -197,12 +198,12 @@
 	    }		
 	}
-	print "$skycell_id $projection_cell\n";	
+#	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PPSUB.OUTPUT", $path_base, $skycell_id);
-	print "$file $state $quality\n";
+#	print "$file $state $quality\n";
 	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PPSUB.OUTPUT.MASK", $path_base, $skycell_id);
-	    print "$mask\n";
+#	    print "$mask\n";
 	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
@@ -215,5 +216,5 @@
 	}
 	$command .= " ${outroot}.${projection_cell} ";
-	print "$command\n";
+#	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
 	unless ($success) {
@@ -297,12 +298,16 @@
 		$tangents{$projection_cell}{$key}{FILE} = $tempFile;
 		$tangents{$projection_cell}{$key}{NAME} = $tempName;
+		$tangents{$projection_cell}{$key}{N}    = 0;
 	    }
 	}
 	foreach my $key (keys %products) {
-	    print "$skycell_id $projection_cell\n";	
+#	    print "$skycell_id $projection_cell\n";	
 	    my $file = $ipprc->filename($products{$key}, $path_base, $skycell_id);
-	    print "$file $state $quality\n";
+#	    print "$file $state $quality\n";
 	    my $f_fh = $tangents{$projection_cell}{$key}{FILE};
-	    print $f_fh "$file\n";
+	    if ($ipprc->file_exists($file)) {
+		print $f_fh "$file\n";
+		$tangents{$projection_cell}{$key}{N} ++;
+	    }
 	}
     }
@@ -322,15 +327,22 @@
 		$command .= " -Di BIN1 1 -Di BIN2 1 ";
 	    }
-	    elsif ($key eq 'image') {
-		$command .= " -masks $tangents{$projection_cell}{mask}{NAME} ";
-	    }
-	    elsif ($key eq 'mask') { 
-		next; # This should be made with the images.
-	    }
-	    print "$command\n";
-	    ( $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 ppSkycell: $error_code", $stage_id, $error_code);
+# 	    elsif ($key eq 'image') {
+# 		$command .= " -masks $tangents{$projection_cell}{mask}{NAME} ";
+# 	    }
+# 	    elsif ($key eq 'mask') { 
+# 		next; # This should be made with the images.
+# 	    }
+	    else {
+		# Append the image list to other objects, in case the WCS information is unpopulated
+		$command .= " -wcsref $tangents{$projection_cell}{image}{NAME} ";
+	    }
+	    if ($tangents{$projection_cell}{$key}{N} > 0) {
+		print "$command\n";
+		( $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);
+#		    print "Was unable to perform ppSkycell $stage_id $error_code $key\n";
+		    &my_die("unable to perform ppSkycell: $error_code", $stage_id, $error_code);
+		}
 	    }
 	}
