#!/bin/sh
gnuplot <<EOF
set term postscript color eps enhanced solid lw 2 20
set output "out.eps"
set title "Probability distribution of time between NOR corruptions"
set xlabel "Power cycles"
set ylabel "Cumulative probability"
set key bottom
plot "< sed '1,/^\$/d' GRAPH | sort -n" using 1:((\$0+1)/12) with lines \
  title "First corruption observed", \
  "< sed '/^\$/q' GRAPH  | sort -n" using 1:((\$0+1)/12) with lines \
  title "Last non-corruption observed", \
  1-exp(-0.0021*x) with lines \
  title "Exponential distribution ({/Symbol l}=1/476)"
EOF
cat out.eps |
  gs -sDEVICE=ppmraw -r100 -sOutputFile=- \
  -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sPAPERSIZE=a4 -q - | \
  convert -trim - out.png
