home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume2
/
mpg
/
ukmpg
< prev
next >
Wrap
Text File
|
1991-08-07
|
3KB
|
109 lines
:
# ukmpg (Miles Per Gallon -- UK Version) -- A Fuel Economy Calculator
#
# This shell program uses the floating point arithmetic commands
# "fp*" to calculate fuel economy in terms of liters per 100 km,
# miles per US gallon, and miles per UK (Imperial) gallon.
#
# As distributed, the program assumes that the user will enter
# the distance travelled in MILES, and the amount of fuel used
# in UK GALLONS, but that is not difficult to change to any other
# combination of volume and distance measuring units.
#
# Author: Wolf N. Paul (ihnp4!killer!dcs!wnp), 1/13/88
# Released into the Public Domain, Jan 18, 1988
#
# set -v # enable debugging
#
# CONSTANTS:
#
FILE=$HOME/.mpgdata
US_GALLON=3.8
UK_GALLON=4.5
MILE=1.6
#
# Variables - all initialized to 0.0
C_MILES=0.0 # current miles
C_KMS=0.0 # current kilometers
C_USGAL=0.0 # current gallons US
C_UKGAL=0.0 # current gallons UK
C_LITERS=0.0 # current liters
T_MILES=0.0 # total miles
T_KSM=0.0 # total kilometers
T_USGAL=0.0 # total gallons US
T_UKGAL=0.0 # total gallons UK
T_LITERS=0.0 # total liters
C_USMPG=0.0 # current miles/gallon US
C_UKMPG=0.0 # current miles/gallon UK
C_LP100=0.0 # current liters/100 km
A_USMPG=0.0 # average miles/gallon US
A_UKMPG=0.0 # average miles/gallon UK
A_LP100=0.0 # average liters/100 km
TMP=0.0 # kms/100
echo "MPG - Fuel Economy Calculator\n"
echo "UK Version - enter Miles and Imperial Gallons\n"
echo "Reading old values ... \c"
T_MILES=`cut -d: -f1 $FILE`
T_KMS=`cut -d: -f2 $FILE`
T_USGAL=`cut -d: -f3 $FILE`
T_UKGAL=`cut -d: -f4 $FILE`
T_LITERS=`cut -d: -f5 $FILE`
echo "done!\n"
echo "Enter miles driven: \c"
read C_MILES
echo "Enter gallons used: \c"
read C_UKGAL
echo "\nOne moment - calculating consumption figures ... \c"
C_KMS=`fpmultiply $C_MILES $MILE`
C_LITERS=`fpmultiply $C_UKGAL $UK_GALLON`
C_USGAL=`fpdivide $C_LITERS $US_GALLON`
T_MILES=`fpadd $T_MILES $C_MILES`
T_KMS=`fpadd $T_KMS $C_KMS`
T_USGAL=`fpadd $T_USGAL $C_USGAL`
T_UKGAL=`fpadd $T_UKGAL $C_UKGAL`
T_LITERS=`fpadd $T_LITERS $C_LITERS`
C_USMPG=`fpdivide $C_MILES $C_USGAL`
A_USMPG=`fpdivide $T_MILES $T_USGAL`
C_UKMPG=`fpdivide $C_MILES $C_UKGAL`
A_UKMPG=`fpdivide $T_MILES $T_UKGAL`
TMP=`fpdivide $C_KMS 100.00`
C_LP100=`fpdivide $C_LITERS $TMP`
TMP=`fpdivide $T_KMS 100.00`
A_LP100=`fpdivide $T_LITERS $TMP`
echo "$T_MILES:$T_KMS:$T_USGAL:$T_UKGAL:$T_LITERS" > $FILE
echo "done!"
echo "\nFuel Economy:\n"
echo "\t$C_UKMPG miles per UK gallon\t(Average ${A_UKMPG})"
echo "\t$C_USMPG miles per US gallon\t(Average ${A_USMPG})"
echo "\t$C_LP100 liters per 100 km\t\t(Average ${A_LP100})"
echo "\nDo you want a printout of these results? \c"
read REPLY
if [ "$REPLY" != "y" -a "$REPLY" != "Y" ] ; then
exit
fi
echo "
MPG (UK) -- Fuel Economy Calculator
Fuel Economy Statement as of `date '+%h %d, 19%y'`
Miles this Filling: $C_MILES\t($C_KMS km)
Gallons this Filling: $C_UKGAL\t($C_USGAL US, $C_LITERS liters)
Total Miles so far: $T_MILES\t($T_KMS km)
Total Gallons so far: $T_UKGAL\t($T_USGAL US, $T_LITERS liters)
Current Miles per Gallon: $C_UKMPG\t($C_USMPG US, $C_LP100 L/100 km)
Average Miles per Gallon: $A_UKMPG\t($A_USMPG US, $A_LP100 L/100 km)\
" | lp -s &