X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=src%2Fawk%2Fexe%2Fparse_metar_d_output.awk;fp=src%2Fawk%2Fexe%2Fparse_metar_d_output.awk;h=fa354da4f0d2cf7025b0c8639294ce70d3984288;hb=03c229bffd594c1facb72e0d042a88c0505c8dbc;hp=0000000000000000000000000000000000000000;hpb=2e820ad561199f2ccc1ee3fa7e7e708e5dc8bc39;p=khatus.git diff --git a/src/awk/exe/parse_metar_d_output.awk b/src/awk/exe/parse_metar_d_output.awk new file mode 100755 index 0000000..fa354da --- /dev/null +++ b/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 = util_strip(line[1]) + val = util_strip(line[2]) + values[NR] = val + first[key] = NR + last[key] = NR +} + +/^ +/ { + values[NR] = util_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) + } + } + } +}