Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 36010)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 36018)
@@ -774,5 +774,10 @@
         }
 
+
         if ($skycells) {
+            # We have a list of skycells. Find matching projection cells.
+
+            #list of projection_cells that we've included
+            my %projection_cells_found;
             foreach my $skycell (@$skycells) {
                 my $tess_id = $skycell->{tess_id};
@@ -781,6 +786,13 @@
                 my $projection_cell = skycell_id_to_projection_cell($skycell_id);
 
-                print "$tess_id $skycell_id $projection_cell\n";
-                my $command = "$stacktool -dbname $imagedb -summary -tess_id $tess_id -projection_cell $projection_cell";
+                # only need to include a projection cell once
+                next if $projection_cells_found{$projection_cell};
+
+                $projection_cells_found{$projection_cell} = 1;
+
+                # print "$tess_id $skycell_id $projection_cell\n";
+
+                my $command = "$stacktool -dbname $imagedb -summary -tess_id $tess_id";
+                $command .= " -projection_cell $projection_cell";
 
                 $command .= " -filter $filter" if $filter;
@@ -791,6 +803,6 @@
             }
         }
-        # XXX: Lookup stackSummaries that match
-    }
+    }
+
     if ($results) {
         foreach my $summary (@$results) {
@@ -799,8 +811,14 @@
 
             # we need to flesh out the hashes returned with values that the parser expects
+            $summary->{stage} = 'stack_summary';
             $summary->{component} = $projection_cell;
             $summary->{stage_id} = $summary->{sass_id};
-            # $summary->{image} = "$path_base.$projection_cell.image.b1.fits";
-            $summary->{image} = "$path_base.$projection_cell";
+            $summary->{path_base} = "$path_base.$projection_cell";
+
+            # The stack_summary stage doesn't follow the usual ipp conventions for file rules
+            # and path_base. We leave it up to the program that runs the job to handle this.
+            # However, the parser uses the image parameter to set the job's outputBase (by removing the .fits)
+            # so we need to set it. Just use the new path_base.
+            $summary->{image} = $summary->{path_base};
             $summary->{state} = 'full';
             $summary->{data_state} = 'full';
@@ -809,7 +827,8 @@
             $summary->{row_index} = [];
             push @{$summary->{row_index}}, 0;
-            # XXX: is there anything else? 
+
+            # XXX: Are there any other required parameters? 
             # TODO: create a function to validate the components returned
-            # and make sure that any required elements are there
+            # and make sure that any required elements are there.
         }
     }
@@ -1970,10 +1989,17 @@
 }
 
-# not particularly elegant
+# Convert from skycell_id to projection_cell
+# This code is not particularly elegant but I think that it matches the SQL used
+# to create stackAssocations does. 
+
 sub skycell_id_to_projection_cell {
     my $skycell_id = shift;
+
+    # split skycell_id into '.' separated components
     my @strs = split '\.', $skycell_id;
 
     my $num = scalar @strs;
+
+    # projection_cell is 'skycell_id' plus all .num values except the last one
     my $projection_cell = $strs[0];
     for (my $i=1; $i < $num - 1; $i++) {
Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm	(revision 36010)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm	(revision 36018)
@@ -29,4 +29,6 @@
                     $PSTAMP_SELECT_BACKMDL
                     $PSTAMP_SELECT_JPEG
+                    $PSTAMP_SELECT_EXP
+                    $PSTAMP_SELECT_NUM
                     $PSTAMP_SELECT_UNCOMPRESSED
                     $PSTAMP_SELECT_INVERSE
@@ -71,6 +73,6 @@
 our $PSTAMP_SELECT_BACKMDL   = 32;
 our $PSTAMP_SELECT_JPEG      = 64;
-# unused 128
-# unused 256
+our $PSTAMP_SELECT_EXP       = 128;
+our $PSTAMP_SELECT_NUM       = 256;
 our $PSTAMP_SELECT_UNCOMPRESSED = 512;
 our $PSTAMP_SELECT_INVERSE      = 1024;
