#!/usr/bin/ruby1.8
counts = { }
lines = File.open("appdata.dat", "rb").readlines
nums = lines.map { |i| i.to_f }
nums.each { |n|
  counts[n] = 0 unless counts[n]
  counts[n] += 1
}

File.open("countfile.dat", "wb") { |f|
  counts.keys.sort.each { |acc|
    num = counts[acc]
    if num > 0
      f.puts("#{acc} #{num}")
    end
  }
}

gnuplotcmd = File.open("gnuplotnums.cmd", "wb")
gnuplotcmd.write <<EOF
set term postscript
set size 0.7,0.7
set xrange [ 0.4 : 1.1 ]
set xlabel "accuracy"
set ylabel "number of trials"
set linestyle 1 lt 1 lw 50
plot "countfile.dat" using 1:2 title 'Accuracy Histogram' with boxes
EOF
#plot "countfile.dat" using 1:2 title 'Accuracy Histogram' with imp ls 1
gnuplotcmd.close

