Index: trunk/ippScripts/scripts/ipp_mops_translate.pl
===================================================================
--- trunk/ippScripts/scripts/ipp_mops_translate.pl	(revision 17943)
+++ trunk/ippScripts/scripts/ipp_mops_translate.pl	(revision 17945)
@@ -13,23 +13,23 @@
 use constant EXTNAME => 'MOPS_TRANSIENT_DETECTIONS'; # Extension name for output table
 use constant POSITION_ERROR => 0.2 / 3600; # Error in positions, degrees
-use constant ZERO_POINT => 25;	# Magnitude zero point
-use constant MAG_ERROR => 0.1;	# Error in magnitudes
+use constant ZERO_POINT => 25;  # Magnitude zero point
+use constant MAG_ERROR => 0.1;  # Error in magnitudes
 use constant OBSERVATORY_CODE => 566; # IAU Observatory Code
-use constant FAKE_LIMITING_MAG => 23.0;	# Fake limiting magnitude to report
+use constant FAKE_LIMITING_MAG => 23.0; # Fake limiting magnitude to report
 use constant FAKE_DETECTION_EFFICIENCY => 0.0; # Fake detection efficiency to report
 
-my ( $input,			# Name of input file with IPP photometry
-     $extname,			# Name of extension containing photometry
-     $skycell,			# Skycell file with WCS
-     $output,			# Name of output file
-     $save_temps,		# Save temporary files?
+my ( $input,                    # Name of input file with IPP photometry
+     $extname,                  # Name of extension containing photometry
+     $skycell,                  # Skycell file with WCS
+     $output,                   # Name of output file
+     $save_temps,               # Save temporary files?
      );
 
 GetOptions(
-	   'input=s'    => \$input,
-	   'extname=s'  => \$extname,
-	   'skycell=s'  => \$skycell,
-	   'output=s'   => \$output,
-	   'save-temps' => \$save_temps,
+           'input=s'    => \$input,
+           'extname=s'  => \$extname,
+           'skycell=s'  => \$skycell,
+           'output=s'   => \$output,
+           'save-temps' => \$save_temps,
 ) or pod2usage( 2 );
 
@@ -37,5 +37,5 @@
 pod2usage( -msg => "Required options: --input --extname --skycell --output",
            -exitval => 3)
-    unless defined $input 
+    unless defined $input
     and defined $extname
     and defined $skycell
@@ -44,14 +44,14 @@
 # Specification of columns to write
 my $columns = [ { name => 'RA_DEG',   type => 'D' }, # 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 => 'ANG',      type => 'D' }, # Angle
-		{ name => 'ANG_SIG',  type => 'D' }, # Error in angle
-		{ name => 'LEN',      type => 'D' }, # Length
-		{ name => 'LEN_SIG',  type => 'D' }, # Error in length
-		];
+                { 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 => 'ANG',      type => 'D' }, # Angle
+                { name => 'ANG_SIG',  type => 'D' }, # Error in angle
+                { name => 'LEN',      type => 'D' }, # Length
+                { name => 'LEN_SIG',  type => 'D' }, # Error in length
+                ];
 
 # Header translation table
@@ -66,5 +66,5 @@
     'FPA.AZ'       => { name => 'TEL_AZ',   type => TDOUBLE, comment => 'Telescope azimuth' },
     'MJD-OBS'      => { name => 'MJD-OBS',  type => TDOUBLE, comment => 'Time of exposure' },
-	    };
+            };
 
 
@@ -103,18 +103,18 @@
 check_fitsio($status);
 $inFits->movnam_hdu(BINARY_TBL, $extname, 0, $status) and check_fitsio($status);
-my $numRows;			# Number of rows in table
+my $numRows;                    # Number of rows in table
 $inFits->get_num_rows($numRows, $status) and check_fitsio($status);
 
-my ($xCol, $yCol, $magCol);		# Column numbers for x and y
+my ($xCol, $yCol, $magCol);             # 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
+my ($xType, $yType, $magType);  # 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
+my ($x, $y, $mag);              # 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);
@@ -124,7 +124,7 @@
 
 # Parse the list of columns
-my @colNames;			# Names of columns
-my @colTypes;			# Types of columns
-my %colData;			# Data for each column
+my @colNames;                   # Names of columns
+my @colTypes;                   # Types of columns
+my %colData;                    # Data for each column
 foreach my $colSpec ( @$columns) {
     push @colNames, $colSpec->{name};
@@ -156,5 +156,10 @@
 check_fitsio( $status );
 
-# Write the PHU keywords
+# Write the table
+$outFits->create_tbl( BINARY_TBL(), $numRows, scalar @colNames, \@colNames, \@colTypes, undef, EXTNAME,
+                      $status );
+check_fitsio( $status );
+
+# Write the header keywords
 $outFits->create_img( 16, 0, undef, $status );
 check_fitsio( $status );
@@ -162,6 +167,6 @@
     my $value = $inHeader->{$keyword}; # Header keyword value
     unless (defined $value) {
-	print "Can't find header keyword $keyword\n";
-	next;
+        print "Can't find header keyword $keyword\n";
+        next;
     }
     $value =~ s/\'//g;
@@ -196,8 +201,5 @@
 $outFits->write_key( TINT, 'DE10', FAKE_DETECTION_EFFICIENCY, 'Detection efficiency (FAKE)', $status );
 
-# Write the table
-$outFits->create_tbl( BINARY_TBL(), $numRows, scalar @colNames, \@colNames, \@colTypes, undef, EXTNAME,
-		      $status );
-check_fitsio( $status );
+# Write the data
 for (my $i = 0; $i < scalar @colNames; $i++) {
     my $colName = $colNames[$i];# Column name
@@ -215,10 +217,10 @@
 sub check_fitsio
 {
-    my $status = shift;		# Status of FITSIO calls
+    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";
+        my $msg;                # Message to output
+        Astro::FITS::CFITSIO::fits_get_errstatus( $status , $msg );
+        die "CFITSIO error: $msg\n";
     }
 }
@@ -227,5 +229,5 @@
 sub pixels_to_sky
 {
-    my ($x, $y) = @_;		# Coordinates
+    my ($x, $y) = @_;           # Coordinates
 
     # Pixel coordinate relative to reference
@@ -242,10 +244,10 @@
     my $phi = atan2($eta,$xi) + pi/2;
     my $theta = atan(180 / pi / sqrt($xi**2 + $eta**2));
-    
+
     # Coordinates on celestial sphere
     my $ra = $crval1 + atan2(cos($theta) * sin($phi),
-			     sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
+                             sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
     my $dec = asin(sin($theta) * sin($crval2) - cos($theta) * cos($crval2) * cos($phi));
-    
+
     return (rad2deg($ra), rad2deg($dec));
 }
