#!/bin/sh
args=
run=0

ctime=`stat -f "%m" stnetwork 2>/dev/null`	# last compile time
mtime1=`stat -f "%m" main.cpp` 					# last modify time of main.cpp
mtime2=`stat -f "%m" functions.cpp` 			# last modify time of functions.cpp
#mtime3=`stat -f "%m" stnetwork.h` 				# last modify time of stnetwork.h
mtime3=`stat -f "%m" network.h` 				# last modify time of network.h
if ((mtime1-ctime>0||mtime2-ctime>0||mtime3-ctime>0)); then 
	g++ -g main.cpp functions.cpp -o stnetwork1 -fast && run=1
else
	run=1
fi
if [ "-c" == $1 ]; then
	shift
fi
for ((i=1; i<=$#; i++)); do
	args=$args\ ${!i}
done

if (($run==1)) && ./stnetwork1 $args; then
	for file in voltage network; do
		turnx11 on ./plot/"$file"plot.sh
	done
	./plot/fellousplot.sh ./results
#	./plot/fig2.sh
else
	echo -e "\a"
fi