#!/bin/sh
# IFe_simulator
# if no /tmp/ESP directory and default file create...
if test ! -d /tmp/ESP ; then
  mkdir /tmp/ESP
fi
if test ! -f /tmp/ESP/default.cfg ; then
  cp -r ${IFE_HOME}/misc/ESP /tmp
fi
# simulation design function:
# first see if bps is available on this machine, if
# so then run it otherwise show an image
if test ! -f ${IFE_HOME}/sys/bin/bps ; then
	echo    "emulation	simulator	${IFE_HOME}/lib/images/esp-r.ex"
	${IFE_HOME}/sys/bin/vww -ex ${IFE_HOME}/lib/images/esp-r.ex

	# get petri to shift token to the subsequent transition.
	#echo "shift_next_transition"
	echo "Thermal DTF has exited"

	exit 0
fi

finish=no
while ( [ X$finish != "Xyes" ] )
do
 
   if [ $# -lt 1 ]; then
        ${IFE_HOME}/sys/bin/bps -file /tmp/ESP/default.cfg
   else
        ${IFE_HOME}/sys/bin/bps  -file $1
   fi

   finish=`${IFE_HOME}/sys/bin/dialog -p "Are you finished with the thermal simulator ?" -file "yes" -d "yes" -h1 "type yes or no" -h2 "type yes or no"`

done

# Ask user what results db they just created.
schema=`${IFE_HOME}/sys/bin/dialog -p "Name of the esp results db you created?" -file "/tmp/ESP/demo_building.res " -d "/usr/esru/esp-r/training/results/test.res" -h1 "The results db contains the analysis results" -h2 "Choose the default if in doubt."`

if [ "X$schema" != "X" ]; then

   finish=no
   while ( [ X$finish != "Xyes" ] )
   do

      ${IFE_HOME}/sys/bin/res  -file $schema

      finish=`${IFE_HOME}/sys/bin/dialog -p "Are you finished looking at thermal results ?" -file "yes" -d "yes" -h1 "type yes or no" -h2 "type yes or no"`

   done

fi

# show some results
# xv image 1, image 2, etc.

# Ask user for summary of performance.
schema=`${IFE_HOME}/sys/bin/dialog -p "Please give a performance summary." -file " " -d "Classroom 4 overheats." -h1 "Give a brief statement on the analysis results" -h2 "A one line summary is required."`

echo "$schema"
echo "$schema" > /tmp/thermal_summary

# get petri to shift token to the subsequent transition.
#echo "shift_next_transition"
echo "Thermal DTF has exited"

exit 0
