#!/usr/bin/perl

print <<"EOT";
<table cellspacng=5 cellpadding=5>
<tr>
   <td><i>composer</i></td>
   <td><i>modules</i></td>
   <td><i>contrary</i></td>
   <td><i>similar</i></td>
   <td><i>similar up</i></td>
   <td><i>similar down</i></td>
</tr>
EOT

ProcessEntry("J.S. Bach Chorales", "h://370chorales");
ProcessEntry("Josquin", "h://jrp/Jos");
ProcessEntry("Ockeghem", "h://jrp/Ock");

print "</table>\n";

##################################################################################

sub ProcessEntry {
   my ($name, $uri) = @_;

   # All hard modules
   $all = `cint $uri -Hts --chromatic --raw | egrep -v "p1[sx]|R|s" | wc -l`;

   # Similar motion, going down:
   $down = `cint $uri -Hts --chromatic --raw | egrep -v "p1[sx]|R|s" | grep -- "-.*-" | wc -l`;

   # Contrary motion:
   $cont = `cint $uri -Hts --chromatic --raw | egrep -v "p1[sx]|R|s" | grep -- - | grep -v -- "-.*-" | wc -l`;

   # Similar motion, going up:
   $up = `cint $uri -Hts --chromatic --raw | egrep -v "p1[sx]|R|s" | grep -v -- - | wc -l`;

   chomp $all;
   chomp $up;
   chomp $down;
   chomp $cont;

   $upcent = $up / $all * 100.0;
   $downcent = $down / $all * 100.0;
   $contcent = $cont / $all * 100.0;
   $simcent = $upcent + $downcent;
   $similar = $up + $down;

print <<"EOT";
<tr>
   <td>$name</td>
   <td><i>$all<br>100%</i></td>
   <td><i>$cont<br>$contcent%</i></td>
   <td><i>$similar<br>$simcent%</i></td>
   <td><i>$up<br>$upcent%</i></td>
   <td><i>$down<br>$downcent%</i></td>
</tr>
EOT

}

