Index: branches/czw_branch/20110406/pstamp/scripts/detectability_respond.pl
===================================================================
--- branches/czw_branch/20110406/pstamp/scripts/detectability_respond.pl	(revision 31215)
+++ branches/czw_branch/20110406/pstamp/scripts/detectability_respond.pl	(revision 31216)
@@ -55,5 +55,5 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --input --output --dbname",
+pod2usage( -msg => "Required options: --input --output --dbname --workdir",
 	   -exitval => 3,
     ) unless
@@ -91,4 +91,10 @@
     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 $terminator = $/;
+    undef $/;
+    my $wisdom = <WISDOM>;
+    $/ = $terminator;
+    
+    # @query_list = parse_md_list( parse($wisdom));
     while(<WISDOM>) {
 	chomp;
@@ -133,8 +139,8 @@
 		@row_data{@column_names} = (split /\s+/, $entry);
 		for (my $i = 0; $i <= $#column_names; $i++) {
-		push @{ $query{$row_data{"FPA_ID"}}{$column_names[$i]} }, $row_data{$column_names[$i]};
-		$Nrows = scalar(keys(%query));
+		    push @{ $query{$row_data{"FPA_ID"}}{$column_names[$i]} }, $row_data{$column_names[$i]};
+		    $Nrows = scalar(keys(%query));
 #		print "$row_data{'FPA_ID'} $Nrows $i $column_names[$i] $row_data{$column_names[$i]}\n";
-	    }
+		}
 	    }
 	}
@@ -233,10 +239,10 @@
 	# Call the PStamp code to find the images that contain the target on the given MJD in the specified filter.
 	my $pstamp_images_ref = locate_images($ipprc,$imagedb,
-					  \@rowList,
-					  $query_style,$stage,
-					  $fpa_id,undef,undef,
-					  $option_mask,$need_magic,
-					  # $ra,$dec,
-					  $mjd_min,$mjd_max,$filter . ".00000",undef,$verbose);  
+					      \@rowList,
+					      $query_style,$stage,
+					      $fpa_id,undef,undef,
+					      $option_mask,$need_magic,
+					      # $ra,$dec,
+					      $mjd_min,$mjd_max,$filter . ".00000",undef,$verbose);  
 	
 	foreach my $this_image_ref (@{ $pstamp_images_ref }) {
@@ -325,11 +331,13 @@
 
 open(WISDOM,">$wisdom_file") or my_die("failed to open wisdom file $wisdom_file");
-foreach my $fpa_id (keys %query) {
+print WISDOM "DETECTABILITY_WISDOM MULTI\n\n";
+foreach my $fpa_id (sort {$query{$a}{ROWNUM} <=> $query{$a}{ROWNUM} } (keys %query)) {
     for (my $i = 0; $i <= $#{ $query{$fpa_id}{ROWNUM} }; $i++) {
-	print WISDOM "$fpa_id\t";
+	print WISDOM "DETECTABILITY_WISDOM METADATA\n";
+	printf(WISDOM "   %15s  %3s       %s\n","FPA_ID","STR",$fpa_id);
 	foreach my $key (keys %{ $query{$fpa_id} }) {
-	    print WISDOM "$key $query{$fpa_id}{$key}[$i]\t";
-	}
-	print WISDOM "\n";
+	printf(WISDOM "   %15s  %3s       %s\n",$key,"STR",$query{$fpa_id}{$key}[$i]);
+	}
+	print WISDOM "END\n\n";
 	if ($query{$fpa_id}{BAD_COMPONENT}[$i] == 0) {
 	    @{ $update_request{$query{$fpa_id}{IMAGE}[$i]}{$query{$fpa_id}{FAULT}[$i]} } = 
