Posted By

Scooter on 05/09/09


Tagged


Versions (?)

Fuel consumption


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/05/fuel-consumption.html

  1. <%
  2. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' NOTE: The "magic numbers" in these functions are from the 2007 Fuel Consumption Guide
  10. ' published by Natural Resources Canada and use a conversion of 4.546 L = 1 imperial gallon.
  11. ' U.S. fuel economy ratings use U.S. gallons which are 20% smaller than imperial gallons.
  12.  
  13. ' Calculate fuel consumption rating in litres per 100 kilometres.
  14. function lph(kilometres, litres)
  15. lph = (litres * 100) / kilometres
  16. end function
  17.  
  18. ' Calculate fuel consumption rating in miles per gallon.
  19. function mpg(miles, gallons)
  20. mpg = miles / gallons
  21. end function
  22.  
  23. ' Convert miles per (imperial) gallon to litres per 100 kilometres.
  24. function lph2mpg(mpg)
  25. lph2mpg = 282.48 / mpg
  26. end function
  27.  
  28. ' Convert litres per 100 kilometres to miles per (imperial) gallon.
  29. function mpg2lph(lph)
  30. mpg2lph = 282.48 / lph
  31. end function
  32.  
  33. ' Calculate fuel consumption in litres.
  34. ' distanceTravelled = the distance travelled in kilometres; e.g. 20000
  35. ' percentCity = the percentage of the distance travelled occuring in the city; e.g. 0.55
  36. ' percentHighway = the percentage of the distance travelled occuring on the highway; e.g. 0.45
  37. ' ratingCity = city fuel consumption rating in litres per 100 kilometres; e.g. 7.9
  38. ' ratingHighway = highway fuel consumption rating in litres per 100 kilometres; e.g. 5.9
  39. function fuelConsumption(distanceTravelled, percentCity, percentHighway, ratingCity, ratingHighway)
  40. dim cityConsumption
  41. dim highwayConsumption
  42.  
  43. cityConsumption = (distanceTravelled * percentCity * ratingCity) / 100
  44. highwayConsumption = (distanceTravelled * percentHighway * ratingHighway) / 100
  45. fuelConsumption = cityConsumption + highwayConsumption
  46. end function
  47.  
  48. ' Calculate carbon dioxide emissions in kilograms.
  49. function CO2emissions(fuelConsumption, fuelType)
  50. select case fuelType
  51. case "diesel"
  52. CO2emissions = fuelConsumption * 2.7
  53. case else ' gasoline
  54. CO2emissions = fuelConsumption * 2.4
  55. end select
  56. end function
  57. %>

Report this snippet  

You need to login to post a comment.