Index: branches/pap/pstamp/scripts/detectability_respond.pl
===================================================================
--- branches/pap/pstamp/scripts/detectability_respond.pl	(revision 28195)
+++ branches/pap/pstamp/scripts/detectability_respond.pl	(revision 28484)
@@ -226,4 +226,5 @@
 my @psphot_Qfact= ();
 my @psphot_flux = ();
+my @psphot_error = ();
 
 foreach my $k (keys %image_list_hash) {
@@ -231,5 +232,5 @@
 	my $cmf = "$image_list_hash{$k}{OUTROOT}.$image_list_hash{$k}{CLASS_ID}.cmf";
 	
-	my ($tmp_Npix,$tmp_Qfact,$tmp_flux) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE});
+	my ($tmp_Npix,$tmp_Qfact,$tmp_flux,$tmp_flux_error) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE});
 	
 	push @rownums,        @{ $image_list_hash{$k}{ROWNUM} };
@@ -238,4 +239,5 @@
 	push @psphot_Qfact,   @{ $tmp_Qfact };
 	push @psphot_flux,    @{ $tmp_flux };
+	push @psphot_error,   @{ $tmp_flux_error };
     }
     else {
@@ -245,4 +247,5 @@
 	push @psphot_Qfact,   (map { 0.0 }  @{ $image_list_hash{$k}{ROWNUM} });
 	push @psphot_flux,    (map { 0.0 }  @{ $image_list_hash{$k}{ROWNUM} });
+	push @psphot_error,    (map { 0.0 }  @{ $image_list_hash{$k}{ROWNUM} });
     }	
 }
@@ -252,5 +255,5 @@
 		    $query{HEADER}{MJD_OBS}[0],$query{HEADER}{filter}[0],
 		    $query{HEADER}{obscode}[0],
-		    \@rownums, \@out_errors, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux);
+		    \@rownums, \@out_errors, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux, \@psphot_error);
 # print "Wrote response file $output\n";
 #
@@ -406,4 +409,5 @@
     my @tmp_Qfact = ();
     my @tmp_flux = ();
+    my @tmp_flux_err = ();
 
     my ($detect_F_col,$detect_N_col,$detect_flux_col,$detect_mag_col) = (-1, -1, -1, -1);
@@ -428,4 +432,5 @@
 	    { name => 'PSF_NPIX', type => '1J', writetype => TLONG },
 	    { name => 'PSF_INST_MAG', type => '1E', writetype => TDOUBLE },
+	    { name => 'PSF_INST_MAG_SIG', type => '1E', writetype => TDOUBLE },
 	    ];
     }
@@ -435,4 +440,5 @@
 	    { name => 'PSF_NPIX', type => '1J', writetype => TLONG },
 	    { name => 'PSF_INST_FLUX', type => '1E', writetype => TDOUBLE },
+	    { name => 'PSF_INST_FLUX_SIG', type => '1E', writetype => TDOUBLE },
 	    ];
     }
@@ -450,4 +456,5 @@
     $inFits->get_num_rows($numRows, $status) and check_fitsio($status);
 
+    my $correct_error = 0;
     foreach my $col (@$column_defs) {
 	my ($col_num,$col_type,$col_data);
@@ -469,10 +476,22 @@
 	    @tmp_flux = map { $_ = 10**(-0.4 * $_) } @{ $col_data };
 	}
+	elsif ($col->{name} eq 'PSF_INST_MAG_SIG') {
+	    @tmp_flux_err = map { $_ = $_ / (2.5 * log10(exp(1))) } @{ $col_data };
+	    $correct_error = 1;
+	}
 	elsif ($col->{name} eq 'PSF_INST_FLUX') {
 	    @tmp_flux = @{ $col_data };
 	}
+	elsif ($col->{name} eq 'PSF_INST_FLUX_SIG') {
+	    @tmp_flux_err = @{ $col_data };
+	}
+    }
+    if ($correct_error) {
+	for (my $c = 0; $c <= $#tmp_flux_err; $c++) {
+	    $tmp_flux_err[$c] = $tmp_flux_err[$c] * $tmp_flux[$c];
+	}
     }
     $inFits->close_file( $status ) and check_fitsio($status);    
-    return(\@tmp_Npix, \@tmp_Qfact, \@tmp_flux);
+    return(\@tmp_Npix, \@tmp_Qfact, \@tmp_flux, \@tmp_flux_err);
 }
 
@@ -490,4 +509,5 @@
     my $psphot_Qfact_ref = shift;
     my $psphot_flux_ref = shift;
+    my $psphot_error_ref = shift;
     my $status = 0;
 
@@ -504,4 +524,6 @@
 	# flux of the target source
 	{ name => 'TARGET_FLUX', type => 'D', writetype => TDOUBLE },
+	# error in the flux of the target source
+	{ name => 'TARGET_FLUX_SIG', type => 'D', writetype => TDOUBLE },
 	];
     
@@ -543,6 +565,10 @@
 	push @{$colData{'DETECT_F'}},    ${ $psphot_Qfact_ref }[$i];
 	push @{$colData{'TARGET_FLUX'}}, ${ $psphot_flux_ref }[$i];
+	push @{$colData{'TARGET_FLUX_SIG'}}, ${ $psphot_error_ref }[$i];
 	unless (defined(${ $colData{'TARGET_FLUX'}}[-1])) {
 	    $colData{'TARGET_FLUX'}[-1] = 0.0;
+	}
+	unless (defined(${ $colData{'TARGET_FLUX_SIG'}}[-1])) {
+	    $colData{'TARGET_FLUX_SIG'}[-1] = 0.0;
 	}
     }
Index: branches/pap/pstamp/scripts/pstamp_finish.pl
===================================================================
--- branches/pap/pstamp/scripts/pstamp_finish.pl	(revision 28195)
+++ branches/pap/pstamp/scripts/pstamp_finish.pl	(revision 28484)
@@ -76,5 +76,5 @@
 if ($product eq "NULL") {
     # nothing more to do
-    stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
+    my_die("product is NULL!", $req_id, $PS_EXIT_PROG_ERROR);
 }
 
@@ -92,19 +92,14 @@
 
         if (!mkdir $outdir) {
-            print STDERR "cannot create output directory $outdir";
-            stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
+            my_die("cannot create output directory $outdir",$req_id, $PS_EXIT_UNKNOWN_ERROR);
         }
 
 
     } elsif (! -d $outdir ) {
-        # XXX TODO: fault the request so we pstamp_finish doesn't keep trying to process the
-        # request
-        print STDERR "output directory $outdir exists but is not a directory";
-        stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
+        my_die("output directory $outdir exists but is not a directory", $req_id, $PS_EXIT_UNKNOWN_ERROR);
     }
 
     if (! -e $req_file ) {
-        print STDERR "request file $req_file is missing\n";
-        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
+        my_die("request file $req_file is missing", $req_id, $PS_EXIT_CONFIG_ERROR);
     }
 
@@ -115,6 +110,5 @@
         # Since a request got queued, the request file must have been readable at some
         # point 
-        print STDERR "failed to read request_file $req_file" ;
-        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
+        my_die("failed to read request file $req_file", $req_id, $PS_EXIT_CONFIG_ERROR);
     }
 
@@ -151,15 +145,7 @@
         my $output = join "", @$stdout_buf;
         if (!$output) {
-            if ($verbose) {
-                print STDERR "Request $req_id produced no jobs.\n"
-            }
             # This should not happen. A fake job should have been entered
-            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
+            my_die("Request $req_id produced no jobs", $req_id, $PS_EXIT_PROG_ERROR);
         } else {
-if (0) {
-            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
-
-            my $jobs = parse_md_list($metadata);
-}
             my $jobs = parse_md_fast($mdcParser, $output);
 
@@ -181,5 +167,5 @@
             # this request had a duplicate request name yet the parser didn't give
             # it an "ERROR style name.
-            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
+            my_die("duplicate request not given a request name", $req_id, $PS_EXIT_PROG_ERROR);
         }
         my ($row, $req_info, $project) = get_request_info($rows, $rownum);
@@ -187,9 +173,7 @@
         my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
         my $image_db = $proj_hash->{dbname};
-        if (!$image_db) {
-            carp("failed to find imagedb for project: $project");
-            if (!$fault) {
-                stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
-            }
+        if (!$image_db and !$fault) {
+            # if project isn't resolvable, the paser should have faulted this job
+            my_die("failed to find imagedb for project $project", $req_id, $PS_EXIT_CONFIG_ERROR);
         }
 
@@ -273,6 +257,6 @@
                 run(command => $command, verbose => $verbose);
             unless ($success) {
-                print STDERR "Unable to perform $command error code: $error_code\n";
                 $request_fault = $error_code >> 8;
+                my_die("Unable to perform $command error code: $error_code", $req_id, $request_fault);
             }
         }
@@ -282,19 +266,15 @@
         my $command = "$dsreg --list $reglist_name --add $fileset --product $product --type PSRESULTS";
         $command .= " --link --datapath $outdir --ps0 $req_id";
-# XXX: let dsreg and config handle resolving dbname and dbserver
-#        $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");
-            print STDERR "Unable to perform $command error code: $error_code\n";
             $request_fault = $error_code >> 8;
-            # fall through to stop the request
+            my_die("Unable to perform $command error code: $error_code\n", $req_id, $request_fault);
         }
     }
     # set the request's state to stop
     {
-        my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop -set_fault $request_fault";
+        my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop";
         $command   .= " -dbname $dbname" if $dbname;
         $command   .= " -dbserver $dbserver" if $dbserver;
@@ -308,9 +288,12 @@
 }
 
-sub stop_request_and_exit {
+sub my_die {
+    my $msg = shift;
     my $req_id = shift;
     my $fault  = shift;
 
-    my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop -set_fault $fault";
+    carp($msg);
+
+    my $command = "$pstamptool -updatereq -req_id $req_id -set_fault $fault";
     $command   .= " -dbname $dbname" if $dbname;
     $command   .= " -dbserver $dbserver" if $dbserver;
@@ -445,9 +428,4 @@
                 return undef;
             }
-if (0) {
-            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
-
-            my $exposures = parse_md_list($metadata);
-}
             my $exposures = parse_md_fast($mdcParser, $output);
             my $numExp = @$exposures;
Index: branches/pap/pstamp/scripts/pstamp_parser_run.pl
===================================================================
--- branches/pap/pstamp/scripts/pstamp_parser_run.pl	(revision 28195)
+++ branches/pap/pstamp/scripts/pstamp_parser_run.pl	(revision 28484)
@@ -198,5 +198,5 @@
 $parse_cmd .= " --verbose" if $verbose;
 
-my $newState = "run";
+my $newState;
 my $fault;
 {
@@ -224,7 +224,8 @@
     }
 
-    unless ($success) {
+    if ($success) {
+        $newState = 'run';
+    } else {
         $fault = $error_code >> 8;
-#        $newState = "stop";
     }
 }
@@ -234,5 +235,6 @@
 #
 {
-    my $command = "$pstamptool -updatereq -req_id $req_id -set_state $newState";
+    my $command = "$pstamptool -updatereq -req_id $req_id";
+    $command   .= " -set_state $newState" if $newState;
     $command   .= " -set_outdir $outdir";
     $command   .= " -set_reqType $reqType" if $reqType;
Index: branches/pap/pstamp/scripts/pstampparse.pl
===================================================================
--- branches/pap/pstamp/scripts/pstampparse.pl	(revision 28195)
+++ branches/pap/pstamp/scripts/pstampparse.pl	(revision 28484)
@@ -361,5 +361,4 @@
     my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     if (!$proj_hash) {
-        print STDERR "project $project not found\n" ;
         foreach $row (@$rowList) {
             insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PRODUCT);
Index: branches/pap/pstamp/src/ppstampMakeStamp.c
===================================================================
--- branches/pap/pstamp/src/ppstampMakeStamp.c	(revision 28195)
+++ branches/pap/pstamp/src/ppstampMakeStamp.c	(revision 28484)
@@ -688,5 +688,10 @@
         }
     }
-    psU32 maskMask = ~convPoor;
+    psU32 suspect = psMetadataLookupU32(&status, masks, "SUSPECT");
+    if (!status) {
+        psError(PM_ERR_CONFIG, false, "failed to lookup mask value for SUSPECT in recipes\n");
+        return false;
+    }
+    psU32 maskMask = ~(convPoor | suspect);
 
     double exciseValue;
Index: branches/pap/pstamp/src/pstamp.h
===================================================================
--- branches/pap/pstamp/src/pstamp.h	(revision 28195)
+++ branches/pap/pstamp/src/pstamp.h	(revision 28484)
@@ -33,6 +33,8 @@
 #define PSTAMP_SELECT_BACKMDL   32
 #define PSTAMP_SELECT_INVERSE 1024
+#define PSTAMP_SELECT_UNCONV  2048
+#define PSTAMP_USE_IMFILE_ID 16384
 
-#define PSTAMP_WAIT_FOR_UPDATE 2048
+#define PSTAMP_NO_WAIT_FOR_UPDATE 32768
 
 #define PSTAMP_CENTER_IN_PIXELS 1
