Index: /trunk/pstamp/scripts/detect_query_read
===================================================================
--- /trunk/pstamp/scripts/detect_query_read	(revision 41439)
+++ /trunk/pstamp/scripts/detect_query_read	(revision 41440)
@@ -83,8 +83,9 @@
 my ($EXTVER,$headerEXTNAME,$QUERY_ID,
     $FPA_ID,$MJD_OBS,$FILTER,
-    $OBSCODE,$STAGE) = 
+    $OBSCODE,$STAGE,$COMPONENT_ID,$PROJECT,$TESS_ID) = 
     ($inHeader->{EXTVER},$inHeader->{EXTNAME},$inHeader->{QUERY_ID},
      $inHeader->{FPA_ID},$inHeader->{'MJD-OBS'},$inHeader->{FILTER},
-     $inHeader->{OBSCODE},$inHeader->{STAGE});
+     $inHeader->{OBSCODE},$inHeader->{STAGE},$inHeader->{COMPONENT_ID},
+     $inHeader->{PROJECT},$inHeader->{TESS_ID});
 
 unless(defined($EXTVER) && defined($headerEXTNAME) &&
@@ -126,4 +127,10 @@
     # v2 stage: stage name to perform query on, allowed values of 'chip', 'warp', 'stack', and 'diff'
     { name => 'STAGE', type => '20A', writetype => TSTRING, version => 2, default => $STAGE },
+    #
+    { name => 'COMPONENT_ID', type => '20A', writetype => TSTRING, version => 2, default => $COMPONENT_ID },
+    #
+    { name => 'PROJECT', type => '16A', writetype => TSTRING, version => 2, default => $PROJECT },    
+    #
+    { name => 'TESS_ID', type => '64A', writetype => TSTRING, version => 2, default => $TESS_ID },
 ];
 
@@ -203,4 +210,5 @@
 		my ($key,$type,$value) = @line;
 #		print "$entry => $key / $type / $value \n";
+		# if gpc2 then needs .00002
 		if ($key =~ /filter/i) {
 		    $value =~ s/.00000//;
@@ -215,4 +223,5 @@
 	# HACK!
 	my $mjd = $colData{FPA_ID}[$i];
+	# need to remove g for gpc2
 	$mjd =~ s/o(....)g.*/$1/;
 	$mjd += 50000;
@@ -227,4 +236,5 @@
 	my $ra = $colData{'RA1_DEG'}[$i];
 	my $dec = $colData{'DEC1_DEG'}[$i];
+	# if gpc2 then .00002
 	my $filter = $colData{'FILTER'}[$i] . ".00000";
 	my $cmd;
@@ -294,4 +304,5 @@
 
 # Verify uniqueness of important columns:
+# -- need to add PROJECT as well?
 my @unique_fields = ('QUERY_ID','OBSCODE','STAGE');
 foreach my $colName (@unique_fields) {
Index: /trunk/pstamp/scripts/dqueryparse.pl
===================================================================
--- /trunk/pstamp/scripts/dqueryparse.pl	(revision 41439)
+++ /trunk/pstamp/scripts/dqueryparse.pl	(revision 41440)
@@ -76,4 +76,5 @@
 
 # Project name is hardcoded to gpc1 for the moment.
+# -- set gpc1 by default and read in PROJECT column to update for actual query
 $project = resolve_project($ipprc,"gpc1",$dbname,$dbserver);
 my $imagedb = $project->{dbname};
@@ -189,4 +190,6 @@
 	my $filter;
 	my $mjd;
+	my $tess_id;
+	my $component_id;
 	# Confirm that we only have one stage/filter/mjd
 	if ($fpa_id ne 'Not_Set') {   # We only need to check things that aren't the known odd case.
@@ -195,4 +198,7 @@
 		$temp_hash{FILTER}{$query{$fpa_id}{FILTER}[$i]} = 1;
 		$temp_hash{'MJD-OBS'}{$query{$fpa_id}{'MJD-OBS'}[$i]} = 1;
+		$temp_hash{PROJECT}{$query{$fpa_id}{PROJECT}[$i]} = 1;
+		$temp_hash{COMPONENT_ID}{$query{$fpa_id}{COMPONENT_ID}[$i]} = 1;
+		$temp_hash{TESS_ID}{$query{$fpa_id}{TESS_ID}[$i]} = 1;
 	    }
 	    if (scalar(keys(%{ $temp_hash{STAGE} })) == 1) {
@@ -214,4 +220,31 @@
 		exit_with_failure(21,"Too many MJD-OBS specified");
 	    }
+	    # add non-error cases/options as well 
+	    if (scalar(keys(%{ $temp_hash{PROJECT} })) == 1) {
+                if ( (keys(%{ $temp_hash{PROJECT} }))[0] ne 'Not_Set') {
+                    $imagedb = (keys(%{ $temp_hash{PROJECT} }))[0];
+                    $project = resolve_project($ipprc,$imagedb,$dbname,$dbserver);
+                    $imagedb = $project->{dbname};
+                    if (!$imagedb) {
+                        my_die("failed to find imagedb for project: $project", $PS_EXIT_CONFIG_ERROR);
+                    }
+                }
+	    }
+            if (scalar(keys(%{ $temp_hash{TESS_ID} })) == 1) {
+                if ( (keys(%{ $temp_hash{TESS_ID} }))[0] ne 'Not_Set') {                
+                    $tess_id = (keys(%{ $temp_hash{TESS_ID} }))[0];
+                }
+		else {
+		    $tess_id = undef;
+                }
+            }
+            if (scalar(keys(%{ $temp_hash{COMPONENT_ID} })) == 1) {
+                if ( (keys(%{ $temp_hash{COMPONENT_ID} }))[0] ne 'Not_Set') { 
+                    $component_id = (keys(%{ $temp_hash{COMPONENT_ID} }))[0];
+                }
+		else {
+		    $component_id = undef;
+                }
+            }
 	}
 
@@ -255,4 +288,5 @@
 
 	# Determine the query style for this fpa_id
+	# fix remove g  for gpc2
 	if ($fpa_id =~ /o.*g.*o/) {
 	    $query_style = 'byexp';
@@ -287,15 +321,24 @@
             $req_filter = $filter . '%';
         }
-	
+	# set defqults if not_set
+#        if ($imagedb eq 'Not_Set') {
+#            $imagedb = 'gpc1';
+#        }
+#        if ($component_id eq 'Not_Set') {
+#            $component_id = undef;
+#        }
+#        if ($tess_id eq 'Not_Set') {
+#            $tess_id = undef;
+#        }
+
 	# 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,
+					  $fpa_id,$tess_id,$component_id,
 					  $option_mask,$need_magic,
 					  $mjd_min,$mjd_max,$req_filter,undef,$verbose);  
 	
 	foreach my $this_image_ref (@{ $pstamp_images_ref }) {
-
             # loop over the rows that this component matched
             foreach my $valid_index (@{ $this_image_ref->{row_index} }) {
@@ -308,5 +351,4 @@
                 $query{$fpa_id}{NEED_MAGIC}[$valid_index] = $need_magic;
                 $query{$fpa_id}{BAD_COMPONENT}[$valid_index] = 0;
-                
                 if (exists($this_image_ref->{astrom})) {
                     $query{$fpa_id}{CATALOG}[$valid_index] = $this_image_ref->{astrom};
