X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=v2%2Fsrc%2Fawk%2Fexe%2Fparse_metar_d_output.awk;fp=v2%2Fsrc%2Fawk%2Fexe%2Fparse_metar_d_output.awk;h=82d2e29b07b15348cf3bbb6fd1d57627e4d6d533;hb=53d24ad688ea39892dbf3c748c1e40514eeb2763;hp=0000000000000000000000000000000000000000;hpb=0c4f892ec9d0cd7dc87c83c01b52259d0aed1ae3;p=khatus.git diff --git a/v2/src/awk/exe/parse_metar_d_output.awk b/v2/src/awk/exe/parse_metar_d_output.awk new file mode 100644 index 0000000..82d2e29 --- /dev/null +++ b/v2/src/awk/exe/parse_metar_d_output.awk @@ -0,0 +1,40 @@ +# Qualifying the name as "_d_output" lest it be mistaken for parser of actual +# metar format. + +/METAR pattern not found in NOAA data/ { + failures++ + exit +} + +/[A-z][a-z]+ *: / { + split($0, line, ":") + key = str_strip(line[1]) + val = str_strip(line[2]) + values[NR] = val + first[key] = NR + last[key] = NR +} + +/^ +/ { + values[NR] = str_strip($0) + last[key] = NR +} + +END { + if (failures) { + print "metar fetch failed" > "/dev/stderr" + } else { + temp_string = values[first["Temperature"]] + split(temp_string, temp_parts, " +") + temp_celsius = temp_parts[1] + temp_fahrenheit = (temp_celsius * (9 / 5)) + 32 + print("temperature_c", temp_celsius) # °C + print("temperature_f", temp_fahrenheit) # °F + for (i=first["Phenomena"]; i<=last["Phenomena"]; i++) { + phenomenon = values[i] + if (phenomenon) { + print("phenomenon" Kfs i, phenomenon) + } + } + } +}