#!/usr/bin/perl
#

  
  ###############################################################
  #  Make a plot showing brehm emissivity vs. temp
  #
  # get the arguments
  $output_file = "brem_emis.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (eV) ' \n";
  printf CMDFILE "set ylabel 'Emissivity (erg/s/cm^3/Hz)' \n";
  printf CMDFILE "set title 'Brehmsstrahlung radiation from hydrogen n=10^{10} per cm^3 ' \n";


  
  $cmd = "plot [0.05:200][1e-16:1e-12] './calc_brem.out' index 4 using 8:10 ";
  $cmd .= "  with points lc 1 lw 3 t 'T = 10 million K'  ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem.out' index 2 using 8:10 ";
  $cmd .= "  with points lc 2 lw 3 t '1 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem.out' index 0 using 8:10 ";
  $cmd .= "  with points lc 3 lw 3 t '0.1 million K' ";

  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 a plot showing brehm photons vs. temp
  #
  # get the arguments
  $output_file = "brem_photons.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (keV) ' \n";
  printf CMDFILE "set ylabel 'Number of photons emitted (per sec-cm^3)' \n";
  printf CMDFILE "set title 'Brehmsstrahlung radiation from hydrogen n=10^{10} per cm^3 ' \n";


  
  $cmd = "plot [0.08:20][1e17:4e20] './calc_brem_counts.out' index 6 using 8:12 ";
  $cmd .= "  with linespoints lc 1 lw 3 t 'T = 100 million K'  ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts.out' index 5 using 8:12 ";
  $cmd .= "  with linespoints lc 2 lw 3 t 'T = 32 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts.out' index 4 using 8:12 ";
  $cmd .= "  with linespoints lc 3 lw 3 t 'T = 10 million K' ";

  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 a plot showing absorption cross section vs. energy
  #
  # get the arguments
  $output_file = "cross_abs.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (keV) ' \n";
  printf CMDFILE "set ylabel 'cross-section (per cm^2) ' \n";
  printf CMDFILE "set title 'Absorption by ISM from Morrison and McCammon, ApJ 270, 119 (1983) ' \n";

  
  $cmd = "plot [0.08:20][] './cross_morrison.dat' using 2:4 ";
  $cmd .= "  with lines lc 1 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  
  ###############################################################
  #  Make a plot showing brehm photons vs. temp
  #     in the presence of 10^(21) column density
  #
  # get the arguments
  $output_file = "brem_photons_abs_1e21.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (keV) ' \n";
  printf CMDFILE "set ylabel 'Number of photons observed (per sec-cm^3)' \n";
  printf CMDFILE "set title 'Brehmsstrahlung radiation observed through N_H = 10^{21} cm^{-2} ' \n";


  
  $cmd = "plot [0.08:20][1e17:2e20] './calc_brem_counts_abs.1e21.out' index 6 using 8:12 ";
  $cmd .= "  with lines lc 1 lw 3 t 'T = 100 million K'  ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e21.out' index 6 using 8:14 ";
  $cmd .= "  with points lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e21.out' index 5 using 8:12 ";
  $cmd .= "  with lines lc 2 lw 3 t 'T = 32 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e21.out' index 5 using 8:14 ";
  $cmd .= "  with points lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e21.out' index 4 using 8:12 ";
  $cmd .= "  with lines lc 3 lw 3 t 'T = 10 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e21.out' index 4 using 8:14 ";
  $cmd .= "  with points lc 3 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  
  ###############################################################
  #  Make a plot showing brehm photons vs. temp
  #     in the presence of 10^(22) column density
  #
  # get the arguments
  $output_file = "brem_photons_abs_1e22.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (keV) ' \n";
  printf CMDFILE "set ylabel 'Number of photons observed (per sec-cm^3)' \n";
  printf CMDFILE "set title 'Brehmsstrahlung radiation observed through N_H = 10^{22} cm^{-2} ' \n";


  
  $cmd = "plot [0.08:20][1e17:2e20] './calc_brem_counts_abs.1e22.out' index 6 using 8:12 ";
  $cmd .= "  with lines lc 1 lw 3 t 'T = 100 million K'  ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e22.out' index 6 using 8:14 ";
  $cmd .= "  with points lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e22.out' index 5 using 8:12 ";
  $cmd .= "  with lines lc 2 lw 3 t 'T = 32 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e22.out' index 5 using 8:14 ";
  $cmd .= "  with points lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e22.out' index 4 using 8:12 ";
  $cmd .= "  with lines lc 3 lw 3 t 'T = 10 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e22.out' index 4 using 8:14 ";
  $cmd .= "  with points lc 3 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

  
  ###############################################################
  #  Make a plot showing brehm photons vs. temp
  #     in the presence of 10^(20) column density
  #
  # get the arguments
  $output_file = "brem_photons_abs_1e20.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Energy (keV) ' \n";
  printf CMDFILE "set ylabel 'Number of photons observed (per sec-cm^3)' \n";
  printf CMDFILE "set title 'Brehmsstrahlung radiation observed through N_H = 10^{20} cm^{-2} ' \n";


  
  $cmd = "plot [0.08:20][1e17:2e20] './calc_brem_counts_abs.1e20.out' index 6 using 8:12 ";
  $cmd .= "  with lines lc 1 lw 3 t 'T = 100 million K'  ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e20.out' index 6 using 8:14 ";
  $cmd .= "  with points lc 1 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e20.out' index 5 using 8:12 ";
  $cmd .= "  with lines lc 2 lw 3 t 'T = 32 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e20.out' index 5 using 8:14 ";
  $cmd .= "  with points lc 2 lw 3 t '' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e20.out' index 4 using 8:12 ";
  $cmd .= "  with lines lc 3 lw 3 t 'T = 10 million K' ";
  $cmd .= " , ";
  $cmd .= "    './calc_brem_counts_abs.1e20.out' index 4 using 8:14 ";
  $cmd .= "  with points lc 3 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/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  
  ###############################################################
  #  Make a plot showing brehmsstrahlung emission
   #    from a galaxy cluster which is isothermal sphere
  #
  # get the arguments
  $output_file = "cluster_spec_a.ps";
  $term_options = "postscript enhanced color '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";
  #printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  #printf CMDFILE "set xtics (2000,4000,6000) \n";
  #printf CMDFILE "set ytics (0.4,0.8,1.0,4.0) \n";
  printf CMDFILE "set xlabel 'Distance from center of cluster (kpc)' \n";
  printf CMDFILE "set ylabel 'Number of photons observed per sec' \n";
  printf CMDFILE "set title 'Brehmsstrahlung emission from isothermal cluster, T = 10^8 K ' \n";
  printf CMDFILE "set label 1 at 8,5e19 'r^{-1.9}'  \n";
  printf CMDFILE "set label 2 at 5,3e15 'r^{-3.1}'  \n";


  
  $cmd = "plot [0.05:30][1e14:1e23] './calc_cluster_total.B.out' using (\$2+0.0):6 ";
  $cmd .= "  with points lc 1 pt 6 lw 2 t '{/Symbol b} = 0.8'  ";
  $cmd .= " , ";
  $cmd .= "  './calc_cluster_total.A.out' using (\$2+0.0):6 ";
  $cmd .= "  with points lc 2 pt 5 lw 2 t '{/Symbol b} = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "  './calc_cluster_total.C.out' using (\$2+0.0):6 ";
  $cmd .= "  with points lc 3 pt 4 lw 2 t '{/Symbol b} = 1.2'  ";
  $cmd .= " , ";
  $cmd .= " './calc_beta_asymp.out' index 0 using 1:2 with lines lt 1 t '' ";
  $cmd .= " , ";
  $cmd .= " './calc_beta_asymp.out' index 1 using 1:2 with lines lt 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`;
  }





exit 0;

