A METAR report is a loose international semi-standard used by airports for reporting information about wind speeds, humidity, and weather conditions. We’re going to write a program that parses a subset of these reports from a stream and keeps some running aggregates.
The report format looks like this:
<ICAO Code> <Timestamp> <Wind Info>
Which breaks down into this:
This is a string in the ASCII range of upper-case letters. It is at least one such character. It is terminated by a space after the final character.
Examples:
We’re not concerned about verifying the validity of these codes in this exercise. Parsing them is enough.
This is a string in the format of:
<day of month><hours><minutes>Z
Where:
This one is a little tricky. The METAR format specifies wind speeds in two different units: knots or meters per second. To complicate matters there is an optional gusts value.
<direction><speed><gusts?><unit>
Eg:
18027KT
180120MPS
01323G30MPS
The components of the format can be parsed as follows:
G23KT or MPSYYZ 122201Z 12023MPS
LAX 022355Z 09332G78KT
FR 110232Z 001100G12MPS
At minimum we require an interface that lets us:
Write a script to generate a few hundred thousand random reports one per line. Your program should be able to read the entire stream without failure and be able to either: