#!/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 [[  "$1" == ""  ]]; then
    echo 'Enter you must specify a name of the run to remove. (eg rmrun run_01)'     
    exit
fi

if [[ ! -d Events ]]; then
    echo "Error: Events directory not found"
    exit
fi

# Remove the run from the Events directory
cd Events;rm -rf `find . -name "$1*"|grep -v banner`;cd ..

if [[ ! -d SubProcesses ]]; then
    echo "Error: SubProcesses directory not found"
    exit
fi

# Remove the run from the SubProcesses directory
cd SubProcesses
rm -f $1*
for i in P*_* ; do
    cd $i
    echo $i
    rm -f $1*

    for k in G* ; do
	cd $k
	rm -f $1*

	cd ../
    done
    cd ../
done
cd ../
./bin/gen_cardhtml-pl
./bin/gen_crossxhtml-pl

