Index: trunk/pstamp/scripts/detectability_respond.pl
===================================================================
--- trunk/pstamp/scripts/detectability_respond.pl	(revision 29081)
+++ trunk/pstamp/scripts/detectability_respond.pl	(revision 29130)
@@ -91,8 +91,8 @@
     print "Reading wisdom file $wisdom_file instead of parsing...\n";
     open(WISDOM,"$wisdom_file") or my_die("failed to open wisdom file $wisdom_file");
-    my $i = 0;
     while(<WISDOM>) {
 	chomp;
 	my ($fpa_id,@key_values) = split /\s+/;
+	my $index = $#{ $query{$fpa_id}{ROWNUM} } + 1;
 	while ($#key_values > -1) {
 	    my $key = shift(@key_values);
@@ -102,7 +102,6 @@
 		$val = 0;
 	    }
-	    $query{$fpa_id}{$key}[$i] = $val;
-	}
-	$i++;
+	    $query{$fpa_id}{$key}[$index] = $val;
+	}
     }
     close(WISDOM);
@@ -150,52 +149,32 @@
 	my $filter;
 	my $mjd;
-	# Determine the query style for this fpa_id
-	if ($fpa_id =~ /o.*g.*o/) {
-	    $query_style = 'byexp';
-	}
-	elsif ($fpa_id =~ /\d+/) {
-	    $query_style = 'byid';
-	}
-	else {
-	    exit_with_failure(21,"Parse error in request file");
-	}
 	# Confirm that we only have one stage/filter/mjd
-	for (my $i = 0; $i <= $#{ $query{$fpa_id}{STAGE} }; $i++) {
-	    $temp_hash{STAGE}{$query{$fpa_id}{STAGE}[$i]} = 1;
-	    $temp_hash{FILTER}{$query{$fpa_id}{FILTER}[$i]} = 1;
-	    $temp_hash{'MJD-OBS'}{$query{$fpa_id}{'MJD-OBS'}[$i]} = 1;
-	}
-	if (scalar(keys(%{ $temp_hash{STAGE} })) == 1) {
-	    $stage = (keys(%{ $temp_hash{STAGE} }))[0];
-	}
-	else {
-	    exit_with_failure(21,"Too many STAGEs specified");
-	}
-	if (scalar(keys(%{ $temp_hash{FILTER} })) == 1) {
-	    $filter = (keys(%{ $temp_hash{FILTER} }))[0];
-	}
-	else {
-	    exit_with_failure(21,"Too many FILTERs specified");
-	}
-	if (scalar(keys(%{ $temp_hash{'MJD-OBS'} })) == 1) {
-	    $mjd = (keys(%{ $temp_hash{'MJD-OBS'} }))[0];
-	}
-	else {
-	    exit_with_failure(21,"Too many MJD-OBS specified");
-	}
-	# Set common request components
-	my $option_mask |= 1;
-	$option_mask |= $PSTAMP_SELECT_IMAGE;
-	$option_mask |= $PSTAMP_SELECT_MASK;
-	$option_mask |= $PSTAMP_SELECT_VARIANCE;
-	$option_mask |= $PSTAMP_SELECT_PSF;
-	my $need_magic = 1;
-	if ($stage eq 'stack') {
-	    $need_magic = 0;
-	}
-	my $mjd_min = $mjd;
-	my $mjd_max = $mjd + 1;
-	
-	# Construct a row list. 
+	if ($fpa_id ne 'Not_Set') {   # We only need to check things that aren't the known odd case.
+	    for (my $i = 0; $i <= $#{ $query{$fpa_id}{STAGE} }; $i++) {
+		$temp_hash{STAGE}{$query{$fpa_id}{STAGE}[$i]} = 1;
+		$temp_hash{FILTER}{$query{$fpa_id}{FILTER}[$i]} = 1;
+		$temp_hash{'MJD-OBS'}{$query{$fpa_id}{'MJD-OBS'}[$i]} = 1;
+	    }
+	    if (scalar(keys(%{ $temp_hash{STAGE} })) == 1) {
+		$stage = (keys(%{ $temp_hash{STAGE} }))[0];
+	    }
+	    else {
+		exit_with_failure(21,"Too many STAGEs specified");
+	    }
+	    if (scalar(keys(%{ $temp_hash{FILTER} })) == 1) {
+		$filter = (keys(%{ $temp_hash{FILTER} }))[0];
+	    }
+	    else {
+		exit_with_failure(21,"Too many FILTERs specified");
+	    }
+	    if (scalar(keys(%{ $temp_hash{'MJD-OBS'} })) == 1) {
+		$mjd = (keys(%{ $temp_hash{'MJD-OBS'} }))[0];
+	    }
+	    else {
+		exit_with_failure(21,"Too many MJD-OBS specified");
+	    }
+	}
+
+	# Set up a rowList with default values
 	my @rowList;
 	for (my $i = 0; $i <= $#{ $query{$fpa_id}{STAGE} }; $i++) {
@@ -223,6 +202,32 @@
 	    $query{$fpa_id}{FAULT}[$i] = 'no_fault';
 	    $query{$fpa_id}{BURNTOOL_STATE}[$i] = 'no_btstate';
-
-	}
+	}
+
+	# Determine the query style for this fpa_id
+	if ($fpa_id =~ /o.*g.*o/) {
+	    $query_style = 'byexp';
+	}
+	elsif ($fpa_id =~ /\d+/) {
+	    $query_style = 'byid';
+	}
+	elsif ($fpa_id eq 'Not_Set') {
+	    next;
+	}
+	else {
+	    exit_with_failure(21,"Parse error in request file");
+	}
+	# Set common request components
+	my $option_mask |= 1;
+	$option_mask |= $PSTAMP_SELECT_IMAGE;
+	$option_mask |= $PSTAMP_SELECT_MASK;
+	$option_mask |= $PSTAMP_SELECT_VARIANCE;
+	$option_mask |= $PSTAMP_SELECT_PSF;
+	my $need_magic = 1;
+	if ($stage eq 'stack') {
+	    $need_magic = 0;
+	}
+	my $mjd_min = $mjd;
+	my $mjd_max = $mjd + 1;
+	
 	
 	# Call the PStamp code to find the images that contain the target on the given MJD in the specified filter.
@@ -321,5 +326,5 @@
 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}{STAGE} }; $i++) {
+    for (my $i = 0; $i <= $#{ $query{$fpa_id}{ROWNUM} }; $i++) {
 	print WISDOM "$fpa_id\t";
 	foreach my $key (keys %{ $query{$fpa_id} }) {
@@ -690,5 +695,5 @@
 	    $inHeader->{FPA_ID}->{value} = $fpa_id;
 	}
-
+	
 	push @{$colData{'ROWNUM'}}, @{ $query{$fpa_id}{ROWNUM} };
 	push @{$colData{'ERROR_CODE'}}, @{ $query{$fpa_id}{PROC_ERROR} };
