#!/usr/bin/perl
#

  my($output_file, $term_options);


  # First, we print just the ellipse 
  $output_file = "compare_ellipse_easy_a.ps";
  $term_options = "postscript enhanced 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 "set size square \n";
#  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set xlabel '' \n";
  printf CMDFILE "set title 'Circle or ellipse? A '\n";
  
  $cmd = "plot [-1.1:1.1][-1.1:1.1] 'compare_ellipse_easy.out' using 1:4 ";
  $cmd .= "  with lines lt 1 lc 1 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using 1:5 ";
  $cmd .= "  with lines lt 1 lc 1 lw 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/.ps$/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  # Second, we print just the ellipse 
  $output_file = "compare_ellipse_easy_b.ps";
  $term_options = "postscript enhanced 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 "set size square \n";
#  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set xlabel '' \n";
  printf CMDFILE "set title 'Circle or ellipse? B '\n";
  
  $cmd = "plot [-1.1:1.1][-1.1:1.1] 'compare_ellipse_easy.out' using 1:2 ";
  $cmd .= "  with lines lt 1 lc 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using 1:3 ";
  $cmd .= "  with lines lt 1 lc 3 lw 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/.ps$/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Third, we print them side by side
  $output_file = "compare_ellipse_easy_c.ps";
  $term_options = "postscript enhanced 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 "set size ratio 0.50 \n";
#  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set xlabel '' \n";
  printf CMDFILE "set title 'Circle or ellipse? A (red, left) and B (blue, right)'\n";
  
  $cmd = "plot [-2.5:2.5][-1.25:1.25] 'compare_ellipse_easy.out' using (\$1+1.2):2 ";
  $cmd .= "  with lines lt 1 lc 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1+1.2):3 ";
  $cmd .= "  with lines lt 1 lc 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1-1.2):4 ";
  $cmd .= "  with lines lt 1 lc 1 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1-1.2):5 ";
  $cmd .= "  with lines lt 1 lc 1 lw 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/.ps$/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Fourth, we zoom in on the very top
  $output_file = "compare_ellipse_easy_d.ps";
  $term_options = "postscript enhanced 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 "set size ratio 0.5 \n";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set ylabel '' \n";
  printf CMDFILE "set xlabel '' \n";
  printf CMDFILE "set title 'Circle or ellipse? A (red) and B (blue)'\n";
  
  $cmd = "plot [-0.50:0.50][0.55:1.05] 'compare_ellipse_easy.out' using (\$1+0.0):2 ";
  $cmd .= "  with lines lt 1 lc 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1+0.0):3 ";
  $cmd .= "  with lines lt 1 lc 3 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1-0.0):4 ";
  $cmd .= "  with lines lt 1 lc 1 lw 3 ";
  $cmd .= " , ";
  $cmd .= "                         'compare_ellipse_easy.out' using (\$1-0.0):5 ";
  $cmd .= "  with lines lt 1 lc 1 lw 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/.ps$/.png/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






exit 0;

