# This awk script selects the worst energy flowpaths contributing to the
# zone overheating and prints them (currently any non zero flowpath is printed).
#
# IT IS TOTALLY DEPENDENT ON THE FORMAT USED BY res FOR CAUSAL ENERGY BALANCES
# and its output is used by the script comfort_cause. If res were to change,
# this script would probably need to be modified, and if this script is changed,
# script comfort_cause may require modification.
#
BEGIN		{ ORS = ""			# stop "print" outputing NL
		  C[0] = "Infiltration"		# Causal Classes
		  C[1] = "Ventilation"		# These are in the order that
		  C[2] = "Def_Window_cond_Ext"	# res outputs them
		  C[3] = "Def_Window_cond_Int"	# They are printed as shown for
		  C[4] = "Air_Point_Solar"	# script comfort_cause to use
		  C[5] = "Casual_gains"
		  C[6]= "Surface_convection"
		  C[7]= "Surface_convection"
		  C[8]= "Surface_convection"
		  C[9]= "Surface_convection"
		  C[10]= "Plant"
		  G[5] = 0
		  L[5] = 0
		}

$1 == "Infiltration"           {   G[0] = $4; L[0] = $5 }
$1 == "Ventilation"            {   G[1] = $4; L[1] = $5 }
$1 == "Default" && $4 == "ext" {   G[2] = $5; L[2] = $6 }
$1 == "Default" && $4 == "int" {   G[3] = $5; L[3] = $6 }
$1 == "Air"                    {   G[4] = $6;  L[4] = $7 }
$2 == "casual"                 {   G[5] += $5; L[5] += $6 }
$1 == "Controlled"             {   G[5] += $5; L[5] += $6 }
$1 == "Opaque" && $4 == "ext"  {   G[6] = $5; L[6] = $6 }
$1 == "Opaque" && $4 == "int"  {   G[7] = $5; L[7] = $6 }
$1 == "Transp" && $4 == "ext"  {   G[8] = $5; L[8] = $6 }
$1 == "Transp" && $4 == "int"  {   G[9] = $5; L[9] = $6 }
$1 == "Plant"                  {   G[10] = $3;  L[10] = $4 }

$1 == "No" && $2 == "plant"	{ C[15] = "" }	# Correction due to missing
						# gain/loss nos. if no plant

END		{ for (i=0; i<11; i++)
			if (G[i] > 0. )	# Test for o'heating contributor
				print C[i] " "  # Print contributors (1 line)
		  print "\n"
		}
