#!/usr/sww/bin/perl5
#									tab:4
#
# format.pl - program to format the memory benchmark output
#
# Copyright (c) 1995 by Chad Owen Yoshikawa and 
# Regents of the University of California
#
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that the above copyright
# notice appear in all copies.  Copyright holder(s) make no
# representation about the suitability of this software for
# any purpose. It is provided "as is" without express or
# implied warranty.
#
# Author: 			Chad Owen Yoshikawa
# Version:			33
# Creation Date:	Thu Jan 30 13:50:45 1997
# Filename:		format.pl
# History:
#

#!/usr/sww/bin/perl5

sub numerically { $a <=> $b; }

open(INFILE,$ARGV[0]) || die "Couldn't open input file";

while(<INFILE>) {
    ($size,$stride,$time_ns) = /.+\s(\d+).+\s(\d+).+\s(\d+).*/;
    #print "$size $stride $time_ns\n";
    $elements{$size}{$stride} = $time_ns;
}

close  (INFILE);

# now print out the lines w/ spaces in between

open(OUTFILE,">${ARGV[0]}.data") || die "Couldn't open data output file";
foreach $size  (sort numerically keys %elements) {
    print OUTFILE "\n";
    foreach $stride  (sort numerically keys %{$elements{$size}}) {
	# now we know the stride and the size
	print OUTFILE "#size $size\n";
	print OUTFILE "$stride $elements{$size}{$stride}\n";
    }
}
close  (OUTFILE);

# Now create the plot file

open (OUTFILE,">${ARGV[0]}.plot") || die "Couldn't open outpuf file";
print OUTFILE "set logscale x\n";
print OUTFILE "set data style linespoints\n";
print OUTFILE "set terminal postscript eps\n";
print OUTFILE "set output '${ARGV[0]}.ps'\n";
print OUTFILE "plot '${ARGV[0]}.data'\n";

close(OUTFILE);
