#!/bin/sh
# Summer_overheating show_balance script: version 1.1 of Nov 1994

# casual energy...

echo "***** comfort_cause: get energy balance for worst zone from res" >>$comf_dir/tmp/comfort_trace

comfort_lock=$comf_dir/tmp/comfort_lock
comfort_results=$comf_dir/tmp/comfort_results
rm -f $comf_dir/tmp/comfort_eb

if [ "X$comfort_lock" = "X" ]; then
   echo -n "Zone to be examined? "
   read WZ
   echo $comfort_results
else
   WZ=`cat $comfort_lock`
fi

echo "Getting an energy balance for the worst zone...."

res -mode script -file ${comfort_results} >>$comf_dir/tmp/comfort_trace  2>$comf_dir/tmp/comfort_eb  <<~
${comfort_results}
y
a
n
4
<
1
${WZ}
a
p
b
-
-
-
y
~
echo "Here is the energy balance:"
echo

cat $comf_dir/tmp/comfort_eb			# Display energy balance.

					# Get offending energy flowpaths.
OHC=`awk -f  ${IFE_HOME}/sys/bin/summer_comfort/comfort_awk_eb  $comf_dir/tmp/comfort_eb`
echo
echo " From this data it appears that the (rank ordered) "
echo " cause of the zone ${WZ} discomfort is"
echo
echo "$OHC"
echo

for i in $OHC			# Insert plot commands into GP.
do
    case $i in
    "Infiltration")	GP=$GP'l
';;				# 's needed to put \n into GP.
    "Ventilation")	GP=$GP'm
';;
    "Def_Window_cond_Ext")	GP=$GP'n
';;
    "Def_Window_cond_Int")	GP=$GP'n
';;
    "Air_Point_Solar")	GP=$GP'p
';;
    "Casual_gains")	GP=$GP'q
';;
    "Surface_convection")	GP=$GP'r
*
*
';;
    "Plant")	GP=$GP'k
';;
    esac
done
GP=$GP'!'				# Add draw command.

					# Get graph of causal flowpaths.
echo "***** comfort_cause: get causal flowpaths for worst zone from res" >>$comf_dir/tmp/comfort_trace
echo "***** graphpic is ${GP}" >>$comf_dir/tmp/comfort_trace

rm -f $comf_dir/tmp/wz_cause_graph
wz_cause_graph=$comf_dir/tmp/wz_cause_graph

res -mode script -file ${comfort_results} >>$comf_dir/tmp/comfort_trace  2>/dev/null  <<.
${comfort_results}
y
a
n
4
<
1
${WZ}
b
a
>
b
${wz_cause_graph}
${GP}
>
-
-
-
y
.

echo
echo " A graph of flowpath interactions will appear shortly...."

vww -g 200 70 -ww $wz_cause_graph &

echo
echo " Click in the STOP button on each of the graphs to close them down.."
read xb						# hang around.
exit 0
