Redesign component interfaces
[khatus.git] / bin / khatus_parse_metar_d_output
CommitLineData
654ea6e2
SK
1#! /usr/bin/awk -f
2#
3# Qualifying the name as "_d_output" lest it be mistaken for parser of actual
4# metar format.
5
75b23ff8
SK
6BEGIN {
7 OFS = msg_fs ? msg_fs : "|"
8 Kfs = key_fs ? key_fs : ":"
654ea6e2
SK
9}
10
11/METAR pattern not found in NOAA data/ {
12 failures++
13 exit
14}
15
16/[A-z][a-z]+ *: / {
17 split($0, line, ":")
18 key = strip(line[1])
19 val = strip(line[2])
20 values[NR] = val
21 first[key] = NR
22 last[key] = NR
23}
24
25/^ +/ {
26 values[NR] = strip($0)
27 last[key] = NR
28}
29
30END {
31 if (failures) {
32 print "metar fetch failed" > "/dev/stderr"
33 } else {
34 temp_string = values[first["Temperature"]]
35 split(temp_string, temp_parts, " +")
36 temp_celsius = temp_parts[1]
37 temp_fahrenheit = (temp_celsius * (9 / 5)) + 32
75b23ff8
SK
38 print("temperature_c", temp_celsius) # °C
39 print("temperature_f", temp_fahrenheit) # °F
654ea6e2 40 for (i=first["Phenomena"]; i<=last["Phenomena"]; i++) {
3fc7fe2c
SK
41 phenomenon = values[i]
42 if (phenomenon) {
75b23ff8 43 print("phenomenon" Kfs i, phenomenon)
3fc7fe2c 44 }
654ea6e2
SK
45 }
46 }
47}
75b23ff8
SK
48
49function strip(s) {
50 sub("^ *", "", s)
51 sub(" *$", "", s)
52 return s
53}
This page took 0.02325 seconds and 4 git commands to generate.