#!/usr/bin/perl -w

my(@names) = qw(rawsynchronous synchronous mmap2 rawpkthreads aioread rawaio);
# my(@names) = qw(rawsynchronous synchronous mmap2 pkthreads rawpkthreads aioread rawaio);
my(@bsdnames) = map { "bsd$_" } @names;
foreach(@names, @bsdnames) {
	print "$_"."_mean = mean($_"."_since);\n";
	print "$_"."_min = min($_"."_since) - $_"."_mean;\n";
	print "$_"."_max = max($_"."_since) - $_"."_mean;\n";
	print "$_"."_mean = mean($_"."_since);\n";
	print "$_"."_std = std($_"."_since);\n";
}
foreach(qw(best max min mean std)) {
	print "errb_$_ = [ ";
	foreach $n (@names) {
		print "$n"."_$_ ";
	}
	print "] \n";
        print "bsderrb_$_ = [ ";
        foreach $n (@bsdnames) {
                print "$n"."_$_ ";
        }
        print "] \n";

}


# figure;hold
# errorbar(1:6, errb_mean, errb_max, errb_min, 'k+')      
# h=errorbar(1:6, errb_mean, errb_std, 'k+')               
# set (h,'LineWidth',2)                                   
# plot([1 6],[5.333 5.333],'k');
# figure;hold
# errorbar(1:6, bsderrb_mean, bsderrb_max, bsderrb_min, 'k+')      
# h=errorbar(1:6, bsderrb_mean, bsderrb_std, 'k+')               
# set (h,'LineWidth',2)                                   
# plot([1 6],[5.333 5.333],'k');

print <<ENDALL1;
figure;hold
errorbar(errb_best, errb_mean, errb_min, errb_max, 'k+')      
h=errorbar(errb_best, errb_mean, errb_std, 'k+')              
set (h,'LineWidth',2)   
plot([10 65],[5.333 5.333],'k');
axis([10 65 1 8])
ENDALL1
foreach(@names) {
        my($first,$second);
        if(/raw/i) {
                $first = "Raw";
        } else {
                $first = "FS";
        }
        
        if(/aio/i) {
                $second = "AIO";
        } elsif(/synch/) {
                $second = "read";
        } elsif(/mmap/) {
                $second = "mmap";
        } elsif(/thread/) {
                $second = "thread";
        }
        print "label_$_ = '$first/$second'\n";

        print "text($_"."_best - 3,  5.3, '$first/$second')\n";
}
print <<ENDALL2;

figure;hold
errorbar(bsderrb_best, bsderrb_mean, bsderrb_min, bsderrb_max, 'k+')            
h=errorbar(bsderrb_best, bsderrb_mean, bsderrb_std, 'k+')                     
set (h,'LineWidth',2)                                   
plot([20 65],[5.333 5.333],'k');
axis([20 65 3.5 6.5])
ENDALL2

foreach(@bsdnames) {
	my($first,$second);
	if(/raw/i) {
		$first = "Raw";
	} else {
		$first = "FS";
	}
	
	if(/aio/i) {
		$second = "AIO";
	} elsif(/synch/) {
		$second = "read";
	} elsif(/mmap/) {
		$second = "mmap";
	} elsif(/thread/) {
		$second = "thread";
	}

	print "text($_"."_best - 3, 5.3, '$first/$second')\n";
}

