Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Are there any errors displayed in the code below?

#!/bin/bash

token1="AUTO"

token2="COR"

METARFILE="metar.txt"

VSM=$(egrep -o '\s[[:digit:]]*SM' $METARFILE | tr -d SM)

RAIN=$(egrep -o '?\WRA' $METARFILE | tr -d [:blank:])

CLOUD_SKC=$((`egrep o 'SKC[[:digit:]]*?' $METARFILE | cut -c4-6`*100))

CLOUD_FEW=$((`egrep o 'FEW[[:digit:]]*?' $METARFILE | cut -c4-6`*100))

CLOUD_SCT=$((`egrep o 'SCT[[:digit:]]*?' $METARFILE | cut -c4-6`*100))

CLOUD_BKN=$((`egrep o 'BKN[[:digit:]]*?' $METARFILE | cut -c4-6`*100))

CLOUD_OVC=$((`egrep o 'OVC[[:digit:]]*?' $METARFILE | cut -c4-6`*100))

TD_TEMP=$(egrep -o '[[:digit:]]{2}//?M[[:digit:]]{2}' $METARFILE | cut -c1-2)

TD_DEW=$(egrep -o '[[:digit:]]{2}//?M[[:digit:]]{2}' $METARFILE | tr -d M | cut -c4 5)

TH=$(egrep -o '\sTH\s' $METARFILE | tr -d [:blank:] )

printf "Report type:\t\t"

egrep -o 'METAR|SPECI' $METARFILE

printf "Location:\t\t"

egrep -o '\sK[A-Z]{3}\s' $METARFILE

DTGROUP=$(egrep -o '[[:digit:]]*Z' $METARFILE)

day_of_month=$(echo $DTGROUP | cut -c1-2)

report_time_hour=$(echo $DTGROUP | cut -c3-4)

report_time_min=$(echo $DTGROUP | cut -c5-6)

printf "Day of month:\t\t%d " $day_of_month

printf "Time:\t\t\t%d:%d " $report_time_hour $report_time_min

wind=$(egrep -o '[[:digit:]]*?G[[:digit:]]*KT' $METARFILE)

wind_dir=$(echo $wind | cut -c1-3)

wind_spd=$(echo $wind | cut -c4-5)

wind_var=$(egrep -o '\s[[:digit:]]V[[:digit:]]\s' $METARFILE)

wind_var1=$(echo $wind_var | cut -c1-3)

wind_var2=$(echo $wind_var | cut -c5-7)

printf "Wind direction:\t\t%d, Speed: %d " $wind_dir $wind_spd

if [ "x$wind_var" != "x" ] ; then

printf "Wind direction is variable between %d and %d " $wind_var1

$wind_var2

fi

printf "Visibility:\t\t%d Status Miles " $VSM

if [ "$RAIN" == "+RA" ] ; then

printf "Heavy Rain "

elif [ "$RAIN" == "RA" ] ; then

printf "Medium Rain "

elif [ "$RAIN" == "-RA" ] ; then

printf "Light Rain "

else

printf " "

fi

printf "Cloud Conditions:\t\t "

[ $CLOUD_SKC ] && printf "Clouds: \t\tSky clear, at %d feet above sea level "

$CLOUD_SKC

[ $CLOUD_FEW ] && printf $CLOUD_FEW

[ $CLOUD_SCT ] && printf

$CLOUD_SCT

[ $CLOUD_BKN ] && printf

level " $CLOUD_BKN

[ $CLOUD_OVC ] && printf

level " $CLOUD_BKN

"Clouds: \t\tA few, at %d feet above sea level "

"Clouds: \t\tScattered, at %d feet above sea level "

"Clouds: \t\tBroken clouds, at %d feet above sea

"Clouds: \t\tOvercast clouds, at %d feet above sea

printf "Temperature:\t\t%s degrees Celsius " $TD_TEMP

printf "Dew point:\t\t%s degrees Celsius " $TD_DEW

if [ "$TH" ] ; then

printf "Thunderstorms reported in the area "

fi

if [ $(egrep -o "$token1\>" $METARFILE) ] ; then

printf "This is a fully automated report "

fi

if [ $(egrep -o "$token2\>" $METARFILE) ] ; then

printf "This is a corrected observation "

fi

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What is meant by the exchange privilege within a "family of funds"?

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago