Index: /trunk/ippScripts/scripts/ipp_mops_translate.pl
===================================================================
--- /trunk/ippScripts/scripts/ipp_mops_translate.pl	(revision 21200)
+++ /trunk/ippScripts/scripts/ipp_mops_translate.pl	(revision 21201)
@@ -25,4 +25,5 @@
      $extname,                  # Name of extension containing photometry
      $skycell,                  # Skycell file with WCS
+     $diff_image_id,            # difference image id
      $output,                   # Name of output file
      $save_temps,               # Save temporary files?
@@ -34,22 +35,25 @@
            'skycell=s'  => \$skycell,
            'output=s'   => \$output,
+           'diff_image_id=s' => \$diff_image_id,
            'save-temps' => \$save_temps,
 ) or pod2usage( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --input --extname --skycell --output",
+pod2usage( -msg => "Required options: --input --extname --skycell --diff_image_id --output",
            -exitval => 3)
     unless defined $input
     and defined $extname
     and defined $skycell
+    and defined $diff_image_id,
     and defined $output;
 
 # Specification of columns to write
 my $columns = [ { name => 'RA_DEG',   type => 'D' }, # Right ascension
+                { name => 'RA_SIG',   type => 'D' }, # Error in right ascension
                 { name => 'DEC_DEG',  type => 'D' }, # Declination
-                { name => 'RA_SIG',   type => 'D' }, # Error in right ascension
                 { name => 'DEC_SIG',  type => 'D' }, # Error in declination
                 { name => 'FLUX',     type => 'D' }, # Flux
                 { name => 'FLUX_SIG', type => 'D' }, # Error in flux
+                { name => 'STARPSF',  type => 'D' }, # probability that the PSF matches a starlike PSF
                 { name => 'ANG',      type => 'D' }, # Angle
                 { name => 'ANG_SIG',  type => 'D' }, # Error in angle
@@ -124,5 +128,6 @@
 
 # Read the input table
-my $inFits = Astro::FITS::CFITSIO::open_file( $input, READONLY, $status ); # FITS file handle
+my $inputResolved = $ipprc->file_resolve($input);
+my $inFits = Astro::FITS::CFITSIO::open_file( $inputResolved, READONLY, $status ); # FITS file handle
 my $inHeader = $inFits->read_header(); # Header for input
 check_fitsio($status);
@@ -131,18 +136,21 @@
 $inFits->get_num_rows($numRows, $status) and check_fitsio($status);
 
-my ($xCol, $yCol, $magCol);             # Column numbers for x and y
+my ($xCol, $yCol, $magCol, $ensCol);  # Column numbers for x and y
 $inFits->get_colnum(0, 'X_PSF', $xCol, $status) and check_fitsio($status);
 $inFits->get_colnum(0, 'Y_PSF', $yCol, $status) and check_fitsio($status);
 $inFits->get_colnum(0, 'PSF_INST_MAG', $magCol, $status) and check_fitsio($status);
-
-my ($xType, $yType, $magType);  # Column types
+$inFits->get_colnum(0, 'EXT_NSIGMA', $ensCol, $status) and check_fitsio($status);
+
+my ($xType, $yType, $magType, $ensType);  # Column types
 $inFits->get_coltype($xCol, $xType, undef, undef, $status) and check_fitsio($status);
 $inFits->get_coltype($yCol, $yType, undef, undef, $status) and check_fitsio($status);
 $inFits->get_coltype($magCol, $magType, undef, undef, $status) and check_fitsio($status);
-
-my ($x, $y, $mag);              # Sources arrays
+$inFits->get_coltype($ensCol, $ensType, undef, undef, $status) and check_fitsio($status);
+
+my ($x, $y, $mag, $ens);              # Sources arrays
 $inFits->read_col($xType, $xCol, 1, 1, $numRows, 0, $x, undef, $status) and check_fitsio($status);
 $inFits->read_col($yType, $yCol, 1, 1, $numRows, 0, $y, undef, $status) and check_fitsio($status);
 $inFits->read_col($magType, $magCol, 1, 1, $numRows, 0, $mag, undef, $status) and check_fitsio($status);
+$inFits->read_col($ensType, $ensCol, 1, 1, $numRows, 0, $ens, undef, $status) and check_fitsio($status);
 
 $inFits->close_file( $status );
@@ -173,10 +181,12 @@
     push @{$colData{'LEN'}}, 0.0;
     push @{$colData{'LEN_SIG'}}, 0.0;
+    push @{$colData{'STARPSF'}}, $$ens[$i];     # for now set this to the value of EXT_NSIGMA
 }
 
 
 # Write the output
-unlink "$output" if -e "$output";
-my $outFits = Astro::FITS::CFITSIO::create_file( $output, $status ); # Output file handle
+my $outputResolved = $ipprc->file_resolve($output, 1);
+unlink "$outputResolved";
+my $outFits = Astro::FITS::CFITSIO::create_file( $outputResolved, $status ); # Output file handle
 check_fitsio( $status );
 
@@ -201,4 +211,9 @@
 }
 
+# set DIFFIMID
+# XXX TODO: we could put the diff_image_id in the .cmf file and get it from there
+$outFits->write_key( TLONGLONG, 'DIFFIMID', $diff_image_id, 'Difference image identifier', $status);
+check_fitsio( $status );
+
 # Adjust the time from start to mid-point
 {
