Index: trunk/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 16974)
+++ trunk/pstamp/scripts/pstamp_webrequest.pl	(revision 18233)
@@ -11,5 +11,5 @@
 # the selected "input" uris are listed on stdout.
 #
-# Note: Despite the name there nothing really web specific about this program.
+# Note: Despite the name there nothing particularly web specific about this program.
 #
 ###
@@ -18,13 +18,23 @@
 use strict;
 
-my $verbosity = 0;
+use Getopt::Long qw( GetOptions );
+use Sys::Hostname;
 
-use Sys::Hostname;
 my $host = hostname();
+my $verbose = 0;
+my $dbname;
 
-if ($verbosity) {
+GetOptions(
+    'verbose'   =>  \$verbose,
+    'dbname=s'  =>  \$dbname,
+);
+
+
+
+if ($verbose) {
     print "\n\n";
     print "Starting script $0 on $host\n\n";
 }
+
 
 use IPC::Cmd 0.36 qw( can_run run );
@@ -65,9 +75,10 @@
 
 my $cur_dir = getcwd();
-my $request_file = "$cur_dir/request_file.$$.fits";
+my $request_name = "web" . get_webreq_num();
+my $request_file = "$cur_dir/$request_name.fits";
 {
-    my $command = "$pstamprequest $request_file @ARGV";
+    my $command = "$pstamprequest -request_name $request_name $request_file @ARGV";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbosity);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
         print STDERR @$stderr_buf;
@@ -82,6 +93,7 @@
     ###
     my $command = "$pstampparse $request_file";
+    $command .= " -dbname $dbname" if $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbosity);
+        run(command => $command, verbose => $verbose);
 
     if ($success) {
@@ -98,7 +110,8 @@
 {
 
-    my $command = "$pstamptool -addreq -uri $request_file -out_fileset \'pstampresults/web\$REQ_ID\'";
+    my $command = "$pstamptool -addreq -uri $request_file -out_fileset \'pstampresults/$request_name'";
+    $command .= " -dbname $dbname" if $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbosity);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
         print STDERR @$stderr_buf;
@@ -111,2 +124,30 @@
 
 exit 0;
+
+# Temporary hack
+# webrequest number is stored in a file in the current directory
+#
+sub get_webreq_num
+{
+    my $filename = "./webreq_num.txt";
+    if (! open IN, "+< $filename" ) {
+        my $initial_num = 1;
+        open IN, "> $filename" or die "can't open request $filename";
+        print IN "$initial_num\n" or die "failed to initialize $filename";
+        close IN;
+        return $initial_num;
+    }
+
+    my $webreq_num = <IN>;
+    chomp $webreq_num;
+
+    print STDERR "$webreq_num\n";
+
+    my $next = $webreq_num + 1;
+    truncate IN, 0;
+    seek IN, 0, 0;
+    print IN "$next\n";
+
+    close IN;
+    return $webreq_num;
+}
