Index: trunk/pstamp/scripts/detectability_respond.pl
===================================================================
--- trunk/pstamp/scripts/detectability_respond.pl	(revision 33126)
+++ trunk/pstamp/scripts/detectability_respond.pl	(revision 33141)
@@ -41,5 +41,5 @@
 my $EXTVER = 1.0;
 my $EXTNAME = 'MOPS_DETECTABILITY_RESPONSE';
-my ($req_id,$req_name,$product,$need_magic,$missing_tools,$project);
+my ($req_id,$job_id,$req_name,$product,$need_magic,$missing_tools,$project);
 my ($request_file,$output,$workdir,$dbname,$dbserver,$verbose,$save_temps,$ignore_wisdom);
 GetOptions(
@@ -47,4 +47,5 @@
     'output=s'        =>      \$output,
     'workdir=s'       =>      \$workdir,
+    'job_id=s'        =>      \$job_id,
     'dbname=s'        =>      \$dbname,
     'dbserver=s'      =>      \$dbserver,
@@ -298,5 +299,5 @@
 			$query{$fpa_id}{FAULT}[$valid_index] = $PSTAMP_GONE;
 		    }
-		    elsif ($need_magic and ($query{$fpa_id}{MAGICKED}[$valid_index] = 0)) {
+		    elsif ($need_magic and ($query{$fpa_id}{MAGICKED}[$valid_index] eq 0)) {
 			$query{$fpa_id}{FAULT}[$valid_index] = $PSTAMP_NOT_DESTREAKED;
 		    }
@@ -324,45 +325,47 @@
 my %processing_request;
 
-open(WISDOM,">$wisdom_file") or my_die("failed to open wisdom file $wisdom_file");
-foreach my $fpa_id (keys %query) {
-    for (my $i = 0; $i <= $#{ $query{$fpa_id}{ROWNUM} }; $i++) {
-	print WISDOM "$fpa_id\t";
-	foreach my $key (keys %{ $query{$fpa_id} }) {
-	    print WISDOM "$key $query{$fpa_id}{$key}[$i]\t";
-	}
-	print WISDOM "\n";
-        my $data_state = $query{$fpa_id}{DATA_STATE}[$i];
-	if ($query{$fpa_id}{BAD_COMPONENT}[$i] == 0) {
-            if ($data_state ne 'full') {
-                
-                @{ $update_request{$query{$fpa_id}{IMAGE}[$i]}{$query{$fpa_id}{FAULT}[$i]} } = 
-                    ($query{$fpa_id}{STATE}[$i],$query{$fpa_id}{STAGE}[$i],$query{$fpa_id}{STAGE_ID}[$i],
-                     $query{$fpa_id}{COMPONENT_ID}[$i],$query{$fpa_id}{NEED_MAGIC}[$i],$query{$fpa_id}{IMAGE_DB}[$i]);
+if (!$job_id) {
+    open(WISDOM,">$wisdom_file") or my_die("failed to open wisdom file $wisdom_file");
+    foreach my $fpa_id (keys %query) {
+        for (my $i = 0; $i <= $#{ $query{$fpa_id}{ROWNUM} }; $i++) {
+            print WISDOM "$fpa_id\t";
+            foreach my $key (keys %{ $query{$fpa_id} }) {
+                print WISDOM "$key $query{$fpa_id}{$key}[$i]\t";
             }
-	    push @{ $processing_request{$fpa_id}{$query{$fpa_id}{IMAGE}[$i]} }, $i;
-	}
-    }
-}
-close(WISDOM);
-
-# If there is anything that needs to be updated, create the update request list, and then exit the program.
-my $exit_code = 0;
-my $update_request_file = "${workdir}/update_request.dat";
-open(UPDATE_REQUEST,">$update_request_file") or my_die("failed to open update request_file $update_request_file");
-foreach my $images (keys %update_request) {
-    foreach my $fault (keys %{ $update_request{$images} }) {
-	if ($fault == 25) {
-	    $exit_code = 25;
-	}
-	elsif ($fault != 0) {
-	    $exit_code = 21;
-	}
-	my $update_request = join ' ', @{ $update_request{$images}{$fault} };
-	print UPDATE_REQUEST "$update_request\n";
-    }
-}
-close(UPDATE_REQUEST);
-if ($exit_code != 0) {
-    exit($exit_code);
+            print WISDOM "\n";
+            my $data_state = $query{$fpa_id}{DATA_STATE}[$i];
+            if ($query{$fpa_id}{BAD_COMPONENT}[$i] == 0) {
+                if ($data_state ne 'full') {
+                    
+                    @{ $update_request{$query{$fpa_id}{IMAGE}[$i]}{$query{$fpa_id}{FAULT}[$i]} } = 
+                        ($query{$fpa_id}{STATE}[$i],$query{$fpa_id}{STAGE}[$i],$query{$fpa_id}{STAGE_ID}[$i],
+                         $query{$fpa_id}{COMPONENT_ID}[$i],$query{$fpa_id}{NEED_MAGIC}[$i],$query{$fpa_id}{IMAGE_DB}[$i]);
+                }
+                push @{ $processing_request{$fpa_id}{$query{$fpa_id}{IMAGE}[$i]} }, $i;
+            }
+        }
+    }
+    close(WISDOM);
+
+    # If there is anything that needs to be updated, create the update request list, and then exit the program.
+    my $exit_code = 0;
+    my $update_request_file = "${workdir}/update_request.dat";
+    open(UPDATE_REQUEST,">$update_request_file") or my_die("failed to open update request_file $update_request_file");
+    foreach my $images (keys %update_request) {
+        foreach my $fault (keys %{ $update_request{$images} }) {
+            if ($fault == 25) {
+                $exit_code = 25;
+            }
+            elsif ($fault != 0) {
+                $exit_code = 21;
+            }
+            my $update_request = join ' ', @{ $update_request{$images}{$fault} };
+            print UPDATE_REQUEST "$update_request\n";
+        }
+    }
+    close(UPDATE_REQUEST);
+    if ($exit_code != 0) {
+        exit($exit_code);
+    }
 }
 
@@ -714,4 +717,7 @@
     $status = 0;
 #    print "$output\n";
+    if (-e $output) {
+        unlink $output or die "failed to unlink existing response file $output\n";
+    }
     my $outFits = Astro::FITS::CFITSIO::create_file( $output, $status );
     check_fitsio( $status );
