Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 25712)
+++ 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";
