#!/usr/bin/perl
#
# Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
# Creation Date: Sun Jul  9 16:11:04 PDT 2000
# Last Modified: Sun Jul  9 16:11:04 PDT 2000
# Filename:      ...sig/doc/examples/all/tempojnd/parseraw
# Syntax:        perl 5
#
# Description:   Takes raw data from tempojnd and generates analysis
#

use strict;

if (@ARGV != 1) {
   print "Usage: $0 input-data-file\n";
   exit(1);
}

my $infile = @ARGV[0];

unless (open(INPUT, "$infile")) {
   print "Error: cannot open $infile\n";
   exit(1);
}


my @correct;
my @incorrect;


my $last = -1;
my $value;
while (<INPUT>) {
   /^\s*([0-9]+)/;
   $value = $1;
   next if $value eq ""; 
   if ($last == -1) {
      $last = $value;
      next;
   }

   if ($value < $last) {
      $correct[$last]++;
   } else {
      $incorrect[$last]++;
   }   
 
   $last = $value;

}

my $vi;
my $vs;
my $vc;
my $i;
my $percent;
for ($i=1; $i<45; $i++) {
   $vc = $correct[$i];
   $vi = $incorrect[$i];
   $vs = $vi + $vc;
   $percent = $vc/$vs * 100;
   print"$i ms\ttrials = $vs\tcorrect = $percent\n";
}

