Index: /trunk/ippScripts/scripts/lap_science.pl
===================================================================
--- /trunk/ippScripts/scripts/lap_science.pl	(revision 33075)
+++ /trunk/ippScripts/scripts/lap_science.pl	(revision 33076)
@@ -33,5 +33,5 @@
 # Global configuration constants that probably should be read from elsewhere.  
 my $qstack_threshold     = 0.05; # Only make a quickstack if more than 5% of the exposures require it.
-my $minimum_stack_inputs = 6;    # We can avoid magicking stack inputs if we have more than this number.
+my $minimum_stack_inputs = 2;    # We can avoid magicking stack inputs if we have more than this number.
 
 GetOptions(
@@ -620,5 +620,4 @@
     my $are_warped = 0;
     my $are_magicked = 0;
-
     foreach my $exposure (@$exposures) {
 	$total_exposures++;
@@ -710,17 +709,26 @@
 	    $exposure->{data_state} = 'to_diff';
 	}
-	if (($exposure->{diff_id})&&(&S64_IS_NOT_NULL($exposure->{diff_id}))) {
+	if (($exposure->{diff_id})&&
+	    (&S64_IS_NOT_NULL($exposure->{diff_id}))&&
+	    (($exposure->{diffRun_state} eq 'full')||
+	     ($exposure->{diffRun_state} eq 'cleaned'))
+	    ) {
+	    $are_magicked++;
 	    $have_diff ++;
-	    $exposure->{data_state} = 'to_magic';
-	}
-	if (($exposure->{magicked})&&
-	    ($exposure->{warpRun_state})&&
-	    ($exposure->{warpRun_state} eq 'full')&&
-	    (&S64_IS_NOT_NULL($exposure->{magicked}))) {  # This exposure has been magicked, so it is through with diff.
-	    $are_magicked++;
+#	    $exposure->{data_state} = 'to_magic';
 	    $exposure->{data_state} = 'full';
-#	    $can_fstack ++;
-	}
-	&update_this_exposure($exposure);
+	}
+	# We no longer need to care about magic
+# 	if (($exposure->{magicked})&&
+# 	    ($exposure->{warpRun_state})&&
+# 	    ($exposure->{warpRun_state} eq 'full')&&
+# 	    (&S64_IS_NOT_NULL($exposure->{magicked}))) { # This exposure has been magicked, so it is through with diff.
+# 	    $are_magicked++;
+# 	    $exposure->{data_state} = 'full';
+# #	    $can_fstack ++;
+# 	}
+	unless ($debug) {
+	    &update_this_exposure($exposure);
+	}
     }
 
@@ -748,5 +756,8 @@
 	if ($defined_fstack == 0) {        # We have not yet made any stacks.
 	    print "STATUS: We can attempt to queue deep final stacks.\n";
-	    my $Nstacks_made = &queue_muggle_finalstack($exposures);
+	    my $Nstacks_made;
+	    unless ($debug) {
+		$Nstacks_made = &queue_muggle_finalstack($exposures);
+	    }
 	    print "STATUS: Made $Nstacks_made final stacks.\n";
 	    exit($Nstacks_made);
@@ -756,4 +767,5 @@
 	    if ($have_fstack == $defined_fstack) { # We have made all the stacks we have asked for (so far)
 		if ($are_magicked < $total_exposures) { # But we have not yet made diffs
+#		if ($have_diff < $total_exposures) { # We have not yet made diffs
 		    if (($can_diff == $total_exposures)&& # And we have exposures that should be diffed.
 			($have_diff < $can_diff)) {       # and we haven't made them all yet, either.
@@ -763,5 +775,7 @@
 # 			    &update_this_exposure($exposure);
 # 			}
-			&queue_diffs($exposures);
+			unless ($debug) {
+			    &queue_diffs($exposures);
+			}
 			exit(0);
 		    }
@@ -774,24 +788,30 @@
 		}
 		elsif ($are_magicked == $total_exposures) { # We have made all of the diffs, and propagated through magic
-		    print "STATUS: We can create all remaining stacks possible.\n";
-		    my $Nstacks_made = &queue_magic_finalstack($exposures);
-		    if ($Nstacks_made == 0) { # We have made all the stacks that we will ever make.
+		    print "STATUS: We would create all remaining stacks possible, but no longer require magic.\n";
+# 		    my $Nstacks_made = -1;
+# 		    unless ($debug) {
+# 			$Nstacks_made = &queue_muggle_finalstack($exposures);
+# 		    }
+# 		    if ($Nstacks_made == 0) { # We have made all the stacks that we will ever make.
 			print "STATUS: No more stacks generated. Deactivating exposures for this complete lapRun.\n";
-			&deactivate_exposures($exposures);
-			$command = "$laptool -updaterun -lap_id $lap_id";
-			$command .= " -dbname $dbname " if defined $dbname;
-			$command .= " -set_state full ";
-			my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-			    run(command => $command, verbose => $verbose);
-			unless ($success) {
-			    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-			    &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
-			}
+			unless ($debug) {
+			    &deactivate_exposures($exposures);
+			
+			    $command = "$laptool -updaterun -lap_id $lap_id";
+			    $command .= " -dbname $dbname " if defined $dbname;
+			    $command .= " -set_state full ";
+			    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+				run(command => $command, verbose => $verbose);
+			    unless ($success) {
+				$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+				&my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
+			    }
+# 			}
 			exit(0);
 		    }
-		    else { 
-			print "STATUS: $Nstacks_made stacks made.\n";
-			exit(0);
-		    }
+# 		    else { 
+# 			print "STATUS: $Nstacks_made stacks made.\n";
+# 			exit(0);
+# 		    }
 		}
 		else { # What?
@@ -995,5 +1015,5 @@
     foreach $exposure (@$exposures) {
 	if (($exposure->{data_state} ne 'drop')&&
-	    (S64_IS_NOT_NULL($exposure->{magicked}))&&
+#	    (S64_IS_NOT_NULL($exposure->{magicked}))&&
 	    (S64_IS_NOT_NULL($exposure->{warp_id}))) {
 	    $warps .= " -warp_id $exposure->{warp_id} ";
@@ -1478,10 +1498,12 @@
 	$command .= " -set_data_state $exposure->{data_state} ";
     }
-
-    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => $verbose);
-    unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform laptool -updateexp: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
+    unless ($do_nothing) {
+	my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $command, verbose => $verbose);
+	
+	unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    &my_die("Unable to perform laptool -updateexp: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
+	}
     }
 }    
