#!/usr/bin/perl
#

##########################################
#  make graph showing intensity of single-slit diffraction pattern
#    in terms of the quantity (lambda/a)

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "bright_a.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 'Angular distance from center of pattern ({/Symbol l}/a)' \n";
  printf CMDFILE "set title 'Intensity of single-slit diffraction ' \n";
  
  $xmin = 0.0;
  $xmax = 4.0;
  

  $cmd = "plot [$xmin:$xmax][] 'calc_bright.out' using 8:14 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 single-slit diffraction pattern
#    in terms of the quantity (lambda/a)
# 
#  This graph zooms in on the first few dark and bright spots

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "bright_b.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 2 dt 2  \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 'Angular distance from center of pattern ({/Symbol l}/a)' \n";
  printf CMDFILE "set title 'Intensity of single-slit diffraction ' \n";

  printf CMDFILE "set arrow 1 from 1.5,0.00 to 1.5,0.05 nohead ls 3 \n";
  printf CMDFILE "set arrow 2 from 2.5,0.00 to 2.5,0.05 nohead ls 3 \n";
  
  $xmin = 0.8;
  $xmax = 3.0;
  
  

  $cmd = "plot [$xmin:$xmax][] 'calc_bright.out' using 8:14 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 single-slit diffraction pattern
#    in terms of the quantity (lambda/a)
# 
#  This graph shows a combination of the sine-squared term,
#    the (1/x)-squared term, and their product

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "bright_c.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 2  \n";
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 2 dt 2  \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 2  \n";



  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Arbitrary itensity'  \n";
  printf CMDFILE "set xlabel 'Angular distance from center of pattern ({/Symbol l}/a)' \n";
  printf CMDFILE "set title 'Intensity of single-slit diffraction ' \n";

  #printf CMDFILE "set arrow 1 from 1.5,0.00 to 1.5,0.05 nohead ls 3 \n";
  #printf CMDFILE "set arrow 2 from 2.5,0.00 to 2.5,0.05 nohead ls 3 \n";
  
  $xmin = 0.8;
  $xmax = 3.0;
  
  

  $cmd = "plot [$xmin:$xmax][] 'calc_bright.out' using 8:10 with lines ";
  $cmd .= "          ls 6  t 'sine-squared' ";
  $cmd .= " , ";
  $cmd .= "                    'calc_bright.out' using 8:(1.0/(\$8*\$8)) with lines ";
  $cmd .= "          ls 2  t '(1/x^2)' ";
  $cmd .= " , ";
  $cmd .= "                    'calc_bright.out' using 8:(\$10/(\$8*\$8)) with lines ";
  $cmd .= "          ls 1  t 'sine-squared*(1/x^2)' ";


  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;


##########################################
#  make graph showing 2,2 pattern
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "map_2_2.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 10,10 ";

  $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 size square \n";
  printf CMDFILE "set ylabel 'Y'  \n";
  printf CMDFILE "set xlabel 'X' \n";
  
  $cmd = "plot [0:20][0:20] 'make_map_2_2.out' using 2:1:3 with image 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 3,3 pattern
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "map_3_3.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 10,10 ";

  $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 size square \n";
  printf CMDFILE "set ylabel 'Y'  \n";
  printf CMDFILE "set xlabel 'X' \n";
  
  $cmd = "plot [0:20][0:20] 'make_map_3_3.out' using 2:1:3 with image 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 5,2 pattern
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "map_5_2.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 10,10 ";

  $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 size square \n";
  printf CMDFILE "set ylabel 'Y'  \n";
  printf CMDFILE "set xlabel 'X' \n";
  
  $cmd = "plot [0:20][0:20] 'make_map_5_2.out' using 2:1:3 with image 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;


