METARs are reports assembled with a particular format that is easy to decode with computer systems using regular expressions

METARs are reports assembled with a particular format that is easy to decode with computer systems using regular expressions.

These reports typically come in two forms: North American METARs and International METARs.  Create a series of regular expressions that decode each token of information using the North American METAR form.

Please see files and 

Example.

#!/bin/bash

printf “Report type:  “

egrep -o ‘METAR|SPECI’ metar.txt

printf “Station:  “

egrep -o ‘sK[A-Z]{3}s’ metar.txt

day_of_month=$(( $(cat metar.txt | cut -c12-13) ))

metar_time=$(( $(cat metar.txt | cut -c14-17) ))

printf “Day of the month:  %dn” $day_of_month

printf “Time:  %d Zulun” $metar_time

wind_dir=$(( $(egrep -o ‘s[0-9]{5}G?[0-9]?[0-9]?KTs’ metar.txt | cut -c2-4) ))

wind_spd=$(( $(egrep -o ‘s[0-9]{5}G?[0-9]?[0-9]?KTs’ metar.txt | cut -c5-6) ))

printf “Winds are from %d degrees at %d knotsn” $wind_dir $wind_spd

METAR|SPECI  K[ALPHA]{3}  [DIGIT]{6}Z  AUTO|COR 

_____ FIXED ___________________________  Optional

# wind conditions

[DIGIT]{5}G[DIGIT]{2}KT [DIGIT]{3}V[DIGIT]{3} | VRB[DIGIT]

– req — — opt — rq ——— opt ——-

### processing ###

1) read string, but if using math expansion, cut only digits

2) egrep (extended grep) with -o option returns only matched string (watch spaces with cut)

3) Add if/else logic to print correct message or no message if missing, or with optional branches

4) Add “Cloud cover” all categories

5) Add check and report for Thunder Storms and or rain (light/moderate/heavy)

Disclaimer: It is illegal to use the research material ordered on this website for other than research purposes. You must quote the sources appropriately. The company bears no responsibility for the use of research work, not intended for education use, the work is sold as-is with the highest quality and service available and written by freelancers.