#!/usr/bin/perl
#

use POSIX;

$date_zero = 40825.47500;
# period in days: 
$period = 0.5844659000;

#for ($i = 0; $i < 500; $i++) {
#  $jd = $date_zero + $i*0.1;
#
#  $phase = ($jd / $period) - floor($jd / $period);
#  printf "%12.5f %12.5f  %6.3f \n", $jd, $jd, $phase;
#}
#
#exit 0;

while (<STDIN>) {

  $line = $_;
  chomp($line);
  if ($line =~ /^#/) {
    next;
  }

  $line = " " . $line;

  @words = split(/\s+/, $line);
  $date = $words[1];
  $mag = $words[2];

  # remove trend from mag
#  $x = $date - 3590.0;
#  $trend_mag = (13.6532 - 0.806137*$x);
#  $mag = ($mag - $trend_mag) + 13.050;
#  
  $date -= $date_zero;

  $x = $date/$period;
  $x_int = floor($x);
  $phase = (($date - ($x_int*$period))/$period);
#
  printf "%12.8f %12.7f %7.3f \n", $date, $phase, $mag;
  printf "%12.8f %12.7f %7.3f \n", $date, ($phase - 1.0), $mag;
  
}

exit 0;

