#!/usr/bin/perl
#
# Plot results of the swinging ring experiment
#  
# MWR 1/8/2026

  my($output_file, $term_options);

  ######################################################################
  # Plot showing all the data, including the smallest ring
  #   do NOT include hula hoop
  #
  $output_file = "swing_linear_a.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";
  
  $minx = 1.0;
  $maxx = 40.0;
  $miny = 2.0;
  $maxy = 13.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0";
  $cmd .= "    using 1:3 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0 ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0 ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.5 pt 6 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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    includes hula hoop as well
  #
  $output_file = "swing_linear_a_big.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";
  
  $minx = 1.0;
  $maxx = 40.0;
  $maxx = 100.0;
  $miny = 2.0;
  $maxy = 13.0;
  $maxy = 20.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:3 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.5 pt 6 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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    with linear fit to all data EXCEPT the smallest ring
  #
  #    Do NOT include hula hoop
  #
  $output_file = "swing_linear_b.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*x
  # where we do NOT include the smallest ring
  $a_val = 3.438;
  $b_val = 0.246053;

  # these are the parameters for linear fit, if include hula hoop
  # $a_val = 4.174;
  # $b_val = 0.157729;

  
  $minx = 1.0;
  $maxx = 40.0;
  $miny = 2.0;
  $maxy = 13.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0 ";
  $cmd .= "    using 1:3 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0 ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0 ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit excluding smallest' ";


  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    with linear fit to all data EXCEPT the smallest ring
  #
  #    Do include hula hoop
  #
  $output_file = "swing_linear_b_big.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*x
  # where we do NOT include the smallest ring
  $a_val = 3.438;
  $b_val = 0.246053;

  # these are the parameters for linear fit, if include hula hoop
  $a_val = 4.174;
  $b_val = 0.157729;

  
  $minx = 1.0;
  $maxx = 40.0;
  $maxx = 100.0;
  $miny = 2.0;
  $maxy = 13.0;
  $maxy = 20.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:3 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit excluding smallest' ";


  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    with linear fit to all data EXCEPT the smallest ring
  #    and with sqrt fit to all data EXCEPT the smallest ring
  #
  # Do NOT include hula hoop
  #
  $output_file = "swing_linear_c.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*x
  # where we do NOT include the smallest ring
  $a_val = 3.438;
  $b_val = 0.246053;

  # these are the parameters for linear fit, if include hula hoop
  #$a_val = 4.174;
  #$b_val = 0.157729;

  # these are parameters of sqrt fit to data
  #   g(x) = c + d*x
  # where we do NOT include the smallest ring
  $c_val = -0.695895;
  $d_val = 2.08789;
  
  # these are the parameters for sqrt fit, if include hula hoop
  #$c_val = -0.23998;
  #$d_val = 1.97953;
  
  $minx = 1.0;
  $maxx = 40.0;
  $miny = 2.0;
  $maxy = 13.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0";
  $cmd .= "    using 1:3 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0";
  $cmd .= "    using 1:4 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' index 0";
  $cmd .= "    using 1:5 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit excluding smallest' ";
  $cmd .= " , ";
  $cmd .= "    $c_val+($d_val*sqrt(x)) with lines ls 3 ";
  $cmd .= "    t 'sqrt fit excluding smallest' ";



  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    with linear fit to all data EXCEPT the smallest ring
  #    and with sqrt fit to all data EXCEPT the smallest ring
  #
  # Do include hula hoop
  #
  $output_file = "swing_linear_c_big.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s)'\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*x
  # where we do NOT include the smallest ring
  $a_val = 3.438;
  $b_val = 0.246053;

  # these are the parameters for linear fit, if include hula hoop
  $a_val = 4.174;
  $b_val = 0.157729;

  # these are parameters of sqrt fit to data
  #   g(x) = c + d*x
  # where we do NOT include the smallest ring
  $c_val = -0.695895;
  $d_val = 2.08789;
  
  # these are the parameters for sqrt fit, if include hula hoop
  $c_val = -0.23998;
  $d_val = 1.97953;
  
  $minx = 1.0;
  $maxx = 40.0;
  $maxx = 100.0;
  $miny = 2.0;
  $maxy = 13.0;
  $maxy = 20.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:3 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit excluding smallest' ";
  $cmd .= " , ";
  $cmd .= "    $c_val+($d_val*sqrt(x)) with lines ls 3 ";
  $cmd .= "    t 'sqrt fit excluding smallest' ";



  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    and hula hoop.  
  #    This version uses log10(diam) and log10(time).
  #
  # Show linear fit.
  #
  #
  $output_file = "swing_log_big.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026_log.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Log10( Time for 10 oscillations (s) )'\n";
  printf CMDFILE "set xlabel 'Log10( Outside diameter of ring (cm) ) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment -- logarithms '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*x
  # where we include all rings and hula hoop
  $a_val = 0.22940;
  $b_val = 0.536355;

  $minx = 0.4;
  $maxx = 2.1;
  $miny = 0.30;
  $maxy = 1.40;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:3 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:4 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using 1:5 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit slope 0.54 +/- 0.01 ' ";



  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data, including the smallest ring
  #    and hula hoop.  
  #    This version uses sqrt(diameter) on the horizontal axis.
  #
  # Show sqrt fit.
  #
  #
  $output_file = "swing_sqrt_big.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./mwr_jan07_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s) '\n";
  printf CMDFILE "set xlabel 'Sqrt( Outside diameter of ring (cm) ) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment -- square root '\n";

  # these are parameters of linear fit to data
  #   f(x) = a + b*sqrt(x)
  # where we include all rings and hula hoop
  $a_val = -0.265;
  $b_val = 1.975;

  $minx = 1.0;
  $maxx = 11.0;
  $miny = 2.0;
  $maxy = 20.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using (sqrt(\$1)):3 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using (sqrt(\$1)):4 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "                                '$input_file' ";
  $cmd .= "    using (sqrt(\$1)):5 with points ls 1 ps 1.8 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    $a_val+($b_val*x) with lines ls 2 ";
  $cmd .= "    t 'linear fit ' ";



  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   include outlier
  #   don't include my hula-hoop measurements
  #   include linear fit with outlier
  #
  $output_file = "stu_swing_a.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s) '\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";
 
  # linear fit to student data only, including outlier
  $a = 5.516;
  $b = 0.15805;
  printf CMDFILE "f(x) = $a + $b*x \n";
  
  $minx = 0.0;
  $maxx = 50;
  $miny = 2.0;
  $maxy = 15.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:2 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    f(x) ls 3 t 'linear fit' ";

  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   DON'T include outlier
  #   don't include my hula-hoop measurements
  #   include linear fit WITHOUT outlier
  #
  $output_file = "stu_swing_b.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s) '\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";
 
  # linear fit to student data only, including outlier
  $a = 4.400;
  $b = 0.201428;
  printf CMDFILE "f(x) = $a + $b*x \n";
  
  $minx = 0.0;
  $maxx = 50;
  $miny = 2.0;
  $maxy = 15.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:2 index 0 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    f(x) ls 3 t 'linear fit without outlier' ";

  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   DON'T include outlier
  #   DO include my hula-hoop measurements
  #   include linear fit WITHOUT outlier
  #
  $output_file = "stu_swing_c.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Time for 10 oscillations (s) '\n";
  printf CMDFILE "set xlabel 'Outside diameter of ring (cm) ' \n";
  printf CMDFILE "set title 'Swinging ring experiment '\n";
 
  # linear fit to student data only, excluding outlier
  $a = 4.400;
  $b = 0.201428;
  printf CMDFILE "f(x) = $a + $b*x \n";

  # linear fit to student data plus hula hoop, excluding outlier
  $c = 5.359;
  $d = 0.161586;
  printf CMDFILE "g(x) = $c + $d*x \n";

  
  $minx = 0.0;
  $maxx = 100;
  $miny = 2.0;
  $maxy = 22.0;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' ";
  $cmd .= "    using 1:2 index 0:2:2 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "    f(x) ls 3 t 'linear fit, student only' ";
  $cmd .= " , ";
  $cmd .= "    g(x) ls 2 t 'linear fit, student + hula'  ";

  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   include my hula-hoop measurements
  #   plot log10 of both quantities
  #
  $output_file = "stu_swing_log_d.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026_log.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'log10 [ Time for 10 oscillations (s) ]'\n";
  printf CMDFILE "set xlabel 'log10 [ Outside diameter of ring (cm) ] ' \n";
  printf CMDFILE "set title 'Swinging ring experiment - log version'\n";
  
  $minx = 0.4;
  $maxx = 2.2;
  $miny = 0.4;
  $maxy = 1.4;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0:1 ";
  $cmd .= "    using 1:2 with points ls 1 ps 1.5 pt 6 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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   include my hula-hoop measurements and tiny ring
  #   plot log10 of both quantities
  #
  $output_file = "stu_swing_log_e.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026_log.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'log10 [ Time for 10 oscillations (s) ]'\n";
  printf CMDFILE "set xlabel 'log10 [ Outside diameter of ring (cm) ] ' \n";
  printf CMDFILE "set title 'Swinging ring experiment - log version'\n";
  
  $minx = 0.4;
  $maxx = 2.2;
  $miny = 0.4;
  $maxy = 1.4;

  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0:2 ";
  $cmd .= "    using 1:2 with points ls 1 ps 1.5 pt 6 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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  ######################################################################
  # Plot showing all the data collected by students on Jan 12, 2026
  #   include my hula-hoop measurements and tiny ring
  #   plot sqrt of diam
  #
  $output_file = "stu_swing_sqrt_f.ps";
  $term_options = "postscript color 'Helvetica,18' ";
  $input_file = "./stu_jan12_2026.dat";

  $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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'log10 [ Time for 10 oscillations (s) ]'\n";
  printf CMDFILE "set xlabel 'log10 [ Outside diameter of ring (cm) ] ' \n";
  printf CMDFILE "set title 'Swinging ring experiment - sqrt version'\n";
  
  # fit to sqrt of all data 
  $c = -0.2388;
  $d = 1.98113;
  printf CMDFILE "f(x) = $c + $d*sqrt(x) \n";

  $minx = 0;
  $maxx = 110;
  $miny = 2.0;
  $maxy = 22.0;


  $cmd = "plot [$minx:$maxx][$miny:$maxy]  '$input_file' index 0:4:2 ";
  $cmd .= "    using 1:2 with points ls 1 ps 1.5 pt 6 t '' ";
  $cmd .= " , ";
  $cmd .= "   f(x) with lines ls 3 t 'fit to sqrt(diam)' \n";


  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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }













exit 0;
