#!/usr/bin/perl
#
# Create animated GIF of the transit
#
# MWR 4/26/2016

$debug = 1;

  # create GIF copies
  @files = glob("c_transit*png");
  foreach $file (@files) {
    $new = $file;
    $new =~ s/.png/.gif/;
    $cmd = "convert $file $new";
    $ret = exec_cmd($cmd);
  }

  # now merge the GIFs into an animation
  $output_anim = "c_anim.gif";
  @gifs = glob("c_transit*gif");
  $cmd = "gifmerge ";
  $cmd .= "   -l0  -100 ";
  foreach $gif (@gifs) {
    $cmd .= " $gif ";
  }
  $cmd .= " > $output_anim ";
  $ret = exec_cmd($cmd);

   

exit 0;





##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}


