#!/usr/bin/perl
#
# Given two magnitudes, A and B, compute the magnitude of a third star
#    which is required to make the total light (B+C) = A.
#
# usage:    sub_mag.pl  A  B
#
# MWR 7/26/2013

use POSIX;

$debug = 1;

if ($#ARGV != 1) {
  printf "usage: sub_mag.pl  magA  magB \n";
  exit(1);
}
$magA = $ARGV[0];
$magB = $ARGV[1];
if ($debug > 0) {
  printf " magA = %8.3f   magB = %8.3f \n", $magA, $magB;
}
if ($magA >= $magB) {
  printf " magA must be brighter than magB \n";
  exit(1);
}

$magzp = 25.0;

# convert magnitude to intensity 
$iA = 10**(0.4*($magzp - $magA));
$iB = 10**(0.4*($magzp - $magB));

# subtract intensity
$iC = $iA - $iB;

# now convert intensity back to mag
$magC = $magzp - 2.5*(log10($iC));

printf " %8.4f \n", $magC;






exit 0;

