#!/usr/bin/perl
#

##########################################
#  make graph showing intensity of double-slit diffraction pattern

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_two.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";

  # 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 '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 bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Two-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_twoslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 1  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`;
  }



##########################################
#  make graph showing intensity of three-slit diffraction pattern

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_three.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";

  # 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 '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 bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Three-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_threeslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



##########################################
#  make graph showing intensity of three-slit diffraction pattern

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_three_closeup.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";

  # 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 '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 bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Three-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";

  printf CMDFILE "set arrow 1 from 0.00229,0.8 to 0.00229,0.6 ls 1 \n";
  printf CMDFILE "set label 1 '{/Symbol p/3}' at (1*0.00229-0.0002),0.9 tc ls 1  \n";
  printf CMDFILE "set arrow 2 from (2*0.00229),0.8 to (2*0.00229),0.6 ls 1 \n";
  printf CMDFILE "set label 2 '{/Symbol 2p/3}' at (2*0.00229-0.0002),0.9 tc ls 1  \n";
  printf CMDFILE "set arrow 3 from (3*0.00229),0.8 to (3*0.00229),0.6 ls 1 \n";
  printf CMDFILE "set label 3 '{/Symbol p}' at (3*0.00229-0.0002),0.9 tc ls 1  \n";
  printf CMDFILE "set arrow 4 from (4*0.00229),0.8 to (4*0.00229),0.6 ls 1 \n";
  printf CMDFILE "set label 4 '{/Symbol 4p/3}' at (4*0.00229-0.0002),0.9 tc ls 1  \n";
  printf CMDFILE "set arrow 5 from (5*0.00229),0.8 to (5*0.00229),0.6 ls 1 \n";
  printf CMDFILE "set label 5 '{/Symbol 5p/3}' at (5*0.00229-0.0002),0.9 tc ls 1  \n";
  printf CMDFILE "set arrow 6 from (6*0.00229),0.8 to (6*0.00229),0.6 ls 1 \n";
  printf CMDFILE "set label 6 '{/Symbol 2p}' at (6*0.00229-0.0002),0.9 tc ls 1  \n";
  
  $xmin = 0.0;
  $xmax = 0.016;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_threeslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



##########################################
#  make graph showing intensity of both 
#      two-slit and three-slit diffraction pattern


  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_two_three.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";

  # 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 '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 bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Two- and three-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_threeslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 3  t '' ";
  $cmd .= " , ";
  $cmd .= "                     'calc_twoslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 1  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`;
  }



##########################################
#  make graph showing intensity of four-slit diffraction pattern

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_four.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";

  # 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 '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 style line 6 lt rgb 'black' lw 3  \n";



  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Four-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_fourslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



##########################################
#  make graph showing intensity of both 
#      two-slit and four-slit diffraction pattern


  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_two_four.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";

  # 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 '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 style line 6 lt rgb 'black' lw 3  \n";



  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Two- and four-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_fourslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 6  t '' ";
  $cmd .= " , ";
  $cmd .= "                     'calc_twoslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 1  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`;
  }



##########################################
#  make graph showing intensity of both 
#      two-slit and ten-slit diffraction pattern


  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "inten_two_ten.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";

  # 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 '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 style line 6 lt rgb 'black' lw 3  \n";



  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'Normalized itensity'  \n";
  printf CMDFILE "set xlabel 'Distance from center of pattern (m)' \n";
  printf CMDFILE "set title 'Two- and ten-slit  d = 0.4 mm, L = 10 m, lambda = 550 nm' \n";
  
  $xmin = 0.0;
  $xmax = 0.10;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_tenslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 6  t '' ";
  $cmd .= " , ";
  $cmd .= "                     'calc_twoslit_inten.out' using 2:10 with lines ";
  $cmd .= "          ls 1  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;

