#!/usr/bin/perl


  my($output_file, $term_options);

  # basic graph showing regions of transmission
  #    color codes for source of data
  $output_file = "ism_a.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 grid \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set key bot right  \n";
  printf CMDFILE "set ylabel 'Extinction (mag)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Extinction in the ISM (1 atom per cc) '\n";

  printf CMDFILE "set label 1 at 1.2,300 'keV' center tc rgbcolor 'violet' \n";
  printf CMDFILE "set label 2 at 1.0e4,300 '{/Symbol m}m' center tc rgbcolor 'black' \n";

  printf CMDFILE "set label 3 at 3.65E3,70 'U' center tc rgbcolor 'blue' \n";
  printf CMDFILE "set label 4 at 5.55E3,70 'V' center tc rgbcolor 'green'  \n";
  printf CMDFILE "set label 5 at 8.50E3,70 'I' center tc rgbcolor 'red' \n";
  
  $cmd = "plot [0.3e0:2.0e5][0.01:500] ";
  $cmd .=  "  './xuv.dat' using (\$1):(\$3) ";
  $cmd .=  "      with linespoints pt 3 ps 1.0 lt 1 lc -1 lw 2 t 'per kpc' ";
  $cmd .=  " , ";
  $cmd .=  "  './uv_ext.dat' using (\$1*1e4):(\$3) ";
  $cmd .=  "      with linespoints pt 4 ps 1.0 lt 1 lc 3 lw 2 t 'rel to V' ";
  $cmd .=  " , ";
  $cmd .=  "  './uv_ext_2.dat' using (\$1*1e4):(\$3) ";
  $cmd .=  "      with linespoints pt 6 ps 1.0 lt 1 lc 4 lw 2 t 'rel to V' ";

  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`;
  }



  # basic graph showing regions of transmission
  #    color codes for source of data
  # closeup in optical
  $output_file = "ism_b.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 grid \n";
#  printf CMDFILE "set logscale x \n";
#  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set key bot right  \n";
  printf CMDFILE "set ylabel 'Extinction, relative to V-band (mag)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Extinction in the ISM '\n";

#  printf CMDFILE "set label 1 at 1.2,300 'keV' center tc rgbcolor 'violet' \n";
#  printf CMDFILE "set label 2 at 1.0e4,300 '{/Symbol m}m' center tc rgbcolor 'black' \n";

  printf CMDFILE "set label 3 at 3.65E3,70 'U' center tc rgbcolor 'blue' \n";
  printf CMDFILE "set label 4 at 5.55E3,70 'V' center tc rgbcolor 'green'  \n";
  printf CMDFILE "set label 5 at 8.50E3,70 'I' center tc rgbcolor 'red' \n";
  
  $cmd = "plot [2500:10000][0.01:3] ";
#  $cmd .=  "  './xuv.dat' using (\$1):(\$3) ";
#  $cmd .=  "      with linespoints pt 3 ps 1.0 lt 1 lc -1 lw 2 t 'per kpc' ";
#  $cmd .=  " , ";
  $cmd .=  "  './uv_ext.dat' using (\$1*1e4):(\$3) ";
  $cmd .=  "      with linespoints pt 4 ps 1.0 lt 1 lc 3 lw 2 t '' ";
  $cmd .=  " , ";
  $cmd .=  "  './uv_ext_2.dat' using (\$1*1e4):(\$3) ";
  $cmd .=  "      with linespoints pt 6 ps 1.0 lt 1 lc 4 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/.ps/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


exit 0;



