#!/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";
  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";

  
  $cmd = "plot [-1:5][0:6] './scale_3.50.dat' using 1:9 ";
  $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:9 ";
  $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:9 ";
  $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 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";
  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";

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