#!/usr/bin/perl
#
# create a simple multi-column ASCII text file with
#   photometry of stars in intensity units
#   (using data on V404 Cyg from jun23_2015)
#
#      Jun23_2015 star        my label in output
#       ----------------------------------------
#            A                      B
#            B                      D
#            V404                   C
#            C                      A
#
# MWR 2/17/2022

use POSIX;
$debug = 0;

$infile = "./all.dat4";
$outfile = "./intensity.dat";


open(INFILE, "$infile") || die("can't open file $infile");
open(OUTFILE, ">$outfile") || die("can't create file $outfile");

printf OUTFILE " %12s  %9s %9s %9s %9s \n",
       "Julian_Day", "A", "B", "C", "D";

while (<INFILE>) {

  $line = $_;
  @words = split(/\s+/, $line);
  $jd = $words[4];
  $mag_a = $words[6];
  $mag_b = $words[16];
  $mag_c = $words[26];
  $mag_d = $words[36];
  $mag_e = $words[46];
  $mag_v404 = $words[56];

  if ($debug > 0) {
    printf " %12.5f  %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f \n",
        $jd, $mag_a, $mag_b, $mag_c, $mag_d, $mag_e, $mag_v404;
  }

  # convert from mag to intensity, arbitrary scale
  # also, switch identities

  # old star A becomes new star B
  $inten_b = 10.0**(0.4*(10.0 - $mag_a));
  # old star B becomes new star D
  $inten_d = 10.0**(0.4*(10.0 - $mag_b));
  # old star V404 becomes new star C
  $inten_c = 10.0**(0.4*(10.0 - $mag_v404));
  # old star C becomes new star A
  $inten_a = 10.0**(0.4*(10.0 - $mag_c));

    printf OUTFILE " %12.5f  %9.1f %9.1f %9.1f %9.1f \n",
        $jd, $inten_a, $inten_b, $inten_c, $inten_d;



}


close(OUTFILE);
close(INFILE);






exit 0;
