if [ $# -ne 2 ]
then
echo "Usage $0 <program> l|c"
exit 2 
fi

echo Analisando trace estatico - $1

cp bin/2D_StAnalyser bin/Pattern Programs/$1/Static/2D-VLIW
if [ "$?" = "0" ]; then
	cd Programs/$1/Static/2D-VLIW
	if [ "$?" = "0" ]; then
		./2D_StAnalyser < $1.info.out $1 $2 > saida_analyser.txt
		echo Fim da analise do trace estatico
        else
                echo Nao foi possivel acessar o diretorio Programs/$1/Static/2D-VLIW
        fi
else
        echo Nao foi possivel copiar para Programs/$1/Static/2D-VLIW
fi

#echo Gerando os arquivos de Pattern Range - $1

#for i in `find Header -type f`
#do
#	./Pattern $1 $i 
#done

#mkdir PatternRange
#count=0
#until [ $count = 10 ]; do
#  mv Header/*$count.range PatternRange
#  count=`expr $count + 1`
#done

\rm 2D_StAnalyser Pattern
grep "Mais operandos" saida_analyser.txt | wc -l > operandos.err
grep "FALTOU" analysis_results_$1.txt | wc -l > espaco.err
#more *.err
#tail analysis_results_$1.txt
#cd ~/archc/models/drap/Trace/StaticBuilderAnalyser
#if [ "$2" = "lc" ]; then
#  cat Programs/$1/Static/2D-VLIW/$1.csv >> Resultados-LC.csv
#else
#  cat Programs/$1/Static/2D-VLIW/$1.csv >> Resultados-CL.csv
#fi                             

echo Fim da execucao
