Index: trunk/ippScripts/scripts/skycell_jpeg.pl
===================================================================
--- trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 28403)
+++ trunk/ippScripts/scripts/skycell_jpeg.pl	(revision 34800)
@@ -268,4 +268,12 @@
 
     my %tangents = ();
+
+    my %products = ('image' => "PPSTACK.UNCONV",
+		    'mask'  => "PPSTACK.UNCONV.MASK",
+		    'variance' => "PPSTACK.UNCONV.VARIANCE",
+		    'exp'   => "PPSTACK.UNCONV.EXP",
+		    'num'   => "PPSTACK.UNCONV.EXPNUM",
+		    'bkg'   => "PPSTACK.OUTPUT.BKGMODEL"
+	);
     
     foreach my $imfile (@$imfiles) {
@@ -281,42 +289,51 @@
 
 	$projection_cell =~ s/^(.*)\..*$/$1/;
-	
+
 	unless (exists($tangents{$projection_cell})) {
 	    # Make a temp file and fill, but be sure to save 
-	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.XXXX",
-						 UNLINK => !$save_temps);
-	    $tangents{$projection_cell}{FILE} = $tempFile;
-	    $tangents{$projection_cell}{NAME} = $tempName;
-	    if ($masks) {
-		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$projection_cell.masks.XXXX",
-						     UNLINK => !$save_temps);
-		$tangents{$projection_cell}{MFILE} = $maskFile;
-		$tangents{$projection_cell}{MNAME} = $maskName;
-	    }		
-	}
-	print "$skycell_id $projection_cell\n";	
-	my $file = $ipprc->filename("PPSTACK.OUTPUT", $path_base, $skycell_id);
-	print "$file $state $quality\n";
-	my $f_fh = $tangents{$projection_cell}{FILE};
-	print $f_fh "$file\n";
-	if ($masks) {
-	    my $mask = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base, $skycell_id);
-	    print "$mask\n";
-	    my $m_fh = $tangents{$projection_cell}{MFILE};
-	    print $m_fh "$mask\n";
+	    foreach my $key (keys %products) {
+		($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.$key.XXXX",
+						  UNLINK => !$save_temps);
+		$tangents{$projection_cell}{$key}{FILE} = $tempFile;
+		$tangents{$projection_cell}{$key}{NAME} = $tempName;
+	    }
+	}
+	foreach my $key (keys %products) {
+	    print "$skycell_id $projection_cell\n";	
+	    my $file = $ipprc->filename($products{$key}, $path_base, $skycell_id);
+	    print "$file $state $quality\n";
+	    my $f_fh = $tangents{$projection_cell}{$key}{FILE};
+	    print $f_fh "$file\n";
 	}
     }
     foreach my $projection_cell (keys %tangents) {
-	$command = "$ppSkycell -images $tangents{$projection_cell}{NAME}";
-	if ($masks) {
-	    $command .= " -masks $tangents{$projection_cell}{MNAME} ";
-	}
-	$command .= " ${outroot}.${projection_cell} ";
-	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);
-	}
+	## Loop over results here.
+	# Images
+	# Masks
+	# Variances
+	# Nexptime
+	# Nexp
+	# Backgrounds
+	
+	foreach my $key (keys %products) {
+	    $command = "$ppSkycell -images $tangents{$projection_cell}{$key}{NAME}";
+	    $command .= " ${outroot}.${projection_cell}.${key} ";
+	    if ($key eq 'bkg') {
+		$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);
+	    }
+	}
+
 	# Update database:
 	$command = "$stacktool -addsummary -sass_id $stage_id -projection_cell $projection_cell -path_base $outroot";
