#!/usr/bin/perl
#

$min_lambda = 380.0;
$max_lambda = 500.0;

# plot the spectrum of G0V star, as a reference
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "spec_g0v.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a motionless G0V star '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][0.2:1.5] ";
  $cmd .= " 'ukg0v_dat' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


# plot the spectrum of galaxy in Virgo cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./virgo_spec_smooth.dat";
  $output_file = "spec_virgo.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Virgo cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



# plot the spectrum of galaxy in Coma cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./coma_spec_smooth.dat";
  $output_file = "spec_coma.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Coma cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



# plot the spectrum of galaxy in Corona Borealis cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./corbor_2_spec_smooth.dat";
  $output_file = "spec_corbor.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Corona Borealis cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



# plot the spectrum of galaxy in Ursa Majoris I cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./uma1_spec_smooth.dat";
  $output_file = "spec_uma1.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Ursa Majoris I cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




# plot the spectrum of galaxy in Ursa Majoris II cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./uma2_spec_smooth.dat";
  $output_file = "spec_uma2.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Ursa Majoris II cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




# plot the spectrum of galaxy in Bootes cluster 
  
  my($output_file, $term_options);

  # get the arguments
  $input_file = "./bootes_spec_smooth.dat";
  $output_file = "spec_bootes.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy in the Bootes cluster '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][0:7] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



# plot the spectrum of galaxy at z=0.5, shifted by a nice amount
  
  my($output_file, $term_options);

  # get the arguments
$min_lambda = 560;
$max_lambda = 690;
  $input_file = "./gal_0_5_spec_smooth10.dat";
  $output_file = "spec_gal_0_5.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy at high redshift '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




# plot the spectrum of galaxy at z=1.0, shifted by a nice amount
  
  my($output_file, $term_options);

  # get the arguments
$min_lambda = 780;
$max_lambda = 900;
  $input_file = "./gal_1_0_spec_smooth10.dat";
  $output_file = "spec_gal_1_0.ps";
  $term_options = "postscript mono enhanced ";

  $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 xlabel 'Observed wavelength (nm) ' \n";
  printf CMDFILE "set ylabel 'Intensity of light (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of a galaxy at very high redshift '\n";
  
  $cmd = "plot [$min_lambda:$max_lambda][] ";
  $cmd .= " '$input_file' using (\$1*0.1):2 with lines lt 1 lw 2 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'ukg0v_dat' using (\$1*0.1*(1.0+1.077)):(\$2*2+1) with lines lt 2 lw 1 t 'shifted G0V star'  ";
 

  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/.eps/.gif/;
    $giffile =~ s/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }







exit 0;

