#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # get the arguments
  $output_file = "other_pie_a.ps";
  $term_options = "postscript 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 "unset border \n";
  printf CMDFILE "unset tics \n";
  printf CMDFILE "b=0.25 \n";
  printf CMDFILE "s=0.05 \n";
  printf CMDFILE "B=0.50 \n";

# oxygen 0.360 = 129.6 deg, carbon 0.246 = 88.6, 
# nitrogen 0.077 = 27.7, neon 0.075 = 27.0,
# silicon 0.022 = 7.92, magnesium 0.021 = 7.56 , iron 0.020 = 7.20

  printf CMDFILE "a1=129.6 \n";
  printf CMDFILE "a2=a1+88.6 \n";
  printf CMDFILE "a3=a2+27.7 \n";
  printf CMDFILE "a4=a3+27.0 \n";
  printf CMDFILE "a5=a4+7.92 \n";
  printf CMDFILE "a6=a5+7.56 \n";
  printf CMDFILE "a7=a6+7.20 \n";

  printf CMDFILE "set angles degree \n";
  printf CMDFILE "set yrange [0:1] \n";
  printf CMDFILE "set style fill solid 1.0 border -1 \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set obj 1 circle arc [0:a1] fc rgb 'light-blue' \n";
  printf CMDFILE "set obj 2 circle arc [a1:a2] fc rgb 'orange' \n";
  printf CMDFILE "set obj 3 circle arc [a2:a3] fc rgb 'aquamarine' \n";
  printf CMDFILE "set obj 4 circle arc [a3:a4] fc rgb 'violet' \n";
  printf CMDFILE "set obj 5 circle arc [a4:a5] fc rgb 'light-salmon' \n";
  printf CMDFILE "set obj 6 circle arc [a5:a6] fc rgb 'light-gray' \n";
  printf CMDFILE "set obj 7 circle arc [a6:a7] fc rgb 'light-green' \n";
  printf CMDFILE "set obj 8 circle arc [a7:360] fc rgb 'white' \n";

  printf CMDFILE "set obj 1 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 2 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 3 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 4 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 5 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 6 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 7 circle at screen B,B size screen b front \n";
  printf CMDFILE "set obj 8 circle at screen B,B size screen b front \n";

  printf CMDFILE "plot 2 \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/.ps/.png/;
    $cmd = "convert -rotate 90 -background white -flatten $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



exit 0;
