#!/bin/bash

###########################################################################################
#	run
#		version: 	1.0	12/12/13
#
#		original author:	Michele Bracuto		<bracuto@cs.unibo.it>
#		modified by:		Gabriele D'Angelo	<g.dangelo@unibo.it>
#
#	description:
#		executes a single run of the chosen simulator
#
#	usage:	
#		./run [cmb || ts || tw || tb || tbv]
#		or
#		./run [cmb || ts]			  in case of MPI-based ARTÌS
#	
#		mandatory input parameters = synchronization mechanism
#		cmb	Chandy-Misra-Bryant
#		ts	Time-Stepped
#		tw	Time-Warp
#		tb	Tree-Barrier (with constant lookahead)
#		tbv	Tree-Barrier (with variable lookahead)
#
#		example: ./run ts
#			it runs a parallel simulation composed of 3 LPs
#			that are synchronized using the time-stepped approach
#
#	notes:
#		the MPI-based version of ARTÌS supports only the "cmb" and "ts" simulators
#	
###########################################################################################

# Checking for the building type of ARTÌS
USEMPI=`cat ../../config.mak | grep "USE_MPI" | grep "=" | grep "YES" | wc -l`
USENOIPMPI=`cat ../../config.mak | grep "USE_NOIP_MPI" | grep "=" | grep "YES" | wc -l`

echo -e "AIRPORT SIMULATOR wrapper..."

if [ $USEMPI -eq 1 ]; then

	if [ "$#" != "1" ]; then
		echo "Incorrect syntax..."
		echo "USAGE: $0 [cmb || ts]"
		exit
	fi

	if [ $1 != "cmb" -a $1 != "ts" ]; then
		echo "Incorrect syntax...		 "
		echo "USAGE: $0 [cmb || ts]"
		echo ""
		exit
	fi

	# MPI (with SIMA) execution
	./run_mpi $1
else 
	if [ $USENOIPMPI -eq 1 ]; then
		# MPI (with NO SIMA) execution
		echo "NOT SUPPORTED"
	else

	if [ "$#" != "1" ]; then
		echo "Incorrect syntax..."
		echo "USAGE: $0 [cmb || ts || tw || tb || tbv]"
		exit
	fi

	if [ $1 != "cmb" -a $1 != "ts" -a $1 != "tw" -a $1 != "tb" -a $1 != "tbv" ]; then
		echo "Incorrect syntax...		 "
		echo "USAGE: $0 [cmb || ts || tw || tb || tbv]"
		echo ""
		exit
	fi

	# Standard execution
	./run_standard $1
fi
fi

sleep 1
echo "Done!"
