2016-04-29 05:40:34 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Config
|
|
|
|
|
|
{
|
|
|
|
|
|
public enum Unit
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
2016-08-02 11:42:26 +00:00
|
|
|
|
|
|
|
|
|
|
l, /// * 1 liter
|
|
|
|
|
|
m3, /// 1000 l
|
|
|
|
|
|
gal_UK, /// 1 gal(UK) = 4.54609 l
|
|
|
|
|
|
gal_US, /// 1 gal(US) = 3.78541178 l
|
|
|
|
|
|
|
|
|
|
|
|
lph, /// 1 liter/h
|
|
|
|
|
|
m3ph, /// * 1 m3/h = 1000 l/h
|
|
|
|
|
|
|
|
|
|
|
|
g, /// 0.001 kg
|
|
|
|
|
|
kg, /// * 1 kilogram
|
|
|
|
|
|
t, /// 1000 kg
|
|
|
|
|
|
lb, /// 0.45359237 kg
|
|
|
|
|
|
|
|
|
|
|
|
C, /// * degree Celsius
|
|
|
|
|
|
F, /// degree Fahrenheit
|
|
|
|
|
|
K, /// degree Kelvin
|
|
|
|
|
|
|
|
|
|
|
|
Pa, /// 1 Pa = 0.01 hPa
|
|
|
|
|
|
hPa, /// 1 hPa = 100 Pa
|
|
|
|
|
|
kPa, /// 1 kPa = 10 HPa
|
|
|
|
|
|
MPa, /// 1 MPa = 10000 hPa
|
|
|
|
|
|
mbar, /// 1 mbar = 1 hPa = 100 Pa
|
|
|
|
|
|
bar, /// * 1 Bar = 1000 mbar = 0.1 MPa = 100000 Pa
|
|
|
|
|
|
inHg, /// 1 inHg = 33.864 hPa
|
|
|
|
|
|
|
|
|
|
|
|
Pct, /// * 1 %
|
|
|
|
|
|
Promile, /// 1 promile = 0.1 %
|
|
|
|
|
|
|
|
|
|
|
|
mm, /// * 1 millimeter
|
|
|
|
|
|
cm, /// 1 cm = 10 mm
|
|
|
|
|
|
m, /// 1 m = 1000 mm
|
|
|
|
|
|
inch, /// 1 inch = 25.4 mm
|
|
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
Count
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class Units
|
|
|
|
|
|
{
|
|
|
|
|
|
public static double ConvertTo(Unit units, double v)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (units)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Volume: internal representation in l
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.l: return v; /// 1 liter
|
|
|
|
|
|
case Unit.m3: return 0.001 * v; /// 1000 l
|
|
|
|
|
|
case Unit.gal_UK: return 0.21996925 * v; /// 1 gal(UK) = 4.54609 l
|
|
|
|
|
|
case Unit.gal_US: return 0.26417205 * v; /// 1 gal(US) = 3.78541178 l
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Flow: internal representation in m3/h
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.lph: return 1000 * v; /// 1 liter/h
|
|
|
|
|
|
case Unit.m3ph: return v; /// 1 m3/h = 1000 l/h
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Mass: internal representation in kg
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.g: return 1000 * v; /// 1 g = 0.001 kg
|
|
|
|
|
|
case Unit.kg: return v; /// 1 kilogram
|
|
|
|
|
|
case Unit.t: return 0.001 * v; /// 1 t = 1000 kg
|
|
|
|
|
|
case Unit.lb: return 2.2046226 * v; /// 1 lb = 0.45359237 kg
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Temperature: internal representation in degree C
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.C: return v; /// degree Celsius
|
|
|
|
|
|
case Unit.F: return 1.8 * v + 32; /// degree Fahrenheit
|
|
|
|
|
|
case Unit.K: return v + 273.15; /// degree Kelvin
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
2016-08-02 11:42:26 +00:00
|
|
|
|
/// Pressure: internal representation in bar = 0.1 MPa
|
|
|
|
|
|
case Unit.Pa: return 100000 * v; /// 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.hPa: return 1000 * v; /// 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.mbar: return 1000 * v; /// 1 mbar = 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.kPa: return 100 * v; /// 1 kPa = 10 HPa
|
|
|
|
|
|
case Unit.bar: return v; /// 1 bar = 1000 mbar = 100000 Pa
|
|
|
|
|
|
case Unit.MPa: return 0.1 * v; /// 1 MPa = 10000 hPa
|
|
|
|
|
|
case Unit.inHg: return 29.53 * v; /// 1 inHg = 33.864 hPa
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
2016-05-01 08:04:05 +00:00
|
|
|
|
/// Error: internal representation in %
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.Pct: return v; /// 1 %
|
|
|
|
|
|
case Unit.Promile: return 10 * v; /// 1 promile = 0.1 %
|
|
|
|
|
|
|
|
|
|
|
|
/// Diameter, length: internal representation in mm
|
|
|
|
|
|
case Unit.mm: return v; /// 1 mm
|
|
|
|
|
|
case Unit.cm: return 0.1 * v; /// 1 cm = 10 mm
|
|
|
|
|
|
case Unit.m: return 0.001 * v; /// 1 m = 1000 mm
|
|
|
|
|
|
case Unit.inch: return v / 25.4; /// 1 inch = 25.4 mm
|
2016-05-01 08:04:05 +00:00
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
default: return v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static double ConvertFrom(Unit units, double v)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (units)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Volume: internal representation in l
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.l: return v; /// 1 liter
|
|
|
|
|
|
case Unit.m3: return 1000 * v; /// 1000 l
|
|
|
|
|
|
case Unit.gal_UK: return 4.54609 * v; /// 1 gal(UK) = 4.54609 l
|
|
|
|
|
|
case Unit.gal_US: return 3.78541178 * v; /// 1 gal(US) = 3.78541178 l
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Flow: internal representation in m3/h
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.lph: return 0.001 * v; /// 1 liter/h
|
|
|
|
|
|
case Unit.m3ph: return v; /// 1 m3/h = 1000 l/h
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Mass: internal representation in kg
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.g: return 0.001 * v; /// 1 g = 0.001 kg
|
|
|
|
|
|
case Unit.kg: return v; /// 1 kilogram
|
|
|
|
|
|
case Unit.t: return 1000 * v; /// 1 t = 1000 kg
|
|
|
|
|
|
case Unit.lb: return 0.45359237 * v; /// 1 lb = 0.45359237 kg
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
/// Temperature: internal representation in degree C
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.C: return v; /// degree Celsius
|
|
|
|
|
|
case Unit.F: return 5 * (v-32) / 9; /// degree Fahrenheit
|
|
|
|
|
|
case Unit.K: return v - 273.15; /// degree Kelvin
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
2016-08-02 11:42:26 +00:00
|
|
|
|
/// Pressure: internal representation in bar = 0.1 MPa
|
|
|
|
|
|
case Unit.Pa: return 0.00001 * v; /// 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.hPa: return 0.001 * v; /// 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.mbar: return 0.001 * v; /// 1 mbar = 1 hPa = 100 Pa
|
|
|
|
|
|
case Unit.kPa: return 0.01 * v; /// 1 kPa = 10 HPa
|
|
|
|
|
|
case Unit.bar: return v; /// 1 bar = 1000 mbar = 100000 Pa
|
|
|
|
|
|
case Unit.MPa: return 10 * v; /// 1 MPa = 10000 hPa
|
|
|
|
|
|
case Unit.inHg: return 0.033864 * v; /// 1 inHg = 33.864 hPa
|
2016-04-29 05:40:34 +00:00
|
|
|
|
|
2016-05-01 08:04:05 +00:00
|
|
|
|
/// Error: internal representation in %
|
2016-05-02 13:26:14 +00:00
|
|
|
|
case Unit.Pct: return v; /// 1 %
|
|
|
|
|
|
case Unit.Promile: return 0.1 * v; /// 1 promile = 0.1 %
|
|
|
|
|
|
|
|
|
|
|
|
/// Diameter, length: internal representation in mm
|
|
|
|
|
|
case Unit.mm: return v; /// 1 mm
|
|
|
|
|
|
case Unit.cm: return 10 * v; /// 1 cm = 10 mm
|
|
|
|
|
|
case Unit.m: return 1000 * v; /// 1 m = 1000 mm
|
|
|
|
|
|
case Unit.inch: return 25.4 * v; /// 1 inch = 25.4 mm
|
2016-05-01 08:04:05 +00:00
|
|
|
|
|
2016-04-29 05:40:34 +00:00
|
|
|
|
default: return v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|