#!/bin/bash
if [ $# -lt 4 ]
then
	echo usage:"extr_min2 [-l] -g <graph_type> -f <filename> -a <alg> <alg> ..."
	exit
fi

algs_specified="False"
algs=""
print_type="plain"

while [ $# -gt 0 ]
do
	case "$1" in
	-l)	print_type="latex";;
	-f)	shift; file=$1;;
	-g)	shift; graph=$1;;
        -a)     shift; algs_specified="True";
                while [ $# -gt 0 ]
                do
                        algs="$algs $1"
                        shift
                done;;

	 *)	echo argument error;;
	esac
	shift
done


direct="$HOME/partitioning/min_quotient/output"
direct1="$HOME/bin"

cd $direct

if [ $algs_specified = "True" ]
then
        algs_to_find="$algs"
else
        algs_to_find=`ls`
fi

for i in $algs_to_find
do
	if [ -d $i ]
	then
		case "$i" in
		kl)	alg_class="kl";;
		lkl)	alg_class="kl";;
		rs)	alg_class="kl";;
		klo)	alg_class="kl";;
		klp3)	alg_class="kl";;
		klp3o)	alg_class="kl";;
		wsa)	alg_class="kl";;
	 	*)	alg_class="bk";;
		esac

		if [ $alg_class = "kl" ]
		then
			field="8"
		else
			field="6"
		fi

		cd $i/$graph
		files=`ls $file 2>/dev/null`
		if [ "$files" != "" ]
		then

			set `ls $file`

			while [ $# -gt 0 ]
			do

			   if [ -f $1 ]
			   then
				value=`conf_int $i min_cut $graph $1`
				value2=`conf_int $i min_quotient $graph $1`
				lines=`wc -l $1 | gawk '/./ {print $1}'`
                                echo "$i $1 $lines $value $value2" | \
				if [ $print_type = "plain" ]
				then
                                	gawk '/./ {
                                  	printf "%-6s %-16s %-4d %-10.4f [%-8.4f,%-8.4f] %-10.4f [%-8.4f,%-8.4f] %-10.4f\n", $1, $2, $3, $4, $5, $6, $9, $10, $11, $8 }'
				else
                                	gawk '/./ {
                                  	printf "%-6s \& %10.2f \& %8.2f, %8.2f \& %10.4f \& %8.4f, %8.4f \&  %-10.2f\\\\\\hline\n", $1, $4, $5, $6, $9, $10, $11, $8 }'
				fi

			   fi
			   shift	
			done
		fi
		cd ../..
	fi
done
