#!/usr/bin/perl
# 
# Compute interesting quantities from the results of a Gaia query
#   which gets info on nearby stars
#
# MWR 8/26/2025

use POSIX;
$debug = 1;

$infile = "./gaia_nearby_C.csv";
open(INFILE, "$infile") || die("can't open file $infile");
while (<INFILE>) {
  $line = $_;
  if ($line =~ /^#/) {
    next;
  }

  @words = split(/,/, $line);

  $parallax = $words[0];
  $app_g_mag = $words[1];
  $color = $words[2];
  $teff = $words[3];
  if ($teff == 0) {
    $teff = 1;
  }

  $dist = 1000.0 / $parallax;
  $distmod = 5.0*log10($dist) - 5.0;
  $abs_g_mag = $app_g_mag - $distmod;

  printf " %7.3f %10.2f  %5.3f  %6.3f %6.3f  %5.3f  %8.1f \n",
       $parallax, $dist, $distmod, $app_g_mag, $abs_g_mag, $color, $teff;


}
close(INFILE);

exit 0;
