#!/usr/bin/perl
#

$filter = "";
$filter_lc = lc($filter);
$mag_offset =  0.0;
$aper = "4";
$suffix = sprintf "dat%s", $aper;




############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "./line_nolabel.ps";
  $term_options = "postscript color enhanced \"Helvetica\" 20 ";

  $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 nokey \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms)' \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary units)' \n";
  printf CMDFILE "set title 'An absorption line in the solar spectrum'\n", $aper;
  
  $cmd = "plot [6545.0:6548.0][0:11000] 'spec_closeup.dat' using (\$1-0):(\$2-0)   with points lt 1 pt 1 lw 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/.ps/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




############################################################################
# create a file with GNUPLOT commands, then execute GNUPLOT to read
#   from that file.
#
# usage:  make_graph   outfile_file_name  set_term_options
#
  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "./linear_test.ps";
  $term_options = "postscript color enhanced \"Helvetica\" 20 ";

  $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 reverse width -8 \n";
  printf CMDFILE "set xlabel '{({/Symbol=n} - {/Symbol=n}_0)}^2  (Hz)' \n";
  printf CMDFILE "set ylabel 'quantity based on gaussian or lorentzian' \n";
  printf CMDFILE "set title 'Does a Gaussian or Lorentzian function fit better?'\n", $aper;
  
  $cmd = "plot [][] 'calc_prof.out' using (\$3-0):(\$4-0)   with points lt 3 pt 2 lw 1 t 'Lorentzian' ";
  $cmd .= " , ";
  $cmd .= " 'calc_prof.out' using (\$3-0):(\$5*6.0-0)   with points lt 2 ps 2 pt 1 lw 3 t 'Gaussian' ";
  $cmd .= " , ";
  $cmd .= "  2.722106e-01+1.667491e-19*x with lines lt 3 lw 7 t 'linear fit to Lorentzian' ";
  $cmd .= " , ";
  $cmd .= "  (-3.704391e-01)*6.0-(3.177430e-20)*6.0*x with lines lt -1 t 'linear fit to Gaussian' ";

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




exit 0;
