#!/usr/bin/perl

#
# Converts data outputted by compute_avg to a LaTex table.
#
# rawdata2tex [nb_cols]
#
# nb_cols - if specified, if no data, column with empty cells still
#           created.
#

if ($#ARGV == 0) {
    $nb_cols = $ARGV[0];
} else {
    $nb_cols = 0;
}

$name = <STDIN>;
do {
    $data = <STDIN>;
    #$first = 1;
    chomp($name);
    print "{\\bf $name}";
    $count = 0;
    while ($data =~ /^  /) {
	$data =~ /^  \S* (\S*) .* comp: (\S*)$/;
	$total = $1;
	$comp_time = $2;
	#if (!$first) {
	#print " \& $1 & $2 & (" + ($2 / $1 * 100) + ") ";
	$comp_percent = $2 / $1 * 100;
	printf " \& $2 & $1 & (%3.2f) ", $comp_percent;
	$count = $count + 1;
	#} else {
	#    print "{\bf $name} & $1";
	#    $first = 0;
	#}
	$data = <STDIN>;
	#print "data: $data\n";
    }

    # empty column
    if ($count == 0) {
	for ($i = 0; $i < $nb_cols; $i++) {
	    print " &";
	}
    } elsif ($count < $nb_cols) {
	print STDERR "Warning partially filled row may not match columns!";
    }
    print "\\\\\\hline\n";
    $name = $data;

} while ($name);
