Index: trunk/pstamp/scripts/detect_query_read
===================================================================
--- trunk/pstamp/scripts/detect_query_read	(revision 27783)
+++ trunk/pstamp/scripts/detect_query_read	(revision 27788)
@@ -78,10 +78,16 @@
                         comment => 'site identifier (MPC observatory code)',
                         value => undef
-              }
+                      },
+ 	'STAGE'    => { 
+	                name => 'STAGE',
+			writetype => TSTRING,
+			comment => 'processing stage to examine',
+			value => undef
+	              }
 };
 
 # key_array insures that the order that the keywords is printed out is
 # the same as the ICD
-my @key_array = qw( QUERY_ID FPA_ID MJD_OBS FILTER OBSCODE );
+my @key_array = qw( QUERY_ID FPA_ID MJD_OBS FILTER OBSCODE STAGE);
 
 # Specification of columns
@@ -144,4 +150,7 @@
         my $name = $header->{$key}->{name};
         my $value = $inHeader->{$name};
+	if (($key eq 'STAGE')&& !(defined($value))) {
+	    $value = 'DIFF';
+	}
         # get rid of quotes and whitespace
         $value =~ s/\'//g;
Index: trunk/pstamp/scripts/detectability_respond.pl
===================================================================
--- trunk/pstamp/scripts/detectability_respond.pl	(revision 27783)
+++ trunk/pstamp/scripts/detectability_respond.pl	(revision 27788)
@@ -73,4 +73,5 @@
 #my $tmp_dir = "/data/${host}.0/tmp/";
 
+my $project = resolve_project($ipprc,"project_name",$dbname);
 #
 # Parse input request file using detect_query_read (as it's already written).
@@ -120,5 +121,4 @@
 for (my $i = 1; $i < $Nrows; $i++) {
 #    print "$i $Nrows $query{CONTENT}{RA1_DEG}[$i] $query{CONTENT}{DEC1_DEG}[$i]\n";
-
     my $image_set_tmp  = find_image_set($query{HEADER}{FPA_ID}[0],$query{HEADER}{STAGE}[0],
 					$query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],
@@ -143,4 +143,5 @@
 my $i = 0;
 
+
 foreach my $k (keys %image_list_hash) {
     # Write coordinates of the requested targets to a file.
@@ -153,5 +154,5 @@
 	print $coordfile "$image_list_hash{$k}{SKY_COORDINATES}[$j]\n";
     }
-
+    print "$k\n";
     # Convert the sky coordinates to image coordinates with ppCoord.
     my $command = "ppCoord -astrom $image_list_hash{$k}{CATALOG} -radec $coordname";
@@ -171,5 +172,5 @@
     }
 
-    
+    print "psphot $image_list_hash{$k}{PSF}\n";
     # Run psphotForced on the target list.
     my $tmpdir  = tempdir("detect.$i.XXXX", DIR => "/tmp/", CLEANUP => !$save_temps);
@@ -215,5 +216,5 @@
 		    $query{HEADER}{obscode}[0],
 		    \@rownums, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux);
-
+print "Wrote response file $output\n";
 #
 # Add to datastore
@@ -252,8 +253,21 @@
     my $mjd_max = $mjd + 1;
 
+    # Construct a row list:
+
+    my @rowList;
+    $rowList[0]->{CENTER_X} = $ra;
+    $rowList[0]->{CENTER_Y} = $dec;
+    $rowList[0]->{ID} = 1;
+    $rowList[0]->{STAGE} = $stage;
+    $rowList[0]->{COORD_MASK} = 0;
+    print "$stage\n";
     # Call the PStamp code to find the images that contain the target on the given MJD in the specified filter.
-    my @images = locate_images($ipprc,$dbname,"bycoord",$stage,
-			       undef,undef,undef,$option_mask,$need_magic,
-			       $ra,$dec,$mjd_min,$mjd_max,$filter . ".00000",undef,$verbose);  
+    my @images = locate_images($ipprc,$dbname,
+			        \@rowList,
+			       "bycoord",$stage,
+			       undef,undef,undef,
+			       $option_mask,$need_magic,
+			       # $ra,$dec,
+			       $mjd_min,$mjd_max,$filter . ".00000",undef,$verbose);  
 
     my %image_info  = ();
Index: trunk/pstamp/test/detect_query_create
===================================================================
--- trunk/pstamp/test/detect_query_create	(revision 27783)
+++ trunk/pstamp/test/detect_query_create	(revision 27788)
@@ -16,4 +16,5 @@
      $output,			# Name of output table
      $query_id, 
+     $nostage,
      );
 
@@ -22,4 +23,5 @@
 	   'output|o=s'   => \$output,
 	   'query_id|q=s'  => \$query_id,
+           'nostage'      => \$nostage,
 ) or pod2usage( 2 );
 
@@ -61,4 +63,11 @@
         }
 ];
+unless(defined($nostage)) {
+    push @{ $header },        { name =>  'STAGE',
+				writetype => TSTRING,
+				comment => 'processing stage to examine',
+				value => undef
+    };
+}
 
 # Specification of columns to write
