Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 25775)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 25776)
@@ -108,14 +108,8 @@
     } elsif ($req_type eq "bycoord") {
 
-        # run
-        # regtool -dbname $image_db -processedimfile -time_begin $mjd_min -time_end = $mjd_max -filter $filter
-        #
-        my $results = lookup_bycoord($ipprc, $image_db, $x, $y, $dateobs_begin, $dateobs_end, $filter, $verbose);
-
-        # now take the results and lookup byexp
-        # XXX: This needs work. What stops results from returning multiple images????
-        # We should loop over the set of images returned building up the full results array
-        $req_type = "byexp";
-        $id = $results->{exp_name};
+        if ($img_type eq "stack") {
+            print STDERR "Error bycoord lookup not implemented for stage stack yet\n";
+            return undef;
+        }
     } elsif ($req_type eq "byskycell") {
         if (($img_type eq "raw") or ($img_type eq "chip")) {
@@ -129,5 +123,5 @@
     }
 
-    my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, $dateobs_begin, $dateobs_end, $filter, $label, $verbose);
+    my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $label, $verbose);
 
     return $results;
@@ -143,4 +137,6 @@
     my $component= shift;
     my $need_magic = shift;
+    my $x        = shift;
+    my $y        = shift;
     my $dateobs_begin = shift;
     my $dateobs_end   = shift;
@@ -175,9 +171,13 @@
 
     my $magic_arg = $need_magic ? " -destreaked" : "";
+    my $component_args;
     if ($img_type eq "raw") {
         $class_id = $component;
         $command = "$regtool -processedimfile -dbname $image_db";
+        # XXX: for now restrict lookups to type object 
+        # are stamps of detrend exposures interesting?
+        $command .= " -exp_type object";
         $id_opt = "-exp_id";
-        $command .= " -class_id $class_id" if $component;
+        $component_args = " -class_id $class_id" if $component;
         $want_astrom = 1;
         $set_class_id = 1;
@@ -185,5 +185,5 @@
         $class_id = $component;
         $command = "$chiptool -processedimfile -dbname $image_db";
-        $command .= " -class_id $class_id" if $class_id;
+        $component_args = " -class_id $class_id" if $class_id;
         $id_opt = "-chip_id";
         $image_name   = "PPIMAGE.CHIP";
@@ -196,5 +196,5 @@
         $skycell_id = $component;
         $command = "$warptool -warped -dbname $image_db";
-        $command .= " -skycell_id $skycell_id" if $skycell_id;
+        $component_args = " -skycell_id $skycell_id" if $skycell_id;
         $id_opt = "-warp_id";
         $image_name   = "PSWARP.OUTPUT";
@@ -205,5 +205,5 @@
         $skycell_id = $component;
         $command = "$difftool -diffskyfile -dbname $image_db";
-        $command .= " -skycell_id $skycell_id" if $skycell_id;
+        $component_args = " -skycell_id $skycell_id" if $skycell_id;
         $id_opt = "-diff_id";
         $image_name  = "PPSUB.OUTPUT";
@@ -212,6 +212,8 @@
         $base_name   = "path_base";
     } elsif ($img_type eq "stack") {
+        $skycell_id = $component;
         $command = "$stacktool -sumskyfile -dbname $image_db";
         $id_opt = "-stack_id";
+        $component_args = " -skycell_id $skycell_id" if $skycell_id;
 
         $image_name  = "PPSTACK.OUTPUT";
@@ -225,8 +227,13 @@
     if ($req_type eq "byid") {
         $command .= " $id_opt $id";
+        $command .= $component_args if $component_args;
     } elsif ($req_type eq "byexp") {
         $command .= " -exp_name $id";
+        $command .= $component_args if $component_args;
     } elsif ($req_type eq "byskycell") {
+        die "tess_id and component are required for byskycell" if !$tess_id or ! $skycell_id;
         $command .= " -tess_id $tess_id -skycell_id $skycell_id";
+    } elsif ($req_type eq "bycoord") {
+        $command .= " -radius 3.0 -ra $x -decl $y";
     } else {
         die "Unknown req_type supplied: $req_type";
Index: trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- trunk/pstamp/scripts/pstampparse.pl	(revision 25775)
+++ trunk/pstamp/scripts/pstampparse.pl	(revision 25776)
@@ -195,4 +195,6 @@
     my $mjd_max = $row->{MJD_MAX};
     my $label   = $row->{LABEL};
+    my $x       = $row->{CENTER_X};
+    my $y       = $row->{CENTER_Y};
 
     my $option_mask= $row->{OPTION_MASK};
@@ -205,5 +207,5 @@
     
     if (!$skycenter and !$search_component) {
-        print STDERR "COMPONENT must be specified for pixel coordinate ROI\n" if $verbose;
+        print STDERR "COMPONENT must be specified for pixel coordinate ROI center\n" if $verbose;
         insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
         $num_jobs++;
@@ -213,5 +215,5 @@
     $search_component = "" if $search_component eq "all";
 
-    if (($job_type eq "stamp") and ! validROI($row)) {
+    if ((($job_type eq "stamp") or ($req_type eq "bycoord")) and ! validROI($row)) {
         print STDERR "invalid ROI for row $rownum\n" if $verbose;
         insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
@@ -262,23 +264,22 @@
             next;
         }
-        print STDERR "lookup bycoord is not yet implemented" if $verbose;
-        insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
-        $num_jobs++;
-        next;
-    } else {
-        # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
-        # request specification. An array reference is returned.
-        my ($x, $y);
-
-        $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $tess_id, $search_component,
+        if ($stage eq "stack") {
+            print STDERR "lookup bycoord is not yet implemented for stage stack" if $verbose;
+            insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
+            $num_jobs++;
+            next;
+        }
+    }
+    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
+    # request specification. An array reference is returned.
+    $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $tess_id, $search_component,
                 $inverse, $need_magic, $x, $y, $mjd_min, $mjd_max, $filter, $label, $verbose);
 
-        if (!$imageList or !@$imageList) {
-            print STDERR "no matching images found for row $rownum\n" if $verbose;
-            # note in this case queueJobs inserts the fake job for these rows
-        }
-        $row->{need_magic} = $need_magic;
-        push @rowList, $row;
-    }
+    if (!$imageList or !@$imageList) {
+        print STDERR "no matching images found for row $rownum\n" if $verbose;
+        # note in this case queueJobs inserts the fake job for these rows
+    }
+    $row->{need_magic} = $need_magic;
+    push @rowList, $row;
 }
 
