#!/usr/bin/perl
#

$xmin = 0;
$xmax = 65;
$ymin = 0;
$ymax = 65;


if (0 == 1) {
 # plot a single ST diagram, part of the twin paradox series
 #    show messages from Bob from the Earth

 for ($time = 0; $time <= 60.0; $time += 1.0) {
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $bob_msg  = sprintf "./bob_msg_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_msg' using 1:2 with points lt -1 lw 0.5 ps 0.2 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";

 

  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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

 }

}



if (0 == 1) {
 # plot a single ST diagram, part of the twin paradox series
 #    show messages from Joe aboard the ship

 for ($time = 0; $time <= 60.0; $time += 1.0) {
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_ship.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  $joe_msg  = sprintf "./joe_msg_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_msg' using 1:2 with points lt 1 lw 0.5 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

 }

}




if (1 == 0) {
 # plot a closeup near the start of the Twin paradox,
 #    plotting messages sent from Bob on Earth


 for ($time = 0.0; $time < 10.0; $time += 0.1) {

  $xmin = 0;
  $xmax = 12.0;
  $ymin = 0;
  $ymax = 12.0;

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_close.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 5,3 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $bob_msg  = sprintf "./bob_msg_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_msg' using 1:2 with points lt -1 lw 2 ps 0.2 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";

  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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


 }

}


if (0 == 1) {
 # plot a closeup near the start of the Twin paradox,
 #    plotting messages sent from Joe on the ship


 for ($time = 0.0; $time < 10.0; $time += 0.1) {

  $xmin = 0;
  $xmax = 12.0;
  $ymin = 0;
  $ymax = 12.0;

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_close_ship.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 5,3 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  $joe_msg  = sprintf "./joe_msg_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_msg' using 1:2 with points lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


 }

}


if (1 == 1) {
 # plot a closeup near the turning point of the paradox,
 #    plotting messages sent from Bob on Earth


 for ($time = 23.0; $time < 37.0; $time += 0.1) {

  $xmin = 16;
  $xmax = 30;
  $ymin = 23;
  $ymax = 37;

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_turn.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 22,36 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $bob_msg  = sprintf "./bob_msg_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_msg' using 1:2 with points lt -1 lw 2 ps 0.2 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";

  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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


 }

}



if (1 == 0) {
 # plot a closeup near the END of the Twin paradox,
 #    plotting messages sent from Joe on the ship


 for ($time = 54.0; $time < 60.1; $time += 0.1) {

  $xmin = 0;
  $xmax = 7.0;
  $ymin = 54;
  $ymax = 61.0;

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_end_ship.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 3,58 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;
  $joe_msg  = sprintf "./joe_msg_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_msg' using 1:2 with points lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


 }

}



if (0 == 1) {
 # plot a single ST diagram, part of the twin paradox series
 #    show messages from Joe aboard the ship;
 #    show all the time up to the turning point

 for ($time = 0; $time <= 30.0; $time += 1.0) {
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = sprintf "st_%04.1f_half.ps", $time;
  $term_options = "postscript color enhanced ";

  $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 size square \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot right \n";
  printf CMDFILE "set xlabel 'Position (years) ' \n";
  printf CMDFILE "set ylabel 'Time (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %4.1f years", $time;
  printf CMDFILE "set label 1 '$label_text' at 11,8 font 'Helvetica,24' \n";

  $bob_line = sprintf "./bob_line_%04.1f.dat", $time;
  $bob_bday = sprintf "./bob_bday_%04.1f.dat", $time;
  $bob_msg  = sprintf "./bob_msg_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_line_%04.1f.dat", $time;
  $joe_bday = sprintf "./joe_bday_%04.1f.dat", $time;

  $xmin = 0;
  $xmax = 32;
  $ymin = 0;
  $ymax = 32;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$bob_line' using 1:2 with linespoints lt -1 lw 2 ps 0.4 t 'Bob'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_bday' using 1:2 with points lt -1 lw 1 ps 1.2 t 'Bob birthdays'  ";
  $cmd .= " , ";
  $cmd .= " '$bob_msg' using 1:2 with points lt -1 lw 0.5 ps 0.2 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt 1 lw 2 ps 0.3 t 'Joe'  ";
  $cmd .= " , ";
  $cmd .= " '$joe_bday' using 1:2 with points lt 1 lw 3 pt 4 ps 1.2 t 'Joe birthdays'  ";

 

  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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

 }

}



exit 0;

