home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume2 / mpg / ukmpg < prev    next >
Text File  |  1991-08-07  |  3KB  |  109 lines

  1. :
  2. # ukmpg  (Miles Per Gallon -- UK Version) -- A Fuel Economy Calculator
  3. # This shell program uses the floating point arithmetic commands
  4. # "fp*" to calculate fuel economy in terms of liters per 100 km,
  5. # miles per US gallon, and miles per UK (Imperial) gallon.
  6. #
  7. # As distributed, the program assumes that the user will enter 
  8. # the distance travelled in MILES, and the amount of fuel used
  9. # in UK GALLONS, but that is not difficult to change to any other
  10. # combination of volume and distance measuring units.
  11. #
  12. # Author: Wolf N. Paul (ihnp4!killer!dcs!wnp), 1/13/88
  13. # Released into the Public Domain, Jan 18, 1988
  14. #
  15. # set -v # enable debugging
  16. #
  17. # CONSTANTS:
  18. #
  19. FILE=$HOME/.mpgdata
  20. US_GALLON=3.8
  21. UK_GALLON=4.5
  22. MILE=1.6
  23. #
  24. # Variables - all initialized to 0.0
  25. C_MILES=0.0        # current miles
  26. C_KMS=0.0        # current kilometers
  27. C_USGAL=0.0        # current gallons US
  28. C_UKGAL=0.0        # current gallons UK
  29. C_LITERS=0.0    # current liters
  30. T_MILES=0.0        # total miles
  31. T_KSM=0.0        # total kilometers
  32. T_USGAL=0.0        # total gallons US
  33. T_UKGAL=0.0        # total gallons UK
  34. T_LITERS=0.0    # total liters
  35. C_USMPG=0.0        # current miles/gallon US
  36. C_UKMPG=0.0        # current miles/gallon UK
  37. C_LP100=0.0        # current liters/100 km
  38. A_USMPG=0.0    # average miles/gallon US
  39. A_UKMPG=0.0    # average miles/gallon UK
  40. A_LP100=0.0    # average liters/100 km
  41. TMP=0.0            # kms/100
  42.  
  43. echo "MPG - Fuel Economy Calculator\n"
  44. echo "UK Version - enter Miles and Imperial Gallons\n"
  45.  
  46. echo "Reading old values ... \c"
  47.  
  48. T_MILES=`cut -d: -f1 $FILE`
  49. T_KMS=`cut -d: -f2 $FILE`
  50. T_USGAL=`cut -d: -f3 $FILE`
  51. T_UKGAL=`cut -d: -f4 $FILE`
  52. T_LITERS=`cut -d: -f5 $FILE`
  53. echo "done!\n"
  54.  
  55. echo "Enter miles driven: \c"
  56. read C_MILES
  57.  
  58. echo "Enter gallons used: \c"
  59. read C_UKGAL
  60.  
  61. echo "\nOne moment - calculating consumption figures ... \c"
  62. C_KMS=`fpmultiply $C_MILES $MILE`
  63. C_LITERS=`fpmultiply $C_UKGAL $UK_GALLON`
  64. C_USGAL=`fpdivide $C_LITERS $US_GALLON`
  65.  
  66. T_MILES=`fpadd $T_MILES $C_MILES`
  67. T_KMS=`fpadd $T_KMS $C_KMS`
  68. T_USGAL=`fpadd $T_USGAL $C_USGAL`
  69. T_UKGAL=`fpadd $T_UKGAL $C_UKGAL`
  70. T_LITERS=`fpadd $T_LITERS $C_LITERS`
  71.  
  72. C_USMPG=`fpdivide $C_MILES $C_USGAL`
  73. A_USMPG=`fpdivide $T_MILES $T_USGAL`
  74.  
  75. C_UKMPG=`fpdivide $C_MILES $C_UKGAL`
  76. A_UKMPG=`fpdivide $T_MILES $T_UKGAL`
  77.  
  78. TMP=`fpdivide $C_KMS 100.00`
  79. C_LP100=`fpdivide $C_LITERS $TMP`
  80. TMP=`fpdivide $T_KMS 100.00`
  81. A_LP100=`fpdivide $T_LITERS $TMP`
  82.  
  83. echo "$T_MILES:$T_KMS:$T_USGAL:$T_UKGAL:$T_LITERS" > $FILE
  84.  
  85. echo "done!"
  86. echo "\nFuel Economy:\n"
  87. echo "\t$C_UKMPG miles per UK gallon\t(Average ${A_UKMPG})"
  88. echo "\t$C_USMPG miles per US gallon\t(Average ${A_USMPG})"
  89. echo "\t$C_LP100 liters per 100 km\t\t(Average ${A_LP100})"
  90. echo "\nDo you want a printout of these results? \c"
  91. read REPLY
  92. if [ "$REPLY" != "y" -a "$REPLY" != "Y" ] ; then
  93.     exit
  94. fi
  95. echo "
  96. MPG (UK) -- Fuel Economy Calculator
  97. Fuel Economy Statement as of `date '+%h %d, 19%y'`
  98.  
  99. Miles this Filling:        $C_MILES\t($C_KMS km)
  100. Gallons this Filling:      $C_UKGAL\t($C_USGAL US, $C_LITERS liters)
  101.  
  102. Total Miles so far:        $T_MILES\t($T_KMS km)
  103. Total Gallons so far:      $T_UKGAL\t($T_USGAL US, $T_LITERS liters)
  104.  
  105. Current Miles per Gallon:  $C_UKMPG\t($C_USMPG US, $C_LP100 L/100 km)
  106. Average Miles per Gallon:  $A_UKMPG\t($A_USMPG US, $A_LP100 L/100 km)\
  107. " | lp -s &
  108.