#!/usr/bin/perl
#
# Create HTML files which allow user to click 
#   rapidly from one graph to the next
#
# MWR 6/16/2011


$debug = 1;

$template = "start.html";


@files = glob("macho*resid.png");
$nfile = 0;
foreach $file (@files) {
  $file_array[$nfile] = $file;
  if ($debug > 0) {
    printf " file %3d is ..%s.. \n", $nfile, $file_array[$nfile];
  }
  $nfile++;
}

for ($i = 0; $i < 50; $i++) {
  $new = $file_array[$i];
  $new =~ s/.png/.html/;
  if ($debug > 0) {
    printf "new is ..$new.. \n";
  }
  open(NEW, ">$new") || die("cannot open file $new");

  $this = $file_array[$i];
  $next = $file_array[$i+1];
  $next =~ s/.png/.html/;
  if ($debug > 0) {
    printf "next is ..$next.. \n";
  }

  open(TEMPLATE, "$template") || die("cannot open file $template");
  while (<TEMPLATE>) {
    $line = $_;
    chomp($line);
    $line =~ s/foo1/$next/;
    $line =~ s/foo2/$this/;
    printf NEW "%s \n", $line;

  }
  close(TEMPLATE);


  close(NEW);


}







exit 0;

