#!/usr/bin/perl
#
# convert from magnitudes per sq.arcsec 
#   to some linear units, like counts per sq.arcsec,
#   with arbitrary scaling factor.
#
# MWR 3/17/2011


use POSIX;
$debug = 1;

$magzero = 30;
$scale = 0.001;

while  (<STDIN>) {
  $line = $_;
  if ($line =~ /^#/) {
    printf "%s", $line;
    next;
  }
  if ($line =~ /^$/) {
    printf "%s", $line;
    next;
  }
  $line = " " . $line;
  @words = split(/\s+/, $line);
  if ($#words == 0) {
    printf "%s \n", $line;
    next;
  }
  if ($#words != 3) {
    printf STDERR "bad input line ..%s..; \n", $line;
    exit(1);
  }
  $rad = $words[1];
  $sb = $words[2];
  $sb_err = $words[3];

  # calculate intensity from sb
  $inten = $scale*pow(10.0, 0.4*($magzero - $sb));

  printf " %8.1f %5.2f %5.2f  %9.4e \n", 
          $rad, $sb, $sb_err, $inten;



}

exit 0;
