shellscriptfrequencycalculator

Shell Script Frequency Calculator

A Demo Program That Calls "dc" To Do Math Calculations

Calculates Harmonics, Sub-harmonics, and Wavelength from Frequency.

=========== START ===========

#!/bin/sh

# simple text based menu system demonstration

# Arv K7HKL

# Dec. 30, 2007

#

# NOTE: This program calls the "desk calculator" (dc),

# so you need it installed to run this script.

#

frequency=7.150

while true

do

clear

echo "#==========================================#"

echo "# SIMPLE TEXT BASED MENU SYSTEM #"

echo "#------------------------------------------#"

echo "# 1) Frequency = $frequency MHz"

echo "# 2) Calculate Harmonics"

echo "# 3) Calculate Sub-Harmonics"

echo "# 4) Calculate Wavelength"

echo "# 5) "

echo "# 0) Exit #"

echo "#------------------------------------------#"

echo -n "# SELECTION: "; read selection

case $selection in

0|q|Q) exit #exit on "0", "q", or "Q".

;;

1) clear

echo

echo -n "Enter Frequency in MHz: "

read frequency

;;

2) clear

for xxx in 1 2 3 4 5 6 7 8 9 10

do

harmonic=`echo "6 k $frequency $xxx * p" | dc` # "6 K" sets the precision for dc

echo "$frequency X $xxx = $harmonic MHz"

done

echo

echo -n "Hit ENTER To Continue: "

read junk

;;

3) clear

for xxx in 1 2 3 4 5 6 7 8 9 10

do

harmonic=`echo "6 k $frequency $xxx / p" | dc` # "6 k" sets the precision for dc

echo "$Frequendy / $xxx = $harmonic"

done

echo -n "Hit ENTER To Continue: "

read junk

;;

4) clear

wavelength=`echo "6 k 492 $frequency / p" | dc` # "6 k" sets the precision for dc

echo "Wavelength for $frequency MHz = $wavelength Feet."

echo

echo -n "Hit ENTER To Continue: "

read junk

;;

5) clear

echo "Not Sure What To do With $selection Entry."

echo -n "Hit ENTER To Contunue: "

read junk

;;

*) # CatchAll for unrecognized Commands:

clear

echo

echo " Illegal Command in $selection."

echo -n "Hit ENTER To Continue: "

read junk

;;

esac # end case evaluation section

done

=========== END ============