#!/bin/sh
#
movie=$1
year=$2
if [ ! -f $movie.$year ] ; then
	echo "I do not see $movie.$year here"
	exit 1
fi
sed -e 's/^\ *\$//' -e 's/\ (USA)\ .*$//' -e 's/,//g' $movie.$year | \
	sort -n | awk 'BEGIN { A = 0; } {print $1 - A; A = $1}' > "$movie-$year"
weeks=`wc -l $movie-$year| awk '{print $1}'`
x=`expr 5 \* $weeks / 6` 
echo "weeks is $weeks, x is $x"
echo "# $movie $year" > gnuplot1.in
echo "set logscale y" >> gnuplot1.in
#echo "set xrange [0:25]" >> gnuplot1.in
#echo "set yrange [1e4:1e8]" >> gnuplot1.in
echo "set title \"$movie $year\"" >> gnuplot1.in
echo "set terminal png small color" >> gnuplot1.in
echo "set output '$movie-$year.png'" >> gnuplot1.in
echo "f(x) = exp(a*x + b)" >> gnuplot1.in
echo "fit f(x) '$movie-$year' using :1 via 'variable.init'" >> gnuplot1.in
echo "set label 'a = %3.5g',a at $x, 30000000" >> gnuplot1.in
echo "set label 'b = %3.5g',b at $x, 40000000" >> gnuplot1.in
echo "plot '$movie-$year', exp(a*x + b) with linesp" >> gnuplot1.in
# run it
gnuplot < gnuplot1.in

