#!/usr/bin/perl
#
# Plots for radial velocity lecture
# 
# MWR 3/11/2015

if (0 == 1) {
    
      ####################################################################
      #  "typical" stellar spectrum, covering visible range
      #
      # get the arguments
      $output_file = "./pickles_big_range.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [4000:8000][] ";
      $cmd .= " './ukg2v_dat' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


      ####################################################################
      #  "typical" stellar spectrum, closeup near H-beta visible range
      #
      # get the arguments
      $output_file = "./pickles_small_range.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [4800:5000][] ";
      $cmd .= " './ukg2v_dat' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with linespoints ps 1.0 pt 5 lw 2 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


if (0 == 1) {

      ####################################################################
      #  HARPS spectrum of BD 184914
      #
      # get the arguments
      $output_file = "./bd184914_a.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [5000:5020][] ";
      $cmd .= " './excerpt.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    

      ####################################################################
      #  HARPS spectrum of BD 184914 -- closeup around 5010 Angstroms
      #
      # get the arguments
      $output_file = "./bd184914_b.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [5010.5:5011.5][] ";
      $cmd .= " './excerpt.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with linespoints lw 2 pt 5 ps 0.5 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    

      ####################################################################
      #  HARPS spectrum of BD 184914 -- very closeup around 5010.8 Angstroms
      #
      # get the arguments
      $output_file = "./bd184914_c.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [5010.6:5011.0][] ";
      $cmd .= " './excerpt.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with linespoints lw 2 pt 5 ps 0.8 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    

      ####################################################################
      #  HARPS spectrum of BD 184914 -- entire spectrum
      #
      # get the arguments
      $output_file = "./bd184914_d.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [3700:7000][-2:105] ";
      $cmd .= " './BD184914_20100702_0949_full.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with lines lw 1 lt 1 lc 1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    

      ####################################################################
      #  HARPS spectrum of BD 184914 -- 4800 to 5000 Angstroms
      #    compared to Pickles spectrum of another star over same interval
      #
      # get the arguments
      $output_file = "./bd184914_e.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [4800:5000][] ";
      $cmd .= " './BD184914_20100702_0949_full.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './ukg2v_dat' ";    
      $cmd .= "    using 1:(\$2*90) ";
      $cmd .= "    t '' ";
      $cmd .= "    with linespoints ps 0.8 pt 5 lw 2 lt 1 lc -1 ";

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

    
}
    
    

      ####################################################################
      #  radial velocity due to earth spin only, over three days
      #
      # get the arguments
      $output_file = "./rv_spin_only.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Time (days) ' \n";
      printf CMDFILE "set ylabel 'Apparent radial velocity (m/s)' \n";
      printf CMDFILE "set title 'Observatory at lat=40, star at ecl. lat=30 ' \n";
      
      $cmd = "plot [-0.1:3.1][-600:600] ";
      $cmd .= " './compute_rv.out' index 0 ";
      $cmd .= "    t 'spin only' ";
      $cmd .= "    with lines lw 3 lt 1 lc 1 ";

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

    

      ####################################################################
      #  radial velocity due to earth spin and orbit, over three days
      #
      # get the arguments
      $output_file = "./rv_both_short.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key top left Left reverse \n";
      printf CMDFILE "set xlabel 'Time (days) ' \n";
      printf CMDFILE "set ylabel 'Apparent radial velocity (m/s)' \n";
      printf CMDFILE "set title 'Observatory at lat=40, star at ecl. lat=30 ' \n";
      
      $cmd = "plot [-0.1:3.1][-600:2000] ";
      $cmd .= " './compute_rv.out' index 0 using 1:2 ";
      $cmd .= "    t 'spin only' ";
      $cmd .= "    with lines lw 3 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './compute_rv.out' index 0 using 1:3 ";
      $cmd .= "    t 'orbit only' ";
      $cmd .= "    with lines lw 3 lt 1 lc 3 ";
      $cmd .= " , ";
      $cmd .= " './compute_rv.out' index 0 using 1:4 ";
      $cmd .= "    t 'combined' ";
      $cmd .= "    with lines lw 3 lt 1 lc -1 ";


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

    

      ####################################################################
      #  radial velocity due to earth spin and orbit, over ninety days
      #
      # get the arguments
      $output_file = "./rv_both_long.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key top left Left reverse \n";
      printf CMDFILE "set xlabel 'Time (days) ' \n";
      printf CMDFILE "set ylabel 'Apparent radial velocity (m/s)' \n";
      printf CMDFILE "set title 'Observatory at lat=40, star at ecl. lat=30 ' \n";
      
      $cmd = "plot [-0.1:90.1][-600:] ";
      $cmd .= " './compute_rv.out' index 0 using 1:2 ";
      $cmd .= "    t 'spin only' ";
      $cmd .= "    with lines lw 3 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './compute_rv.out' index 0 using 1:3 ";
      $cmd .= "    t 'orbit only' ";
      $cmd .= "    with lines lw 3 lt 1 lc 3 ";
      $cmd .= " , ";
      $cmd .= " './compute_rv.out' index 0 using 1:4 ";
      $cmd .= "    t 'combined' ";
      $cmd .= "    with lines lw 3 lt 1 lc -1 ";


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

    
}
    
if (0 == 1) {

      ####################################################################
      #  Spectra of several stars from Elodie
      #
      # get the arguments
      $output_file = "./elodie_a.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [5000:5020][50000:380000] ";
      $cmd .= " './elodie_hd113139.dat' index 0 ";
      $cmd .= "    using (\$1):(\$2*4.0) ";
      $cmd .= "    t 'HD 113139' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './elodie_hd27808.dat' index 0 ";
      $cmd .= "    t 'HD 27808' ";
      $cmd .= "    with lines lw 2 lt 1 lc 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/.eps/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    
      ####################################################################
      #  Spectra of several stars from Elodie
      #     (now label the rotation speed)
      #
      # get the arguments
      $output_file = "./elodie_b.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      
      $cmd = "plot [5000:5020][50000:380000] ";
      $cmd .= " './elodie_hd113139.dat' index 0 ";
      $cmd .= "    using (\$1):(\$2*4.0) ";
      $cmd .= "    t 'HD 113139: F2V  vrot = 100 km/s' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './elodie_hd27808.dat' index 0 ";
      $cmd .= "    t 'HD 27808:   F8V  vrot =     6 km/s' ";
      $cmd .= "    with lines lw 2 lt 1 lc 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/.eps/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    
    
      ####################################################################
      #  Spectra of several stars of different spectral class from Elodie
      #
      # get the arguments
      $output_file = "./elodie_c.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
#      printf CMDFILE "set key top right Left \n";
      printf CMDFILE "set nokey \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      printf CMDFILE "set label 1 at 5001,20000 'BD+44 4548' \n";
      printf CMDFILE "set label 2 at 5001,160000 '51 Peg' \n";
      printf CMDFILE "set label 3 at 5001,440000 'HD 27808' \n";
      printf CMDFILE "set label 4 at 5001,560000 'eps Aur' \n";

      
      $cmd = "plot [5000:5020][] ";
      $cmd .= " './elodie_epsaur.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*1.0) ";
      $cmd .= "    t 'eps Aug' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './elodie_hd27808.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*1.5) ";
      $cmd .= "    t 'HD 27808' ";
      $cmd .= "    with lines lw 2 lt 1 lc 3 ";
      $cmd .= " , ";
      $cmd .= " './elodie_51peg.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*8.0) ";
      $cmd .= "    t '51 Peg' ";
      $cmd .= "    with lines lw 2 lt 1 lc 4 ";
      $cmd .= " , ";
      $cmd .= " './elodie_bd444548.dat' index 0 ";
      $cmd .= "    using (\$1):(\$2*24.0) ";
      $cmd .= "    t 'BD+44 4548' ";
      $cmd .= "    with lines lw 2 lt 1 lc -1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    
      ####################################################################
      #  Spectra of several stars of different spectral class from Elodie
      #      with labels for spectral class
      #
      # get the arguments
      $output_file = "./elodie_d.ps";
      $term_options = "postscript color enhanced 'Helvetica,22' ";
    
      $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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
#      printf CMDFILE "set key top right Left \n";
      printf CMDFILE "set nokey \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flam (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      printf CMDFILE "set label 1 at 5001,20000 'BD+44 4548  (M2V)' \n";
      printf CMDFILE "set label 2 at 5001,160000 '51 Peg   (G2.5V) ' \n";
      printf CMDFILE "set label 3 at 5001,440000 'HD 27808   (F8V) ' \n";
      printf CMDFILE "set label 4 at 5001,560000 'eps Aur  (O8Iab) ' \n";

      
      $cmd = "plot [5000:5020][] ";
      $cmd .= " './elodie_epsaur.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*1.0) ";
      $cmd .= "    t 'eps Aug' ";
      $cmd .= "    with lines lw 2 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " './elodie_hd27808.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*1.5) ";
      $cmd .= "    t 'HD 27808' ";
      $cmd .= "    with lines lw 2 lt 1 lc 3 ";
      $cmd .= " , ";
      $cmd .= " './elodie_51peg.dat' index 0 ";
      $cmd .= "    using (\$1):(100000+\$2*8.0) ";
      $cmd .= "    t '51 Peg' ";
      $cmd .= "    with lines lw 2 lt 1 lc 4 ";
      $cmd .= " , ";
      $cmd .= " './elodie_bd444548.dat' index 0 ";
      $cmd .= "    using (\$1):(\$2*24.0) ";
      $cmd .= "    t 'BD+44 4548' ";
      $cmd .= "    with lines lw 2 lt 1 lc -1 ";
    
  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/.png/;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

    
    
}
    
    

      ####################################################################
      #  HARPS spectrum of BD 184914 -- very closeup around 5010.8 Angstroms
      #    with a pseudo-fitted absorption line
      #
      # get the arguments
      $output_file = "./bd184914_f.ps";
      $term_options = "postscript color enhanced '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 size 1.0,1.0 \n";
      printf CMDFILE "set grid \n";
      printf CMDFILE "set key bot left Left reverse \n";
      printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
      printf CMDFILE "set ylabel 'Flux (arbitrary units)' \n";
      printf CMDFILE "set title '' \n";
      printf CMDFILE "set arrow 1 from 5010.745,60 to 5010.745,63.5 \n";

      # this is only an approximate model, fit by eye
      printf CMDFILE "A = 1.5 \n";
      printf CMDFILE "c = 5010.745 \n";
      printf CMDFILE "s = 0.02 \n";
      printf CMDFILE "f(x) = 65.5-A*exp(-(x-c)*(x-c)/(s*s)) \n";
      
      $cmd = "plot [5010.6:5011.0][] ";
      $cmd .= " './excerpt.txt' index 0 ";
      $cmd .= "    t '' ";
      $cmd .= "    with linespoints lw 2 pt 5 ps 0.8 lt 1 lc 1 ";
      $cmd .= " , ";
      $cmd .= " f(x) with lines lc 3 lw 2  t '' \n";

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

    
    




exit 0;
