#!/usr/bin/perl
#

  my($output_file, $term_options);

  ########################################################################3
  #  Plot the curve of binding energy
  #

  $output_file = "./binding_a.ps";
  $term_options = "postscript color enhanced 'Helvectica,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 '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 style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Binding energy per nucleon (MeV) ' \n";
  printf CMDFILE "set xlabel 'Mass number' \n";
  
  $cmd = "plot [-5:280][] 'binding_energy.dat' index 0 using 1:6   ";
  $cmd .= "   with points ls 1 ps 0.3 pt 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`;
  }



  ########################################################################3
  #  Plot the curve of binding energy
  #    Closeup on the low-mass elements
  #

  $output_file = "./binding_b.ps";
  $term_options = "postscript color enhanced 'Helvectica,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 '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 style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Binding energy per nucleon (MeV) ' \n";
  printf CMDFILE "set xlabel 'Mass number' \n";
  printf CMDFILE "set label 1 '^{1}H'  at -0.5,0.3  \n";
  printf CMDFILE "set label 2 '^{4}He'  at 2.0,7.3  \n";
  printf CMDFILE "set label 3 '^{12}C'  at 10.5,8.0  \n";
  printf CMDFILE "set label 4 '^{16}O'  at 14.5,8.3  \n";
#  printf CMDFILE "set label 5 '^{2}D'  at 0.8,1.4  \n";
#  printf CMDFILE "set label 6 '^{3}T'  at 1.8,3.0  \n";
  
  $cmd = "plot [-2:30][] 'binding_energy.dat' index 0 using 1:6   ";
  $cmd .= "   with points ls 1 ps 0.3 pt 3  t '' ";
  $cmd .= " , ";
  $cmd .= "               'binding_energy.dat' index 1 using 1:6   ";
  $cmd .= "   with points ls 3 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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  ########################################################################3
  #  Plot the curve of binding energy
  #    Closeup on the peak 
  #

  $output_file = "./binding_c.ps";
  $term_options = "postscript color enhanced 'Helvectica,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 '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 style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Binding energy per nucleon (MeV) ' \n";
  printf CMDFILE "set xlabel 'Mass number' \n";
  printf CMDFILE "set label 4 '^{56}Fe'  at 50.0,8.9  \n";
  
  $cmd = "plot [-2:110][7:9] 'binding_energy.dat' index 0 using 1:6   ";
  $cmd .= "   with points ls 1 ps 0.3 pt 3  t '' ";
  $cmd .= " , ";
  $cmd .= "               'binding_energy.dat' index 2 using 1:6   ";
  $cmd .= "   with points ls 3 ps 2.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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






exit 0;

