Category Archives: OpenOffice

Fuel Consumption LibreOffice Calc Macro

Here’s a LibreOffice (former Basic macro calculating current fuel consumption in litre/100km.
It needs three input arguments:

  1. Final Injection Amount (Injection Quantity) [mm³/stroke]
  2. Engine Speed [rpm]
  3. Vehicle Speed [kph]

Note: When accelerating at low speeds such instant consumption value can be very high (> 100 litre/100km).
Current consumption is mostly useful at constant vehicle speed (cruise control) or you can average many/all calculated values using Calc’s “=AVERAGE(range...)” function.

' Fuel consumption [litre/100km] for Subaru Diesel assuming 4 cylinders
' (Final Injection Amount [mm3/stroke], Engine Speed [rpm], Vehicle Speed [kph])
Function Fuel100km(ByVal FIA, ByVal RPM, ByVal VSPEED)
   If Not IsNumeric(VSPEED) Or VSPEED < 1 Or Not IsNumeric(FIA) Or Not IsNumeric(RPM) Then
      Fuel100km = ""
      Fuel100km = 0.012 * FIA * RPM / VSPEED
   End If
End Function


Gear Number OpenOffice Calc Macro

Derived from engine speed vs. vehicle speed math, here’s an Basic macro calculating gear numbers. Again values are for EDM Impreza 2.0 Diesel. Calc using macro formula

' Usage: GearNum(Engine Speed [rpm], Vehicle Speed [kph])
' Does not require clutch and neutral input
' but yields invalid values in neutral and when clutch depressed!
Function GearNum(ByVal rpm, ByVal velocity)
  Const Invalid = ""
  If Not IsNumeric(velocity) Or velocity < 1 Or Not IsNumeric(rpm) then
    GearNum = Invalid
    Dim factor As Double
    factor = rpm / velocity
    Select Case factor
      ' range values calculated using 5% tolerance
      Case 108.669 To 120.108
	      GearNum = 1
      Case 55.0583 To 60.8539
	      GearNum = 2
      Case 33.4125 To 36.9296
	      GearNum = 3
      Case 24.6976 To 27.2973
	      GearNum = 4
      Case 19.9468 To 22.0465
	      GearNum = 5
      Case 17.5243 To 19.3689
	      GearNum = 6
      Case Else
	      ' neutral or clutch depressed
	      GearNum = Invalid
    End Select
  End If
End Function

If you always log clutch and neutral switches you could add those as inputs to the macro. Then check (if…then..) to prevent invalid output.