#!/usr/bin/perl
#
  
  ###############################################################
  #  Make a graph showing scale factor as function of time
  #     for open, critical, closed values of Omega_M
  #
  $output_file = "scale_omegam_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";

  #  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 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 'Time (Hubble times from present) ' \n";
  printf CMDFILE "set ylabel 'Scale factor a' \n";
  printf CMDFILE "set title 'Newtonian universe with matter only ' \n";

  printf CMDFILE "set arrow 1 from 0.0,3.2 to 0.0,2.5  \n";
  printf CMDFILE "set label 1 at -0.1,3.5 'now' font 'Helvetica-Bold,18'  \n";
  
  $cmd = "plot [-1:5][0:6] './scale_35_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 1 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 3.5'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_10_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 2 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_03_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 3  pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 0.3'  ";

  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 graph showing scale factor as function of time
  #     for open, critical, closed values of Omega_M
  #     Zoom in on time near present
  #
  $output_file = "scale_omegam_b.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";

  #  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 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 'Time (Hubble times from present) ' \n";
  printf CMDFILE "set ylabel 'Scale factor a' \n";
  printf CMDFILE "set title 'Newtonian universe with matter only ' \n";

  printf CMDFILE "set arrow 1 from 0.0,1.33 to 0.0,1.10 \n";
  printf CMDFILE "set label 1 at -0.03,1.45 'now' font 'Helvetica-Bold,18'  \n";
  

  
  $cmd = "plot [-0.5:0.5][] './scale_35_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 1 pt 4 ps 0.3  ";
  $cmd .= "      t '{/Symbol W}_M = 3.5'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_10_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 2 pt 4 ps 0.3  ";
  $cmd .= "      t '{/Symbol W}_M = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_03_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 3 pt 4 ps 0.3  ";
  $cmd .= "      t '{/Symbol W}_M = 0.3'  ";

  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 graph showing scale factor as function of time
  #     for various combinations of Omega_M and Omega_Lambda
  #
  $output_file = "scale_with_lambda_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";

  #  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 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 'Time (Hubble times from present) ' \n";
  printf CMDFILE "set ylabel 'Scale factor a' \n";
  printf CMDFILE "set title 'Newtonian universe with matter and lambda ' \n";

  #printf CMDFILE "set arrow 1 from 0.0,3.2 to 0.0,2.5  \n";
  #printf CMDFILE "set label 1 at -0.1,3.5 'now' font 'Helvetica-Bold,18'  \n";
  
  $cmd = "plot [-1:5][0:6] './scale_35_00.dat' using 1:9 ";
  $cmd .= "  with points  ls 1 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 3.5  {/Symbol W}_{/Symbol L} = 0.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_35_02.dat' using 1:9 ";
  $cmd .= "  with points  ls 2 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 3.5  {/Symbol W}_{/Symbol L} = 0.2'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_35_03.dat' using 1:9 ";
  $cmd .= "  with points  ls 3  pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 3.5  {/Symbol W}_{/Symbol L} = 0.3'  ";

  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 graph showing scale factor as function of time
  #     for various combinations of Omega_M and Omega_Lambda
  #     This combination has Omega_M = 0.3 and various Lambdas
  #
  $output_file = "scale_with_lambda_b.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";

  #  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 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 'Time (Hubble times from present) ' \n";
  printf CMDFILE "set ylabel 'Scale factor a' \n";
  printf CMDFILE "set title 'Newtonian universe with matter and lambda ' \n";

  #printf CMDFILE "set arrow 1 from 0.0,3.2 to 0.0,2.5  \n";
  #printf CMDFILE "set label 1 at -0.1,3.5 'now' font 'Helvetica-Bold,18'  \n";
  
  $cmd = "plot [-1:5][0:6] './scale_03_005.dat' using 1:9 ";
  $cmd .= "  with points  ls 1 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 0.3  {/Symbol W}_{/Symbol L} = 0.05'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_03_01.dat' using 1:9 ";
  $cmd .= "  with points  ls 2 pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 0.3  {/Symbol W}_{/Symbol L} = 0.1  '  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_03_03.dat' using 1:9 ";
  $cmd .= "  with points  ls 3  pt 4 ps 0.5  ";
  $cmd .= "      t '{/Symbol W}_M = 0.3  {/Symbol W}_{/Symbol L} = 0.3  '  ";

  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 a graph showing redshift as function of time
  #     for open, critical, closed values of Omega_M
  #
  $output_file = "redshift_time.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 'Time (Hubble times from present) ' \n";
  printf CMDFILE "set ylabel 'redshift z' \n";
  printf CMDFILE "set title 'Newtonian universe with matter only ' \n";

  
  $cmd = "plot [-1.0:-0.001][0.0:9.9] './scale_3.50.dat' using 1:11 ";
  $cmd .= "  with points  pt 4 ps 0.5 lt 1 lc 1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 3.5'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_1.00.dat' using 1:11 ";
  $cmd .= "  with points  pt 4 ps 0.5 lt 1 lc -1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './scale_0.20.dat' using 1:11 ";
  $cmd .= "  with points  pt 4 ps 0.5 lt 1 lc 3 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 0.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`;
  }

  
  ###############################################################
  #  Make a graph showing proper distance as function of redshift
  #     for open, critical, closed values of Omega_M
  #
  $output_file = "propdist_z.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 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 'redshift z' \n";
  printf CMDFILE "set ylabel 'proper distance (Mpc)' \n";
  printf CMDFILE "set title 'Newtonian universe with matter only, H_0 = 70 ' \n";

  
  $cmd = "plot [-0.03:0.6][] './calc_omega.out' using 2:8 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc 1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 3.5'  ";
  $cmd .= " , ";
  $cmd .= "                 './calc_omega.out' using 2:6 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc -1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './calc_omega.out' using 2:4 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc 3 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 0.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`;
  }


  
  ###############################################################
  #  Make a graph showing proper distance as function of redshift
  #     for open, critical, closed values of Omega_M
  #     Closeup on very small distances.
  #
  $output_file = "propdist_z_2.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 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 'redshift z' \n";
  printf CMDFILE "set ylabel 'proper distance (Mpc)' \n";
  printf CMDFILE "set title 'Newtonian universe with matter only, H_0 = 70 ' \n";

  
  $cmd = "plot [-0.003:0.06][] './calc_omega.out' using 2:8 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc 1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 3.5'  ";
  $cmd .= " , ";
  $cmd .= "                 './calc_omega.out' using 2:6 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc -1 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 1.0'  ";
  $cmd .= " , ";
  $cmd .= "                 './calc_omega.out' using 2:4 ";
  $cmd .= "  with linespoints  pt 4 ps 0.5 lt 1 lc 3 lw 3 ";
  $cmd .= "      t '{/Symbol W}_M = 0.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;
