Index: /trunk/pstamp/scripts/Makefile.am
===================================================================
--- /trunk/pstamp/scripts/Makefile.am	(revision 18586)
+++ /trunk/pstamp/scripts/Makefile.am	(revision 18587)
@@ -15,5 +15,10 @@
 	pstamp_webrequest.pl \
         pstamp_get_image_job.pl \
-        dqueryparse.pl
+	request_finish.pl \
+	detect_query_read \
+	detect_response_create \
+        dquery_finish.pl \
+        dqueryparse.pl \
+	fakedresponse.pl
 
 install_SCRIPTS = $(install_files)
Index: /trunk/pstamp/scripts/detect_query_read
===================================================================
--- /trunk/pstamp/scripts/detect_query_read	(revision 18587)
+++ /trunk/pstamp/scripts/detect_query_read	(revision 18587)
@@ -0,0 +1,195 @@
+#!/usr/bin/env perl
+
+# Read and parse a fits table containing a MOPS_DETECTABILITY_QUERY Extension
+# and optionally print out the contents
+
+# by default prints out the keywords in the exension header followed by the rows of the table
+# with labels
+# -l omits the labels
+# -h omits the header
+# -r omits the rows
+# so -lhr will print nothing
+
+use warnings;
+use strict;
+
+use Astro::FITS::CFITSIO qw( :constants );
+Astro::FITS::CFITSIO::PerlyUnpacking(1);
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+use Math::Trig;
+use Data::Dumper;
+
+use constant EXTNAME => 'MOPS_DETECTABILITY_QUERY'; # Extension name for table
+
+my $no_print_label  = 0;    # omit the labels
+my $no_print_header = 0;    # omit the header keywords
+my $no_print_rows   = 0;    # omit the rows
+
+
+my ( $input,			# Name of input text file
+     $output,			# Name of output table
+     $save_temps,		# Save temporary files?
+     );
+
+GetOptions(
+	   'input|i=s'    => \$input,
+	   'output|o=s'   => \$output,
+           'nolabel|l'    => \$no_print_label,
+           'noheader|h'   => \$no_print_header,
+           'norows|r'     => \$no_print_rows
+) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --input",
+           -exitval => 3) unless defined $input;
+
+if ($output && ($output ne "-")) {
+    die "cannot open $output for output\n" unless open OUTFILE, ">$output";
+    select OUTFILE;
+}
+
+my $status = 0;
+
+# The required keywords
+my $header = {
+        'QUERY_ID' => { name => 'QUERY_ID', 
+                        writetype => TSTRING, 
+                        comment => 'MOPS Query ID for this batch query',
+                        value => undef
+                      },
+        'FPA_ID'   => { name => 'FPA_ID', 
+                        writetype => TSTRING, 
+                        comment => 'orginal FPA_ID used at ingest',
+                        value => undef
+                      }, 
+        'MJD_OBS'  => { name => 'MJD-OBS', 
+                        writetype => TDOUBLE, 
+                        comment => 'starting time of the exposure, MJD',
+                        value => undef
+                      },
+        'FILTER'   => { name => 'FILTER', 
+                        writetype => TSTRING, 
+                        comment => 'effective filter use for the exposure',
+                        value => undef
+                      },
+        'OBSCODE'  => { name => 'OBSCODE', 
+                        writetype => TSTRING, 
+                        comment => 'site identifier (MPC observatory code)',
+                        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 );
+
+# Specification of columns
+my $column_defs = [ 
+        # matching rownum from detectability original request
+        { name => 'ROWNUM',   type => '20A', writetype => TSTRING }, 
+        # coordinate at start of exposure, in degrees
+        { name => 'RA1_DEG',  type => 'D',   writetype => TDOUBLE },
+        # coordinate at start of exposure, in degrees
+        { name => 'DEC1_DEG', type => 'D',   writetype => TDOUBLE },
+        # coordinate at end of exposure, in degrees
+        { name => 'RA2_DEG',  type => 'D',   writetype => TDOUBLE },
+        # coordinate at end of exposure, in degrees
+        { name => 'DEC2_DEG', type => 'D',   writetype => TDOUBLE },
+        # apparent magnitude
+        { name => 'MAG',      type => 'D',   writetype => TDOUBLE },
+];
+
+# Parse the list of columns
+my @colNames;			# Names of columns
+my @colTypes;			# Types of columns
+my @colWriteType;               # type to use to write
+my %colData;			# Data for each column referenced by name
+foreach my $colSpec ( @$column_defs) {
+    push @colNames, $colSpec->{name};
+    push @colTypes, $colSpec->{type};
+    push @colWriteType, $colSpec->{writetype};
+}
+
+# Read the input file
+
+my $inFits = Astro::FITS::CFITSIO::open_file( $input, READONLY, $status ); # FITS file handle
+check_fitsio($status);
+
+$inFits->movnam_hdu(BINARY_TBL, EXTNAME, 0, $status) and check_fitsio($status);
+
+my $inHeader = $inFits->read_header(); # Header for input
+
+my $numRows;			# Number of rows in table
+$inFits->get_num_rows($numRows, $status) and check_fitsio($status);
+
+foreach my $col (@$column_defs) {
+    my ($col_num, $col_type, $col_data);
+
+    $inFits->get_colnum(0, $col->{name}, $col_num, $status) and check_fitsio($status);
+    $inFits->get_coltype($col_num, $col_type, undef, undef, $status) and check_fitsio($status);
+    $inFits->read_col($col_type, $col_num, 1, 1, $numRows, 0, $col_data, undef, $status)
+                                                                    and check_fitsio($status);
+    $colData{$col->{name}} = $col_data;
+}
+
+# Now produce the output
+
+if (!$no_print_header) {
+    my $label;
+    my $data;
+    # I don't do this because I want the keys to be printed in a particular order
+    #foreach my $key (keys %$header) {
+    foreach my $key (@key_array) {
+        my $name = $header->{$key}->{name};
+        my $value = $inHeader->{$name};
+        # get rid of quotes and whitespace
+        $value =~ s/\'//g;
+        if (defined $value) {
+            #print "$key\t\t\t$value\n";
+            $label .= sprintf "%-12s ", $key;
+            $data  .= sprintf "%-12s ", $value;
+        } else {
+            die "keyword $key not found in $input\n";
+        }
+    }
+    print "# " . $label . "\n" unless $no_print_label;
+    print $data  . "\n";
+}
+
+if (!$no_print_rows) {
+    if (!$no_print_label) {
+        print "# ";
+        foreach my $col (@$column_defs) {
+            printf "%-12s ", $col->{name};
+        }
+        print "\n";
+    }
+
+    for (my $i = 0; $i < $numRows; $i++) {
+        foreach my $col (@$column_defs) {
+            printf "%-12s ", $colData{$col->{name}}->[$i];
+        #foreach my $aref (@col_arrays) {
+            #printf "%-12s ", $aref->[$i];
+        }
+        print "\n";
+    }
+}
+
+exit 0;
+
+### Pau.
+
+# From Astro::FITS::CFITSIO demo
+sub check_fitsio
+{
+    my $status = shift;		# Status of FITSIO calls
+
+    if ($status != 0) {
+	my $msg;		# Message to output
+	Astro::FITS::CFITSIO::fits_get_errstatus( $status , $msg );
+	die "CFITSIO error: $msg\n";
+    }
+}
+
+__END__
Index: /trunk/pstamp/scripts/detect_response_create
===================================================================
--- /trunk/pstamp/scripts/detect_response_create	(revision 18587)
+++ /trunk/pstamp/scripts/detect_response_create	(revision 18587)
@@ -0,0 +1,176 @@
+#!/usr/bin/env perl
+
+# program to create a simulated MOPS_DETECTABILITY_RESPONSE file
+# based on text format input file
+
+use warnings;
+use strict;
+
+use Astro::FITS::CFITSIO qw( :constants );
+Astro::FITS::CFITSIO::PerlyUnpacking(1);
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+use Math::Trig;
+use Data::Dumper;
+
+use constant EXTNAME => 'MOPS_DETECTABILITY_RESPONSE'; # Extension name for output table
+use constant EXTVER =>  1;
+use constant OBSERVATORY_CODE => 566; # IAU Observatory Code
+
+my ( $input,			# Name of input Detectabilty Query table
+     $output,			# Name of output table
+     $save_temps,		# Save temporary files?
+     );
+
+GetOptions(
+	   'input|i=s'    => \$input,
+	   'output|o=s'   => \$output,
+	   'save-temps' => \$save_temps,
+) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage( -msg => "Required options: --input --output",
+           -exitval => 3)
+    unless defined $input 
+    and defined $output;
+
+my $status = 0;
+
+# Specification of columns to write
+my $columns = [ 
+        # matching rownum from detectability original request
+        { name => 'ROWNUM',   type => '20A', writetype => TSTRING }, 
+
+        # number of pixels used in hypothetical PSF for the query detection
+        { name => 'DETECT_N', type => 'V',   writetype => TULONG },
+
+        # detectibility, indicating the fraction of PSF pixels detetable by IPP
+        { name => 'DETECT_F', type => 'D',   writetype => TDOUBLE },
+            ];
+
+# Header translation table
+my $headers = {
+    'QUERY_ID' => { name => 'QUERY_ID', type => TSTRING, 
+                        comment => 'MOPS Query ID for this batch query' },
+    'FPA_ID' => { name => 'FPA_ID',   type => TSTRING, 
+                        comment => 'original FPA_ID used at ingest' },
+	    };
+
+# Parse the list of columns
+my @colNames;			# Names of columns
+my @colTypes;			# Types of columns
+my %colData;			# Data for each column
+my @colWriteType;                 # type to use to write
+foreach my $colSpec ( @$columns) {
+    push @colNames, $colSpec->{name};
+    push @colTypes, $colSpec->{type};
+    push @colWriteType, $colSpec->{writetype};
+    $colData{$colSpec->{name}} = [];
+}
+
+my $in;
+if ($input eq "-") {
+    $in = *STDIN;
+} else {
+    die "cannot open input file $input" unless open $in, "<$input";
+}
+
+my $numRows;
+my $inHeader = { };
+
+read_input($in);
+
+
+# Write the output
+unlink "$output" if -e "$output";
+# Output file handle
+my $outFits = Astro::FITS::CFITSIO::create_file( $output, $status );
+check_fitsio( $status );
+
+$outFits->create_img( 16, 0, undef, $status );
+check_fitsio( $status );
+
+# Start the table
+$outFits->create_tbl( BINARY_TBL(), $numRows, scalar @colNames, \@colNames, \@colTypes, undef, EXTNAME,
+		      $status );
+check_fitsio( $status );
+
+# TODO: get the extension version number from somewhere common
+$outFits->write_key( TINT, 'EXTVER', EXTVER, 'Version of this Extension', $status );
+check_fitsio( $status );
+
+# Write the Extension keywords
+foreach my $keyword ( keys %$headers ) {
+    my $value = $inHeader->{$keyword}->{value}; # Header keyword value
+    unless (defined $value) {
+	print "Can't find header keyword $keyword\n";
+	next;
+    }
+    $value =~ s/\'//g;
+    my $name    = $headers->{$keyword}->{name}; # New name
+    my $type    = $headers->{$keyword}->{type}; # Type
+    my $comment = $headers->{$keyword}->{comment}; # Comment
+    $outFits->write_key( $type, $name, $value, $comment, $status );
+    check_fitsio( $status );
+}
+
+
+for (my $i = 0; $i < scalar @colNames; $i++) {
+    my $colName = $colNames[$i];# Column name
+    my $writeType = $colWriteType[$i];
+    $outFits->write_col( $writeType, $i + 1, 1, 1, $numRows, $colData{$colName}, $status );
+    check_fitsio( $status );
+}
+
+$outFits->close_file( $status );
+
+### Pau.
+
+
+# From Astro::FITS::CFITSIO demo
+sub check_fitsio
+{
+    my $status = shift;		# Status of FITSIO calls
+
+    if ($status != 0) {
+	my $msg;		# Message to output
+	Astro::FITS::CFITSIO::fits_get_errstatus( $status , $msg );
+	die "CFITSIO error: $msg\n";
+    }
+}
+
+sub read_input
+{
+    my $inh = shift;
+    my $line;
+    # read data for header
+    while ($line = <$inh>) {
+        next if ($line =~ /^#/);    # skip comment lines
+        chomp $line;
+        ($inHeader->{QUERY_ID}->{value}, $inHeader->{FPA_ID}->{value}, $inHeader->{MJD_OBS}->{value}, 
+         $inHeader->{FILTER}->{value}, $inHeader->{OBSCODE}->{value}) 
+                = split " ", $line;
+        last;
+    }
+    die "failed to read valid header words from $input" 
+        unless defined($inHeader->{QUERY_ID}->{value}) &&
+           ($inHeader->{FPA_ID}->{value}) &&
+           ($inHeader->{MJD_OBS}->{value}) && ($inHeader->{FILTER}->{value}) &&
+           ($inHeader->{OBSCODE}->{value}) ;
+
+
+    $numRows = 0;
+    while ($line = <$inh> ) {
+        next if ($line =~ /^#/);    # skip comment lines
+        chomp $line;
+
+        my ($rownum, $npix, $flux) = split " ", $line;
+
+        push @{$colData{'ROWNUM'}},   $rownum;
+        push @{$colData{'DETECT_N'}}, $npix;
+        push @{$colData{'DETECT_F'}}, $flux;
+        $numRows++;
+    }
+}
+
+__END__
Index: /trunk/pstamp/scripts/dqueryparse.pl
===================================================================
--- /trunk/pstamp/scripts/dqueryparse.pl	(revision 18586)
+++ /trunk/pstamp/scripts/dqueryparse.pl	(revision 18587)
@@ -5,6 +5,4 @@
 # Note: this file is currently only a placeholder which creates a fake response file
 # and adds a completed job to the database
-#
-# TODO: split off the actual generation of the response file into a standalone program
 #
 
@@ -28,5 +26,5 @@
 		       );
 
-my ($uri, $out_dir, $mode, $req_id, $verbose, $save_temps);
+my ($req_file, $req_id, $out_dir, $product, $mode, $dbname, $verbose, $save_temps);
 
 #
@@ -35,25 +33,29 @@
 
 GetOptions(
-        'uri=s'           =>      \$uri,
+        'file=s'          =>      \$req_file,
+        'req_id=s'        =>      \$req_id,
         'out_dir=s'       =>      \$out_dir,
+        'product=s'       =>      \$product,
+        'mode=s'          =>      \$mode,
+        'dbname=s'        =>      \$dbname,
         'verbose'         =>      \$verbose,
-        'mode=s'          =>      \$mode,
-        'req_id=s'        =>      \$req_id,
         'save-temps'      =>      \$save_temps,
-        'verbose'         =>      \$verbose,
 ) or pod2usage(2);
 
 my $err = "";
 
-if (!$uri) {
-    $err .= "--uri is required\n";
+if (!$req_file) {
+    $err .= "--file is required\n";
+}
+if (!$req_id) {
+    $err .= "--req_id is required\n";
 }
 if (!$out_dir) {
     $err .="--out_dir is required\n";
 }
+if (!$product) {
+    $err .="--product is required\n";
+}
 
-if (!$req_id) {
-    $err .= "--req_id is required\n";
-}
 
 die $err if ($err);
@@ -62,4 +64,5 @@
 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools =1);
 my $fakedresponse = can_run('fakedresponse.pl') or (warn "Can't find fakedresponse.pl" and $missing_tools =1);
+my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools =1);
 
 if ($missing_tools) {
@@ -68,8 +71,38 @@
 }
 
+# get the query id and check the extname and version from the header
+my $fields_output;
+{
+    my $command = "echo $req_file | $fields -x 0 EXTNAME EXTVER QUERY_ID";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    
+#   fields doesn't return zero when it succeeds
+#    unless ($success) {
+#        print STDERR @$stderr_buf;
+#    }
+    $fields_output = join "", @$stdout_buf;
+}
+my (undef, $extname, $extver, $req_name) = split " ", $fields_output;
+
+die "$req_file has EXTNAME $extname not MOPS_DETECTABILITY_QUERY table"
+                if $extname ne         "MOPS_DETECTABILITY_QUERY";
+die "$req_file does not have a QUERY_ID" if ! $req_name;
+die "$req_file is version $extver expecting 1" if $extver ne 1;
+
+$out_dir .= "/$req_name";
+if (! -e $out_dir ) {
+    mkdir $out_dir or die "cannot create output directory $out_dir";
+} elsif (! -d $out_dir ) {
+    die "output fileset directory $out_dir exists but is not a directory";
+}
+
+#
+# we don't parse the file here, pass it to fakedresponse it will create a response for each
+# row in the file
 my $response_file = "$out_dir/response.fits";
 my $fault;
 {
-    my $command = "$fakedresponse --input $uri --output $response_file --workdir $out_dir";
+    my $command = "$fakedresponse --input $req_file --output $response_file --workdir $out_dir";
     $command .= " --save-temps" if $save_temps;
     $command .= " --verbose" if $verbose;
@@ -84,7 +117,10 @@
 
 my $job_id;
+my $result;
 {
-    my $command = "$pstamptool -addjob -req_id $req_id -uri $uri -outputBase $out_dir -job_type detect_query";
-    $command .= " -state stop -fault $fault";
+    my $command = "$pstamptool -addjob -req_id $req_id -uri $req_file -outputBase $out_dir";
+    $command .= " -job_type detect_query -state stop -fault $fault";
+    $command .= " -rownum 1";
+    $command .= " -dbname $dbname" if $dbname;
 
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -101,17 +137,15 @@
 }
 
-exit $result;
+{
+    my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name -outProduct $product";
+    $command .= " -fault $result" if $result;
+    $command .= " -dbname $dbname" if $dbname;
 
-
-
-
-sub fake_dquery_response {
-    my $line = shift;
-    my ($rownum, $ra1, $dec1, $ra2, $dec2, $mag) = split " ", $line;
-
-    # todo perhaps think more about these values
-    my $n = rand(16);
-    my $f = rand(1);
-
-    return ($rownum, $n, $f);
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        die "$command failed";
+    }
 }
+ 
+exit 0;
Index: /trunk/pstamp/scripts/pstamp_finish.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_finish.pl	(revision 18586)
+++ /trunk/pstamp/scripts/pstamp_finish.pl	(revision 18587)
@@ -31,12 +31,14 @@
 
 
-my ( $dbname, $limit, $verbose, $save_temps );
+my ( $req_id, $req_name, $product, $dbname, $verbose, $save_temps );
 
 # the char to the right of the bar may be used as a single - alias for the longer name
 # for example --input and -i are equivalent
 GetOptions(
-	   'limit=s'    => \$limit,
+           'req_id=s'   => \$req_id,
+           'req_name=s' => \$req_name,
+           'product=s'  => \$product,
 	   'dbname=s'   => \$dbname,
-	   'verbose'  => \$verbose,
+	   'verbose'    => \$verbose,
 	   'save-temps' => \$save_temps,
 ) or pod2usage( 2 );
@@ -62,38 +64,5 @@
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
-my @requests;
 {
-    my $command = "$pstamptool -completedreq";
-    $command   .= " -limit $limit" if $limit;
-    $command   .= " -dbname $dbname" if $dbname;
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => $verbose);
-    unless ($success) {
-        die("Unable to perform $command error code: $error_code");
-    }
-    my $output = join "", @$stdout_buf;
-    if (!$output) {
-        if ($verbose) {
-            print STDERR "no completed requests pending\n"
-        }
-        exit 0;
-    }
-    my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
-
-    my $requests = parse_md_list($metadata);
-
-    @requests = @$requests
-}
-
-foreach my $req (@requests) {
-    my $req_id = $req->{req_id};
-
-    my $product = $req->{outProduct};
-    die "outProduct in request is null" if !$product;
-
-    my $req_name = $req->{name};
-    die "request name is null" if !$req_name;
-
-
     # set the output fileset's name to the request name.
     my $fileset = $req_name;
@@ -156,6 +125,4 @@
             # including those that produced no jobs.
             # for now add an entry for rownum 1 and a phony error code.
-            #
-            # possible fix: have pstampparse add a dummy job with state=stop and a fault code
             # we've included parse_results.txt to the fileset if it exists
             #
@@ -169,5 +136,5 @@
             my $jobs = parse_md_list($metadata);
 
-            @jobs = @$jobs
+            @jobs = @$jobs;
         }
     }
@@ -201,5 +168,6 @@
             }
         } else {
-            die "Unknown jobType: $job_type";
+            print STDERR "Unknown jobType: $job_type";
+            next;
         }
     }
@@ -235,5 +203,4 @@
     # set the request's state to stop
     {
-        
         my $command = "$pstamptool -processedreq -req_id $req_id -state stop -fault $request_fault";
         $command   .= " -dbname $dbname" if $dbname;
@@ -245,2 +212,16 @@
     }
 }
+sub stop_request {
+    my $req_id = shift;
+    my $fault  = shift;
+    my $dbname = shift;
+
+    my $command = "$pstamptool -processedreq -req_id $req_id -state stop -fault $fault";
+    $command   .= " -dbname $dbname" if $dbname;
+
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        die("Unable to perform $command error code: $error_code");
+    }
+}
Index: /trunk/pstamp/scripts/pstamp_parser_run.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_parser_run.pl	(revision 18586)
+++ /trunk/pstamp/scripts/pstamp_parser_run.pl	(revision 18587)
@@ -121,5 +121,5 @@
 
 my $new_uri;
-if ($ds_id) {
+if ($ds_id && ($uri =~ /^http:/)) {
     {
         $new_uri = "$workdir/request.fits";
@@ -183,16 +183,28 @@
 if ($request_type eq "PS1_PS_REQUEST") {
     $reqType = 'pstamp';
-    $parse_cmd = $pstampparse . " --mode queue_job --req_id $req_id --product $product --out_dir $outProductDir --file $uri";
-    $parse_cmd .= " --dbname $dbname" if $dbname;
+    $parse_cmd = $pstampparse;
 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
     $reqType = 'dquery';
-    $parse_cmd = $dqueryparse  . " --mode queue_job --req_id $req_id --out_dir $outProductDir --uri $uri";
+    $parse_cmd = $dqueryparse;
 }
 
 if (!$parse_cmd) {
-    # XXX TODO mark the error state for the job and set it to stop
-    die "null request type found in $uri" if !$request_type;
-    die "unknown request type $request_type found in $uri";
-}
+    print STDERR "No EXTNAME found in $uri" if !$request_type;
+    print STDERR "Unknown request type $request_type found in $uri";
+
+    my $command = "$pstamptool -processedreq -req_id $req_id -state run";
+    $command   .= " -reqType unknown";
+    $command   .= " -fault $PS_EXIT_DATA_ERROR";
+    $command   .= " -dbname $dbname" if $dbname;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        die("Unable to perform $command error code: $error_code");
+    }
+    exit $PS_EXIT_DATA_ERROR;
+}
+
+$parse_cmd .= " --mode queue_job --req_id $req_id --product $product --out_dir $outProductDir --file $uri";
+$parse_cmd .= " --dbname $dbname" if $dbname;
 
 my $fault;
@@ -211,8 +223,9 @@
     if ($errbuf) {
         if (!open OUT, ">$error_file_name") {
-            die("unable to open parse_error file $error_file_name");
+            print STDERR ("unable to open parse_error file $error_file_name");
+        } else {
+            print OUT "$errbuf";
+            close(OUT);
         }
-        print OUT "$errbuf";
-        close(OUT);
         print STDERR $errbuf if $verbose;
     }
@@ -241,5 +254,5 @@
 # Note: We do not return $fault here. If there was a fatal error we've already exited.
 # If we got a fault it's due to bad input from the user we've set things up for this to be
-# handled by the pstamp.request.finish
+# handled by the task pstamp.request.finish
 
 exit 0;
Index: /trunk/pstamp/scripts/pstamp_revert_request.pl
===================================================================
--- /trunk/pstamp/scripts/pstamp_revert_request.pl	(revision 18586)
+++ /trunk/pstamp/scripts/pstamp_revert_request.pl	(revision 18587)
@@ -91,9 +91,5 @@
 my $fileset = $req_name;
 
-# Here we invoke the assumption that the output for the request is placed in the
-# fileset directory directly
-my $out_dir = "$outputDataStoreRoot/$product/$fileset";
-
-print STDERR "product: $product  REQ_NAME: $req_name $out_dir\n" if $verbose;
+print STDERR "product: $product  REQ_NAME: $req_name\n" if $verbose;
 
 if ($product and $fileset) {
Index: /trunk/pstamp/scripts/pstamp_runcommand.sh
===================================================================
--- /trunk/pstamp/scripts/pstamp_runcommand.sh	(revision 18586)
+++ /trunk/pstamp/scripts/pstamp_runcommand.sh	(revision 18587)
@@ -18,8 +18,7 @@
 # These variables need to be customized for a particular installation
 # XXX: why not pass these on on the command line or in the environment?
-export PSCONFDIR=/export/data0/bills/psconfig
+export PSCONFDIR=/home/panstarrs/bills/psconfig
 
-WORK_DIR=/export/data1/bills/pstamp/work
-CMD_DIR=/export/data0/bills/src/ipp/pstamp/scripts:/export/data0/bills/src/ipp/DataStoreServer/web/cgi
+WORK_DIR=/data/ipp004.0/pstamp-work
 
 #### END LOCAL_CONFIGURATION
Index: /trunk/pstamp/scripts/pstampparse.pl
===================================================================
--- /trunk/pstamp/scripts/pstampparse.pl	(revision 18586)
+++ /trunk/pstamp/scripts/pstampparse.pl	(revision 18587)
@@ -88,7 +88,8 @@
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
         run(command => $command, verbose => $verbose);
-    unless ($success) {
-        print STDERR @$stderr_buf;
-    }
+    # fields doesn't return zero when it succeeds
+    #unless ($success) {
+    #    print STDERR @$stderr_buf;
+    #}
     $fields_output = join "", @$stdout_buf;
 }
