#!/usr/bin/perl
#
# reformat the nova catalog so that 
#   RA and Dec are in decimal degrees
#
# MWR 10/17/2007

$debug = 0;

while (<STDIN>) {
  $line = $_;

  if ($debug > 0) {
    printf "next line is ..%s.. \n", $line;
  }
 
  # get the name, replace spaces by underscores
  $name_str = substr($line, 12, 13);
  $len = length($name_str);
  for ($i = 1; $i < $len - 1; $i++) {
    if ((substr($name_str, $i-1, 1) ne " ") &&
        (substr($name_str, $i+1, 1) ne " ") &&
        (substr($name_str, $i, 1) eq " ")) {
      substr($name_str, $i, 1) = "_";
    }
  }
  $name_str =~ s/ //g;
  if ($debug > 0) {
    printf " name_str is ..%s.. \n", $name_str;
  }

  # figure out RA, convert to decimal degrees
  $ra_str = substr($line, 26, 12);
  @words = split(/\s+/, $ra_str);
  $ra_h = $words[0];
  $ra_m = $words[1];
  $ra_s = $words[2];
  if ($debug > 0) {
    printf " RA  ..%s.. %d %d %5.2f ", $ra_str, $ra_h, $ra_m, $ra_s;
  }
  $ra_deg = $ra_h + ($ra_m/60.0) + ($ra_s/3600.0);
  $ra_deg *= 15.0;
  if ($debug > 0) {
    printf "  = %10.5f \n", $ra_deg;
  }
  
  # figure out Dec, convert to decimal degrees
  $dec_str = substr($line, 40, 13);
  @words = split(/\s+/, $dec_str);
  $dec_d = $words[0];
  $dec_m = $words[1];
  $dec_s = $words[2];
  if ($debug > 0) {
    printf " Dec  ..%s.. %d %d %5.2f ", $dec_str, $dec_d, $dec_m, $dec_s;
  }
  if ($dec_d >= 0) {
    $dec_sign = 1;
  }
  else {
    $dec_d = 0.0 - $dec_d;
    $dec_sign = -1.0;
  }
  $dec_deg = $dec_d + ($dec_m/60.0) + ($dec__s/3600.0);
  $dec_deg *= $dec_sign;
  if ($debug > 0) {
    printf "  = %10.5f \n", $dec_deg;
  }
  

  # now print out a copy of the original line, but with the
  #   new name, and with RA and Dec in decimal degrees
  $first = substr($line, 0, 12);
  $last = substr($line, 54, length($line) - 54);
  printf "%s %-14s %10.5f %10.5f %s", 
           $first, $name_str, $ra_deg, $dec_deg, $last;



}




exit 0;
