#!/usr/bin/perl
#
# Calculate extinction corrections for sample of Cepheids 
#   given by 
#   https://vizier.u-strasbg.fr/viz-bin/VizieR-3?-source=J/AcA/49/543/table1&-out.max=9999&-out.form=HTML%20Table&-out.add=_r&-out.add=_RAJ,_DEJ&-sort=_r&-oc.form=sexa
#
# MWR 11/9/2020

$debug = 1;

# extinction coefficient for V-band: A_V = cv * E(B-V)
$cv = 0.20;
# extinction coefficient for I-band: A_I = ci * E(B-V)
$ci = 0.08;
# distance modulus to LMC 
$distmod = 18.5;
# absolute magnitude of Sun in V
$mv_solar = 4.80;
# absolute magnitude of Sun in I
$mi_solar = 4.10;
# luminosity of Sun (solar units)
$lum_solar = 1.0;


$infile = "./lmc_ceph.dat";

open(INFILE, "$infile") || die("Can't open file $infile \n");
while (<INFILE>) {
  $line = $_;
  chomp($line);
  if ($line =~ /^#/) {
    next;
  }
  
  @words = split(/\s+/, $line);
  $vmag = $words[6];
  $imag = $words[7];
  $ebv = $words[8];

  $new_vmag = $vmag - $cv*$ebv;
  $new_imag = $imag - $ci*$ebv;

  # now, compute luminosity
  $abs_vmag = ($new_vmag - $distmod);
  $lum_v = $lum_solar*( 10.0**(-0.4*($abs_vmag - $mv_solar)) );
  $abs_imag = ($new_imag - $distmod);
  $lum_i = $lum_solar*( 10.0**(-0.4*($abs_imag - $mi_solar)) );

  printf "%s %6.3f %6.3f  %9.3e %9.3e  \n", 
        $line, $new_vmag, $new_imag, $lum_v, $lum_i;

}



exit 0;
