#!/usr/bin/perl
#


# get rid of old plots
$cmd = "/bin/rm fluff_[0-9][0-9].[0-9].ps";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm fluff_[0-9][0-9].[0-9].gif";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm fluff_[0-9][0-9].[0-9].png";
$ret = exec_cmd($cmd);

$cmd = "/bin/rm fluff_v_[0-9][0-9].[0-9].ps";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm fluff_v_[0-9][0-9].[0-9].gif";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm fluff_v_[0-9][0-9].[0-9].png";
$ret = exec_cmd($cmd);

$cmd = "/bin/rm rope_[0-9][0-9].[0-9].ps";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm rope_[0-9][0-9].[0-9].gif";
$ret = exec_cmd($cmd);
$cmd = "/bin/rm rope_[0-9][0-9].[0-9].png";
$ret = exec_cmd($cmd);





$start_time = 0;
$end_time = 30.0;
$dt = 0.5;

if (1 == 1) {

 for ($time = $start_time; $time <= $end_time; $time += $dt) {
  
  my($output_file, $term_options);

  # get the arguments
  $term_options = "postscript color enhanced ";

  $cmdfile = "gnuplot.in";

 #
 # plot a diagram showing fluff's position as it moves up and down vertically
 #
  $output_file = sprintf "fluff_v_%04.1f.ps", $time;
  $xmin = -0.2;
  $xmax = 0.2;
  $ymin = -1.0;
  $ymax = 1.0;


  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 'Horizontal Position (meters) ' \n";
  printf CMDFILE "set ylabel 'Vertical position (meters) ' \n";
  printf CMDFILE "set title 'A piece of fluff on a rope'\n";
  $label_text = sprintf "Time %4.1f seconds", $time;
  printf CMDFILE "set label 1 '$label_text' at -0.1,0.7 font 'Helvetica,24' \n";


  $fluff_pos = sprintf "./fluff_%04.1f.dat", $time;
  $temp = "./fluff_tmp.dat";
  $cmd = sprintf "tail -1 %s > %s ", $fluff_pos, $temp; 
  $ret = exec_cmd($cmd);
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$temp' using 2:3 with points lc 1 pt 3 ps 1.5 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/.ps/.gif/;
    $cmd = "convert -rotate 90 -flatten $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  
 #
 # plot a diagram showing fluff's position as a function of time
 #

  $output_file = sprintf "fluff_%04.1f.ps", $time;
  $xmin = -5;
  $xmax = 35;
  $ymin = -1.0;
  $ymax = 1.0;

  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 'Time (seconds) ' \n";
  printf CMDFILE "set ylabel 'Vertical position (meters) ' \n";
  printf CMDFILE "set title 'A piece of fluff, plotted as function of time '\n";
  $label_text = sprintf "Time %4.1f seconds", $time;
  printf CMDFILE "set label 1 '$label_text' at 21,0.7 font 'Helvetica,24' \n";

  $fluff_pos = sprintf "./fluff_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$fluff_pos' using 1:3 with points lc 1 pt 3 ps 1.5 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/.ps/.gif/;
    $cmd = "convert -rotate 90 -flatten $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

  
 #
 # plot a diagram showing rope's position (and fluff) as a function of time
 #

  $output_file = sprintf "rope_%04.1f.ps", $time;
  $xmin = -30;
  $xmax = 30;
  $ymin = -1.0;
  $ymax = 1.0;

  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 'Horizontal position (meters) ' \n";
  printf CMDFILE "set ylabel 'Vertical position (meters) ' \n";
  printf CMDFILE "set title 'Pictures of the rope'\n";
  $label_text = sprintf "Time %4.1f seconds", $time;
  printf CMDFILE "set label 1 '$label_text' at 4,0.7 font 'Helvetica,24' \n";

  $rope_pos = sprintf "./rope_%04.1f.dat", $time;
  
  $cmd = "plot [$xmin:$xmax][$ymin:$ymax] ";
  $cmd .= " '$rope_pos' index 0 using 2:3 with linespoints lc -1 pt 6 ps 0.2 lw 2 t ''  ";
  $cmd .= " , ";
  $cmd .= "   '$rope_pos' index 1 using 2:3 with points lc 1 pt 3 ps 1.5 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/.ps/.gif/;
    $cmd = "convert -rotate 90 -flatten $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



 }  # end of loop over time


}

exit 0;


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;




##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}


