Index: /tags/ipp-ops-20220705/ippScripts/scripts/nightly_science.pl
===================================================================
--- /tags/ipp-ops-20220705/ippScripts/scripts/nightly_science.pl	(revision 42262)
+++ /tags/ipp-ops-20220705/ippScripts/scripts/nightly_science.pl	(revision 42263)
@@ -1561,5 +1561,5 @@
         $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
         $input_sth .=   " AND camProcessedExp.fwhm_major <= $maxFWHM ";
-        $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
+        $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY rawExp.comment,dateobs ";
 
         my $warps = $db->selectall_arrayref( $input_sth );
@@ -1572,4 +1572,10 @@
             my $this_quality = ${ $this_warp }[5];
             my $this_state   = ${ $this_warp }[4];
+            my $this_warp_id  = ${ $this_warp }[1];
+            if (($this_warp_id eq 'NULL') && (($this_quality == 0) || ($this_quality eq 'NULL')) ) {
+                print STDERR "diff_queue: excluding $this_object from making diffs due to exposure $this_exp_id not being processed to warp stage\n";
+                next;
+            }
+
             if (($this_quality != 0) || ($this_state eq 'drop') ) {
                 print STDERR "diff_queue: excluding $this_exp_id for $this_object due to non-zero cam.quality $this_quality or state $this_state\n";
@@ -1752,5 +1758,5 @@
             $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
             $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
-            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
+            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY rawExp.comment,dateobs ";
 
             my $warps = $db->selectall_arrayref( $input_sth );
@@ -2124,5 +2130,5 @@
             $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
             $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
-            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
+            $input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY rawExp.comment,dateobs ";
 
             my $warps = $db->selectall_arrayref( $input_sth );
