#!/usr/bin/perl
# 
# Compute the radius of the Sun as a function of time,
#   using data from an evolutionary model from 
#   the Dartmouth Stellar Evolution tools at
#
#     http://stellar.dartmouth.edu/models/webtools.html
#
# MWR 8/19/2017

$debug = 1;

# luminosity of current Sun (Watts)
$lum_now = 3.83E26;
# radius of current Sun (meters)
$rad_now = 6.96E8;
# Stefan-Boltzmann constant, MKS units
$sigma = 5.67E-8;
# pi
$pi = 3.14159;

# read information from stdin, expect file with format
#    Age    Log Teff Log g  Log L/Lo     B       V       R       I  
#
while (<STDIN>) {
  $line = $_;
  if ($line =~ /^#/) {
    next;
  }
  @words = split(/\s+/, $line);
  
  $age = $words[1];
  $teff = $words[2];
  $teff = 10.0**$teff;
  $logg = $words[3];
  $logL = $words[4];
  $absV = $words[6];

  # compute radius, using simple blackbody emission
  $lum = $lum_now*(10.0**($logL));
  $rad = sqrt(  ($lum) / (4.0*$pi*$sigma*($teff**4.0)) );
  $rad_ratio = $rad / $rad_now;

  # print out one line with all the needed information
  printf " %10.5e %8.4f %8.4f %8.4f %7.4f  %9.5e %6.3f \n",
     $age, $teff, $logg, $logL, $absV, $rad, $rad_ratio;

  


}



exit 0;
