#!/usr/bin/perl
#

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


$v = 0.9;
$gamma = sqrt( 1.0 / (1.0 - $v*$v) );


if (1 == 1) {
 # plot a single ST diagram, part of the twin paradox series
 #    show Joe about to leave Earth 
 

  
  my($output_file, $term_options);

  $time = 0.0;
  # get the arguments
  $output_file = sprintf "joe_earth_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %.0f ", 2500 + $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_earth_%04.1f.dat", $time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$earth_simul' using 1:2 with lines lt 3 lw 10  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 single ST diagram, part of the twin paradox series
 #    show Joe leaving Earth, with simul of Red ship marked
 

  
  my($output_file, $term_options);

  $time = 0.0;
  # get the arguments
  $output_file = sprintf "start_red_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Red Navy time %.0f ", 2500 + $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_earth_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", 30.0;
  $red_simul = sprintf "./red_simul_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$red_simul' using 1:2 with lines lt 1 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe just reaching the planet P27
 

  
  my($output_file, $term_options);

  $time = 30.0;
  # get the arguments
  $output_file = sprintf "joe_earth_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %.0f ", 2500 + $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_p27_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", $time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$earth_simul' using 1:2 with lines lt 3 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe returning to Earth, as measured by Earth people
 

  
  my($output_file, $term_options);

  $time = 60.0;
  # get the arguments
  $output_file = sprintf "joe_earth_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Earth time %.0f ", 2500 + $time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_earth_%04.1f.dat", $time;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", $time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$earth_simul' using 1:2 with lines lt 3 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe briefly shopping on P27
 #    with lines of simultaneity, according to planet P27 time
 

  
  my($output_file, $term_options);

  $earth_time = 30.0;
  # get the arguments
  $output_file = sprintf "p27_simul_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Planet time %.0f", 2500 + $earth_time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_p27_%04.1f.dat", $earth_time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $earth_time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$earth_simul' using 1:2 with lines lt 3 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe just reaching the planet P27
 #    with lines of simultaneity, according to red ship frame
 

  
  my($output_file, $term_options);

  $earth_time = 30.0;
  $red_time = 30.0/$gamma;
  # get the arguments
  $output_file = sprintf "red_simul_%04.1f.ps", $red_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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Red Navy time %.0f ", 2500 + $red_time;
  printf CMDFILE "set label 1 '$label_text' at 21,15 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_p27_%04.1f.dat", $earth_time ;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", $earth_time ;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  $red_simul = sprintf "./red_simul_%04.1f.dat", $red_time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$red_simul' using 1:2 with lines lt 1 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe just reaching the planet P27
 #    with lines of simultaneity, according to Green ship frame
 

  
  my($output_file, $term_options);

  $earth_time = 30.0;
  $red_time = 30.0/$gamma;
  # get the arguments
  $output_file = sprintf "green_simul_%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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Green Navy time %.0f", 2500 + $earth_time;
  printf CMDFILE "set label 1 '$label_text' at 21,50 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_p27_%04.1f.dat", $earth_time;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", $earth_time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  $green_simul = sprintf "./green_simul_%04.1f.dat", $red_time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$green_simul' using 1:2 with lines lt 2 lw 3  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 single ST diagram, part of the twin paradox series
 #    show Joe just getting back to Earth
 #    with lines of simultaneity, according to Green ship frame
 

  
  my($output_file, $term_options);

  $earth_time = 60.0;
  $green_time = 30 + 30.0/$gamma;
  # get the arguments
  $output_file = sprintf "green_simul_%04.1f.ps", $green_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 on Earth since 2500 (years) ' \n";
  printf CMDFILE "set title 'Twin paradox '\n";
  $label_text = sprintf "Green Navy time %.0f", 2500 + $green_time;
  printf CMDFILE "set label 1 '$label_text' at 21,50 font 'Helvetica,24' \n";

  $joe_dot = sprintf "./joe_on_earth_%04.1f.dat", $earth_time;
  $joe_line = sprintf "./joe_earth_%04.1f.dat", $earth_time;
  $earth_simul = sprintf "./earth_simul_%04.1f.dat", $time;
  $green_simul = sprintf "./green_simul_%04.1f.dat", $green_time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$joe_dot' using 1:2 with points lt -1 lw 2 pt 6 ps 2.0 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$joe_line' using 1:2 with linespoints lt -1 lw 2 ps 0.3 t ''  ";
  $cmd .= " , ";
  $cmd .= " '$green_simul' using 1:2 with lines lt 2 lw 3  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`;
  }


}





exit 0;

