#!/bin/bash
#  
#   First we need to get into the main directory
#
if [[  ! -d ./bin  ]]; then
    cd ../
    if [[ ! -d ./bin ]]; then
	echo "Error: store must be executed from the main, or bin directory"
	exit
    fi
fi
if [[ ! -d SubProcesses ]]; then
    echo "Error: SubProcesses directory not found"
    exit
fi
cd SubProcesses
if [[  "$1" == ""  ]]; then
    echo 'Enter you must specify a name of files to remove. (eg store TeV)'     
    exit
fi
files='results.dat ftn25 ftn99 log.txt'

if [[ -e $1_results.html ]]; then
    rm -f $1_results.html
fi

for i in P*_* ; do
    cd $i
    echo $i
    if [[ -e $1_results.html ]]; then
	rm -f $1_results.html
    fi

    for k in G* ; do
	cd $k
	for j in $files ; do
	    if [[ -e $1_$j ]]; then
		rm -f $1_$j >& /dev/null
	    fi
	done
	rm -f $1_events.lhe.gz >& /dev/null
	rm -f $1_ftn25.gz  >&/dev/null
	rm -f $1_ftn99.gz  >&/dev/null
	cd ../
    done
    cd ../
done
cd ../
./bin/gen_cardhtml-pl
rm -f Events/$1_events.lhe*
rm -f Events/$1_unweighted_events.lhe*
rm -rf Events/$1_Resultdir


