#!/usr/bin/perl
#

use POSIX;

$date_zero = 3590.0;
# period in days: note superhumps for EI Psc are 66.774 minutes,
#   and orbital period is (probably) 64.184 minutes
$period = 66.774/1440.0;
#$period = 64.184/1440.0;
#$period = 0.04456691;
#$period = 0.04656691;

while (<STDIN>) {

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

  $line = " " . $line;

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

  # 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;

