#!/bin/sh
# Version 1.0
# This script calculates avgavg and maxavg for the output of the GA program
# and produces an output file with a _graph appended to it. This can be the
# input to xgraph. 
#
# usage: prcs <maxgen+1> <ofilename> 
# example: prcs 51 ofile
# will produce the file   ofile_graph
# Bugs: Will only work on runs for 10 random seeds but that can be changed
# Send bug reports to sushil@cs.unr.edu
#
rm ff_?? ${2}_graph_tmp
split -$1 $2 ff_
for i in `ls ff_??`
do
	cat $i | awk '{print $2, $3}' > ${i}_col
done
rm tmp
paste `ls ff_??_col` > tmp
cat -n tmp > ${2}_graph_tmp
rm ff_?? ff_??_col tmp
#
# calculates the average  (maxavg)over 10 runs
#
cat ${2}_graph_tmp | awk '{print $1, ($2 + $4 + $6 + $8 + $10 + $12 + $14 + $16 + $18 + $20)/10.0}' > ${2}_graph
echo "\"max_$2 \"" >> ${2}_graph
echo " " >> ${2}_graph
#
# calculates the average  (maxavg)over 10 runs
#
cat ${2}_graph_tmp | awk '{print $1, ($3 + $5 + $7 + $9 + $11 + $13 + $15 + $17 + $19 + $21)/10.0}' >> ${2}_graph
echo "\"avg_$2 \"" >> ${2}_graph
echo " " >> ${2}_graph
rm ${2}_graph_tmp
