Index: trunk/PStamp/lib/PStamp/Job.pm
===================================================================
--- trunk/PStamp/lib/PStamp/Job.pm	(revision 21193)
+++ trunk/PStamp/lib/PStamp/Job.pm	(revision 21240)
@@ -25,5 +25,5 @@
 use PS::IPP::Config qw( :standard );
 
-### my @images = locate_images($image_db, $req_type, $img_type, $id, $lookup_class_id,
+### my @images = locate_images($image_db, $req_type, $img_type, $id, $component,
 ###            $mjd_min, $mjd_max, $filter);
 
@@ -34,5 +34,5 @@
     my $img_type = shift;   # required
     my $id       = shift;   # required unless req_type eq bycoord
-    my $class_id = shift;
+    my $component= shift;   # class_id or skycell_id
     my $x        = shift;
     my $y        = shift;
@@ -66,4 +66,5 @@
             $req_type = "byid";
             $id = $results->{warp_id};
+            $component = $results->{skycell_id};
             return undef if !$id;
             # fall through and lookup by warp_id 
@@ -93,5 +94,5 @@
     }
 
-    my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $class_id, $verbose);
+    my $results = lookup($ipprc, $image_db, $req_type, $img_type, $id, $component, $verbose);
 
     return $results;
@@ -104,6 +105,6 @@
     my $img_type = shift;
     my $id       = shift;
-    my $class_id = shift;
-    my $verbose = shift;
+    my $component= shift;
+    my $verbose  = shift;
 
     my $missing_tools;
@@ -124,17 +125,21 @@
     my $want_astrom;
     my $set_class_id;
+    my $class_id;
+    my $skycell_id;
 
     # special class_id value "null" means ignore
-    if ($class_id eq "null") {
-        $class_id = undef;
+    if ($component eq "null") {
+        $component = undef;
     }
 
     if ($img_type eq "raw") {
+        $class_id = $component;
         $command = "$regtool -processedimfile -dbname $image_db";
         $id_opt = "-exp_id";
-        $command .= " -class_id $class_id" if $class_id;
+        $command .= " -class_id $class_id" if $component;
         $want_astrom = 1;
         $set_class_id = 1;
     } elsif ($img_type eq "chip") {
+        $class_id = $component;
         $command = "$chiptool -processedimfile -dbname $image_db";
         $command .= " -class_id $class_id" if $class_id;
@@ -146,5 +151,7 @@
         $set_class_id = 1;
     } elsif ($img_type eq "warp") {
+        $skycell_id = $component;
         $command = "$warptool -warped -dbname $image_db";
+        $command .= " -skycell_id $skycell_id" if $skycell_id;
         $id_opt = "-warp_id";
         $mask_name    = "PSWARP.OUTPUT.MASK";
@@ -152,5 +159,7 @@
         $base_name    = "path_base"; # name of the field for the warptool output
     } elsif ($img_type eq "diff") {
+        $skycell_id = $component;
         $command = "$difftool -diffskyfile -dbname $image_db";
+        $command .= " -skycell_id $skycell_id" if $skycell_id;
         $id_opt = "-diff_id";
         $mask_name   = "PPSUB.OUTPUT.MASK";
@@ -281,22 +290,29 @@
     my $image = $images->[0];
 
+    my $skycell_id = $image->{skycell_id};
+
+    if ($image->{fault}) {
+        print STDERR "selected difference image $id $image->{diff_id} $skycell_id has fault: $image->{fault}\n";
+        return undef;
+    }
+
     # The standard way to do a diff is warp - stack 
     # so we interpret the requested image in that way
 
-    # XXX the query currently returns max long long for null
+    my $stack_id = $image->{stack2};
+    # XXX difftool currently returns max long long for null
     # this line is ready if we switch the code to return zero for null
-    my $stack_id = $image->{stack_id_temp_1};
     if ($stack_id and ($stack_id != 9223372036854775807)) {
         $image->{stack_id} = $stack_id;
     }
 
-    # XXX the query currently returns max long long for null
+    my $warp_id =  $image->{warp1};
+    # XXX difftool currently returns max long long for null
     # this line is ready if we switch the code to return zero for null
-    my $warp_id =  $image->{warp_id_temp_0};
     if ($warp_id and ($warp_id != 9223372036854775807)) {
         $image->{warp_id} = $warp_id;
 
         ## now use the warp and go get the exposure information
-        $command = "warptool -warped -warp_id $warp_id -dbname $image_db -limit 1";
+        $command = "warptool -warped -warp_id $warp_id -skycell_id $skycell_id -dbname $image_db -limit 1";
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
                     run(command => $command, verbose => $verbose);
