#!/usr/bin/perl
#


  
  my($output_file, $term_options);


  # Plot the TESS light curve of WASP-100, 
  #    with default units of intensity 
  $output_file = "wasp100_lc_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Brightness of star ' \n";
  printf CMDFILE "set xlabel 'Date (days after 2457000) ' \n";
  printf CMDFILE "set title 'TESS measurements of WASP 100 '\n";
  
  $cmd = "plot [][0:13000] 'tess_00038846515_lc.dat' using (\$1):(\$2) ";
  $cmd .= "        lt 1 pt 1 ps 0.2 t '' ";

  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot the TESS light curve of WASP-100, 
  #    with default units of intensity 
  #    zoom in on the interesting part near peak intensity
  $output_file = "wasp100_lc_b.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Brightness of star ' \n";
  printf CMDFILE "set xlabel 'Date (days after 2457000) ' \n";
  printf CMDFILE "set title 'TESS measurements of WASP 100 '\n";
  
  $cmd = "plot [][10600:11600] 'tess_00038846515_lc.dat' using (\$1):(\$2) ";
  $cmd .= "        lt 1 pt 1 ps 0.2 t '' ";

  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  # Plot the TESS light curve of WASP-100, 
  #    normalize intensity to average peak value of about 11250 
  #    zoom in on the interesting part 
  $output_file = "wasp100_lc_c.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";
  $norm_value = 11250;

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel '(Brightness of star) / $norm_value  ' \n";
  printf CMDFILE "set xlabel 'Date (days after 2457000) ' \n";
  printf CMDFILE "set title 'TESS measurements of WASP 100 '\n";
  
  $cmd = "plot [][0.95:1.02] 'tess_00038846515_lc.dat' using (\$1):(\$2/$norm_value) ";
  $cmd .= "        lt 1 pt 1 ps 0.2 t '' ";

  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot the TESS light curve of WASP-100, 
  #    normalize intensity to average peak value of about 11250 
  #    zoom in on the interesting part 
  #    zoom in even more
  $output_file = "wasp100_lc_d.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";
  $norm_value = 11250;

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel '(Brightness of star) / $norm_value  ' \n";
  printf CMDFILE "set xlabel 'Date (days after 2457000) ' \n";
  printf CMDFILE "set title 'TESS measurements of WASP 100 '\n";
  
  $cmd = "plot [][0.985:1.01] 'tess_00038846515_lc.dat' using (\$1):(\$2/$norm_value) ";
  $cmd .= "        lt 1 pt 1 ps 0.2 t '' ";

  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Plot the TESS light curve of WASP-100, 
  #    normalize intensity to average peak value of about 11250 
  #    zoom in on the interesting part 
  #    zoom in even more
  #    look at just one transit
  $output_file = "wasp100_lc_e.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' ";
  $norm_value = 11240;

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel '(Brightness of star) / $norm_value  ' \n";
  printf CMDFILE "set xlabel 'Date (days after 2457000) ' \n";
  printf CMDFILE "set title 'TESS measurements of WASP 100 '\n";
  
  $cmd = "plot [1332.1:1332.8][0.985:1.005] 'tess_00038846515_lc.dat' using (\$1):(\$2/$norm_value) ";
  $cmd .= "        lt 1 pt 1 ps 0.5 lw 5 t '' ";

  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }







exit 0;
