#!/usr/bin/perl
#
# Compute the phase for a binary star, given a light-curve datafile
#  of the form
#
#          date   JD  HJD  mag
#
# We use the HJD and mag as the inputs for the phased light curve.
#
# Usage:   calc_phase.pl   lightcurve.dat
#
# MWR 5/3/2016
use POSIX;

$debug = 1;

# for ASAS 002511
$epoch = 3267.65;
#   the following is good for combination of Sep19 and Sep20 UT
#$period = 0.05398;
#   the following is good for Sep19 alone
$period = 0.05340;

# for sparse example
$epoch = 0;
$period = 6.280;

if ($#ARGV != 0) {
  printf STDERR "usage: calc_phase.pl  datafile  \n";
  exit(1);
}

$infile = $ARGV[0];
open(INFILE, "$infile") || die("can't open file $infile");
while (<INFILE>) {
  $line = $_;
  if ($line =~ /^#/) {
    next;
  }
  chomp($line);
  @words = split(/\s+/, " " . $line);

# for ASAS 
  $hjd = $words[3];
  $mag = $words[4];
# for sparse
  $hjd = $words[1];
  $mag = $words[3];


  $x = ($hjd - $epoch) / $period;
  $phase = $x - floor($x);
  printf " %s %20.12f %20.12f \n", $line, $phase, 1.0 + $phase;

}



exit 0;




