Index: /trunk/pstamp/scripts/pstamp_insert_request.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_insert_request.pl	(revision 29172)
+++ /trunk/pstamp/scripts/pstamp_insert_request.pl	(revision 29173)
@@ -44,5 +44,5 @@
 
 my $pstamptool = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
-my $pstampdump = can_run('pstampdump')  or (warn "Can't find pstampdump"  and $missing_tools = 1);
+my $fields = can_run('fields')  or (warn "Can't find fields"  and $missing_tools = 1);
 
 if ($missing_tools) {
@@ -53,19 +53,25 @@
 my ($extname, $extver, $req_name);
 {
-    my $command = "$pstampdump -headeronly $tmp_req_file";
+    # get the header keywords of interest.
+    # Note that if it's a pstamp request then REQ_NAME should be defined.
+    # if it's a detectability query it will not have a REQ_NAME but will have a QUERY_ID
+    my $command = "echo $tmp_req_file | $fields -x 0 EXTNAME EXTVER REQ_NAME QUERY_ID";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
+if (0) {
+    # stoopid fields doesn't set exit status to zero when it works
     unless ($success) {
         print STDERR @$stderr_buf;
         exit $error_code >> 8;
     }
+}
     my $output = join "", @$stdout_buf;
-    ($extname, $extver, $req_name) = split " ", $output;
-    if ($extname and ($extname ne "PS1_PS_REQUEST")) {
+    (undef, $extname, $extver, $req_name) = split " ", $output;
+    if (!$extname or ! (($extname eq "PS1_PS_REQUEST") or ($extname eq "MOPS_DETECTABILITY_QUERY"))) {
         print STDERR "invalid request file\n";
         exit $PS_EXIT_DATA_ERROR;
     }
     if (!defined $req_name) {
-        print STDERR "invalid request file no REQ_NAME\n";
+        print STDERR "invalid request file no REQ_NAME or QUERY_ID\n";
         exit $PS_EXIT_DATA_ERROR;
     }
@@ -91,6 +97,5 @@
 my $req_id = 0;
 {
-
-    my $command = "$pstamptool -addreq -name $req_name -uri $req_file -ds_id 0";
+    my $command = "$pstamptool -addreq -uri $req_file -ds_id 0 -name $req_name";
     $command .= " -dbname $dbname" if $dbname;
     $command .= " -dbserver $dbserver" if $dbserver;
