Index: /branches/czw_branch/20120906/ippScripts/scripts/skycell_jpeg.pl
===================================================================
--- /branches/czw_branch/20120906/ippScripts/scripts/skycell_jpeg.pl	(revision 34490)
+++ /branches/czw_branch/20120906/ippScripts/scripts/skycell_jpeg.pl	(revision 34491)
@@ -268,4 +268,12 @@
 
     my %tangents = ();
+
+    my %products = ('image' => "PPSTACK.OUTPUT",
+		    'mask'  => "PPSTACK.OUTPUT.MASK",
+		    'variance' => "PPSTACK.OUTPUT.VARIANCE",
+		    'exp'   => "PPSTACK.OUTPUT.EXP",
+		    'num'   => "PPSTACK.OUTPUT.EXPNUM",
+#		    'bkg'   => "PPSTACK.OUTPUT.BKG"
+	);
     
     foreach my $imfile (@$imfiles) {
@@ -281,42 +289,44 @@
 
 	$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} ";
+	    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";
