# This awk script selects the zones with overheating problems and sorts them
# into descending order.  The temperature used to indicate overheating is 
# obtained from a recode in the file containing "OHT nn", where nn is the temp
# If this record doesn't exist, a default is used.  Script comfort_worstz
# provides the OHT record at the start of imp file.
#
# IT IS TOTALLY DEPENDENT ON THE FORMAT USED BY imp FOR ZONE MAX/MIN/MEAN TEMPS.
# and its output is used by the script comfort_awk_worstz. If imp changes,
# this script may have to be modified, and if this script is changed, script
# comfort_worstz may require modification.
#
BEGIN		{ ORS = "";				# Stop print writing NL
		  OHT = 24;				# Assume default temp
		  nz = 0;				# as showing overheating
		}

$1 ~ /^OHT$/	{ OHT = $2 }				# Pick up overheating
							# temp (from
							# comfort_worstz)

$1 ~ /^[1-9]/	{ if ($3 > OHT) {			# Select line starting
			PT[nz] = $3;			# with no.
			PZ[nz] = $1;			# 1st no. is zone number
			nz++;				# 2nd no. is max temp.
		  }					# Only save o'heat zones
		}

END		{ for (i=0; i<nz; i++)			# Exchange sort temps.
			for (j=i+1; j<nz; j++)		# and accoc. zones
				if (PT[i] < PT[j]) {
					tmp = PT[i]
					PT[i] = PT[j]
					PT[j] = tmp
					tmp = PZ[i]
					PZ[i] = PZ[j]
					PZ[j] = tmp
				}
		  for (i=0; i<nz; i++)			# print zone nos.(1 line
			print PZ[i] " "
		  printf "\n"
		}
