Index: trunk/pstamp/scripts/detectability_respond.pl
===================================================================
--- trunk/pstamp/scripts/detectability_respond.pl	(revision 28229)
+++ trunk/pstamp/scripts/detectability_respond.pl	(revision 28262)
@@ -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;
 	}
     }
