A heat wave is a prolonged period of excessively hot weather. While definitions vary, heat waves are always measured relative to the usual weather in the area and relative to normal temperatures for the season. Temperatures that people from a hotter climate consider normal can be termed a heat wave in a cooler area if they are outside the normal climate pattern for that area. For example, the KMI11 (Belgium) and the KNMI22 (the Netherlands) define a heat wave as a period of at least five consecutive days in which the maximum temperature is at least 25 °C (summer days), provided that on at least three days in this period the maximum temperature is at least 30 °C (tropical days). Temperatures are measured one and a half meters above ground level in a so-called Stevenson screen33.
In common usage, however, people tend to use the term heat wave for periods that do no strictly meet the above criteria. Below are two fictional examples of a real heat wave (left) and a warm period that is not officially accounted as a heat wave (right).
date | maximum temperature |
---|---|
July 12 | 24.7 °C |
July 13 | 25.1 °C |
July 14 | 28.9 °C |
July 15 | 31.0 °C |
July 16 | 28.6 °C |
July 17 | 30.6 °C |
July 18 | 32.4 °C |
July 19 | 23.0 °C |
date | maximum temperature |
---|---|
August 9 | 26.0 °C |
August 10 | 24.1 °C |
August 11 | 29.4 °C |
August 12 | 32.8 °C |
August 13 | 34.0 °C |
August 14 | 25.5 °C |
August 15 | 20.1 °C |
August 16 | 19.0 °C |
Write a bash shell script forecast that reads a sequence of floating point from stdin. These numbers represent the maximum temperatures measured in a Stevenson screen over a period of consecutive days. Each of the numbers is on a separate line and the sequence ends with a line that contains the word stop. The script must write the text heat wave to stdout and end with exit status 0 if at least one heat wave was observed during the given period according to the definition of the KMI and KNMI. Otherwise the script must write the text no heatwave to stdout and end with exit status 1.
In this interactive session we assume the current directory contains the text files temperatures.01.txt4 and temperatures.02.txt5.
$ forecast < temperatures.01.txt6
heatwave
$ echo $?
0
$ forecast < temperatures.02.txt7
no heatwave
$ echo $?
1
A blast of hot air passed from south to north through portions of New Ulm and Renville County last Sunday evening. It lasted only a minute or two, but so intense was the heat that people rushed out of their houses believing them to be on fire.
— Minneapolis Tribune, July 10, 1879