| 1 | # Qualifying the name as "_d_output" lest it be mistaken for parser of actual |
| 2 | # metar format. |
| 3 | |
| 4 | /METAR pattern not found in NOAA data/ { |
| 5 | failures++ |
| 6 | exit |
| 7 | } |
| 8 | |
| 9 | /[A-z][a-z]+ *: / { |
| 10 | split($0, line, ":") |
| 11 | key = str_strip(line[1]) |
| 12 | val = str_strip(line[2]) |
| 13 | values[NR] = val |
| 14 | first[key] = NR |
| 15 | last[key] = NR |
| 16 | } |
| 17 | |
| 18 | /^ +/ { |
| 19 | values[NR] = str_strip($0) |
| 20 | last[key] = NR |
| 21 | } |
| 22 | |
| 23 | END { |
| 24 | if (failures) { |
| 25 | print "metar fetch failed" > "/dev/stderr" |
| 26 | } else { |
| 27 | temp_string = values[first["Temperature"]] |
| 28 | split(temp_string, temp_parts, " +") |
| 29 | temp_celsius = temp_parts[1] |
| 30 | temp_fahrenheit = (temp_celsius * (9 / 5)) + 32 |
| 31 | print("temperature_c", temp_celsius) # °C |
| 32 | print("temperature_f", temp_fahrenheit) # °F |
| 33 | for (i=first["Phenomena"]; i<=last["Phenomena"]; i++) { |
| 34 | phenomenon = values[i] |
| 35 | if (phenomenon) { |
| 36 | print("phenomenon" Kfs i, phenomenon) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |