English and US units added.
This commit is contained in:
parent
e27dfe570d
commit
38ee1cc067
276
Config/Units.cs
276
Config/Units.cs
@ -17,14 +17,21 @@ namespace Config
|
|||||||
#else
|
#else
|
||||||
[Description("degree")] degree,
|
[Description("degree")] degree,
|
||||||
#endif
|
#endif
|
||||||
|
[Description("ml")] ml, /// 1 ml = 0.001 l
|
||||||
[Description("l")] l, /// * 1 liter
|
[Description("l")] l, /// * 1 liter
|
||||||
[Description("dm3")] dm3, /// 1 dm3 = 1 liter
|
[Description("dm3")] dm3, /// 1 dm3 = 1 l
|
||||||
[Description("m3")] m3, /// 1000 l
|
[Description("US gal")] USgal, /// 1 US gallon = 3.78541178 l
|
||||||
[Description("gal(UK)")] gal_UK, /// 1 gal(UK) = 4.54609 l
|
[Description("imper.gal")] UKgal, /// 1 imperial gallon = 4.54609 l
|
||||||
[Description("gal(US)")] gal_US, /// 1 gal(US) = 3.78541178 l
|
[Description("cf")] cf, /// 1 cubic foot = 28.316846592 l
|
||||||
|
[Description("m3")] m3, /// 1 m3 = 1000 l
|
||||||
|
|
||||||
[Description("l/h")] lph, /// 1 liter/h
|
[Description("l/h")] lph, /// 1 l/h = 0.001 m3/h
|
||||||
[Description("m3/h")] m3ph, /// * 1 m3/h = 1000 l/h
|
[Description("l/m")] lpm, /// 1 l/m = 60 l/h = 0.06 m3/h
|
||||||
|
[Description("m3/h")] m3ph, /// * 1 m3/h
|
||||||
|
[Description("l/s")] lps, /// 1 liter/s = 3.6 m3/h
|
||||||
|
[Description("US gal/s")] USgalps, /// 1 US gallon per second = 13.627482408 m3/h
|
||||||
|
[Description("m3/m")] m3pm, /// 1 m3/m = 60 m3/h
|
||||||
|
[Description("cf/s")] cfs, /// 1 cubic foot per second = 101.9406477312 m3/h
|
||||||
|
|
||||||
[Description("g")] g, /// 0.001 kg
|
[Description("g")] g, /// 0.001 kg
|
||||||
[Description("lb")] lb, /// 0.45359237 kg
|
[Description("lb")] lb, /// 0.45359237 kg
|
||||||
@ -43,7 +50,7 @@ namespace Config
|
|||||||
[Description("Pa")] Pa, /// 1 Pa = 0.01 hPa
|
[Description("Pa")] Pa, /// 1 Pa = 0.01 hPa
|
||||||
[Description("hPa")] hPa, /// 1 hPa = 100 Pa
|
[Description("hPa")] hPa, /// 1 hPa = 100 Pa
|
||||||
[Description("mbar")] mbar, /// 1 mbar = 1 hPa = 100 Pa
|
[Description("mbar")] mbar, /// 1 mbar = 1 hPa = 100 Pa
|
||||||
[Description("kPa")] kPa, /// 1 kPa = 10 hPa = 10000 Pa
|
[Description("kPa")] kPa, /// 1 kPa = 10 hPa = 1000 Pa
|
||||||
[Description("inHg")] inHg, /// 1 inHg = 33.864 hPa
|
[Description("inHg")] inHg, /// 1 inHg = 33.864 hPa
|
||||||
[Description("psi")] psi, /// 1 psi = 0.0689475729 bar
|
[Description("psi")] psi, /// 1 psi = 0.0689475729 bar
|
||||||
[Description("bar")] bar, /// * 1 Bar = 1000 mbar = 0.1 MPa = 100000 Pa
|
[Description("bar")] bar, /// * 1 Bar = 1000 mbar = 0.1 MPa = 100000 Pa
|
||||||
@ -51,13 +58,16 @@ namespace Config
|
|||||||
|
|
||||||
[Description("R%")] RPct, /// * 1 R%
|
[Description("R%")] RPct, /// * 1 R%
|
||||||
|
|
||||||
[Description("%")] Pct, /// * 1 %
|
|
||||||
[Description("promile")] Promile, /// 1 promile = 0.1 %
|
[Description("promile")] Promile, /// 1 promile = 0.1 %
|
||||||
|
[Description("%")] Pct, /// * 1 %
|
||||||
|
|
||||||
[Description("mm")] mm, /// * 1 millimeter
|
[Description("mm")] mm, /// * 1 millimeter
|
||||||
[Description("cm")] cm, /// 1 cm = 10 mm
|
[Description("cm")] cm, /// 1 cm = 10 mm
|
||||||
[Description("m")] m, /// 1 m = 1000 mm
|
|
||||||
[Description("in")] inch, /// 1 inch = 25.4 mm
|
[Description("in")] inch, /// 1 inch = 25.4 mm
|
||||||
|
[Description("dm")] dm, /// 1 dm = 100 mm
|
||||||
|
[Description("ft")] foot, /// 1 foot = 304.8 mm
|
||||||
|
[Description("yd")] yard, /// 1 yard = 914.4 mm
|
||||||
|
[Description("m")] m, /// 1 m = 1000 mm
|
||||||
|
|
||||||
[Description("kg/m3")] kgpm3, /// * 1 kg/m3 = 0.001 kg/l
|
[Description("kg/m3")] kgpm3, /// * 1 kg/m3 = 0.001 kg/l
|
||||||
[Description("kg/l")] kgpl, /// 1 kg/l = 1000 kg/m3
|
[Description("kg/l")] kgpl, /// 1 kg/l = 1000 kg/m3
|
||||||
@ -70,6 +80,7 @@ namespace Config
|
|||||||
[Description("MWh")] MWh, /// 1 MWh = 3600000000 J
|
[Description("MWh")] MWh, /// 1 MWh = 3600000000 J
|
||||||
|
|
||||||
[Description("uS/cm")] uSpcm, /// * 1 uS/cm
|
[Description("uS/cm")] uSpcm, /// * 1 uS/cm
|
||||||
|
[Description("mS/m")] mSpm, /// 1 mS/m = 10 uS/cm
|
||||||
|
|
||||||
#if LANG_PL
|
#if LANG_PL
|
||||||
[Description("imp/l")] ppl, /// * 1 pulse/l
|
[Description("imp/l")] ppl, /// * 1 pulse/l
|
||||||
@ -82,17 +93,17 @@ namespace Config
|
|||||||
[Description("dm3/stopień")] dm3pdeg, /// * 1 dm3/degree
|
[Description("dm3/stopień")] dm3pdeg, /// * 1 dm3/degree
|
||||||
#else
|
#else
|
||||||
[Description("pulse/l")] ppl, /// * 1 pulse/l
|
[Description("pulse/l")] ppl, /// * 1 pulse/l
|
||||||
[Description("pulse/dm3")] ppdm3, /// * 1 pulse/dm3
|
[Description("pulse/dm3")] ppdm3, /// 1 pulse/dm3
|
||||||
[Description("degree/l")] degpl, /// * 1 degree/l
|
[Description("degree/l")] degpl, /// 1 degree/l
|
||||||
[Description("degree/dm3")] degpdm3, /// * 1 degree/dm3
|
[Description("degree/dm3")] degpdm3, /// 1 degree/dm3
|
||||||
[Description("l/pulse")] lpp, /// * 1 l/pulse
|
[Description("l/pulse")] lpp, /// 1 l/pulse
|
||||||
[Description("dm3/pulse")] dm3pp, /// * 1 dm3/pulse
|
[Description("dm3/pulse")] dm3pp, /// 1 dm3/pulse
|
||||||
[Description("l/degree")] lpdeg, /// * 1 l/degree
|
[Description("l/degree")] lpdeg, /// 1 l/degree
|
||||||
[Description("dm3/degree")] dm3pdeg, /// * 1 dm3/degree
|
[Description("dm3/degree")] dm3pdeg, /// 1 dm3/degree
|
||||||
#endif
|
#endif
|
||||||
///
|
///
|
||||||
[Description("pulse/kWh")] ppkWh, /// * 1 pulse/kWh
|
[Description("pulse/kWh")] ppkWh, /// * 1 pulse/kWh
|
||||||
[Description("kWh/pulse")] kWhpp, /// * 1 kWh/pulse
|
[Description("kWh/pulse")] kWhpp, /// 1 kWh/pulse
|
||||||
|
|
||||||
Count
|
Count
|
||||||
}
|
}
|
||||||
@ -228,8 +239,9 @@ namespace Config
|
|||||||
|
|
||||||
public static bool IsDefaultUnit(Unit unit)
|
public static bool IsDefaultUnit(Unit unit)
|
||||||
{
|
{
|
||||||
return unit == Unit.l || unit == Unit.m3ph || unit == Unit.kg || unit == Unit.s || unit == Unit.C || unit == Unit.bar || unit == Unit.RPct ||
|
return unit == Unit.l || unit == Unit.m3ph || unit == Unit.kg || unit == Unit.s || unit == Unit.C ||
|
||||||
unit == Unit.Pct || unit == Unit.mm || unit == Unit.kgpm3 || unit == Unit.J || unit == Unit.ppl || unit == Unit.ppkWh || unit == Unit.uSpcm;
|
unit == Unit.bar || unit == Unit.RPct || unit == Unit.Pct || unit == Unit.mm || unit == Unit.kgpm3 ||
|
||||||
|
unit == Unit.J || unit == Unit.uSpcm || unit == Unit.ppl || unit == Unit.ppkWh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsQuantity(Unit units, Quantity quantity)
|
public static bool IsQuantity(Unit units, Quantity quantity)
|
||||||
@ -243,35 +255,42 @@ namespace Config
|
|||||||
{
|
{
|
||||||
case Unit.pulse:
|
case Unit.pulse:
|
||||||
case Unit.degree:
|
case Unit.degree:
|
||||||
return Config.Quantity.Pulses;
|
return Quantity.Pulses;
|
||||||
|
|
||||||
|
case Unit.ml:
|
||||||
case Unit.l:
|
case Unit.l:
|
||||||
case Unit.dm3:
|
case Unit.dm3:
|
||||||
|
case Unit.USgal:
|
||||||
|
case Unit.UKgal:
|
||||||
|
case Unit.cf:
|
||||||
case Unit.m3:
|
case Unit.m3:
|
||||||
case Unit.gal_UK:
|
return Quantity.Volume;
|
||||||
case Unit.gal_US:
|
|
||||||
return Config.Quantity.Volume;
|
|
||||||
|
|
||||||
case Unit.lph:
|
case Unit.lph:
|
||||||
|
case Unit.lpm:
|
||||||
case Unit.m3ph:
|
case Unit.m3ph:
|
||||||
return Config.Quantity.Flow;
|
case Unit.lps:
|
||||||
|
case Unit.USgalps:
|
||||||
|
case Unit.m3pm:
|
||||||
|
case Unit.cfs:
|
||||||
|
return Quantity.Flow;
|
||||||
|
|
||||||
case Unit.g:
|
case Unit.g:
|
||||||
|
case Unit.lb:
|
||||||
case Unit.kg:
|
case Unit.kg:
|
||||||
case Unit.t:
|
case Unit.t:
|
||||||
case Unit.lb:
|
return Quantity.Mass;
|
||||||
return Config.Quantity.Mass;
|
|
||||||
|
|
||||||
|
case Unit.ms:
|
||||||
case Unit.s:
|
case Unit.s:
|
||||||
case Unit.min:
|
case Unit.min:
|
||||||
case Unit.hour:
|
case Unit.hour:
|
||||||
case Unit.ms:
|
return Quantity.Time;
|
||||||
return Config.Quantity.Time;
|
|
||||||
|
|
||||||
case Unit.C:
|
case Unit.C:
|
||||||
case Unit.F:
|
case Unit.F:
|
||||||
case Unit.K:
|
case Unit.K:
|
||||||
return Config.Quantity.Temperature;
|
return Quantity.Temperature;
|
||||||
|
|
||||||
case Unit.Pa:
|
case Unit.Pa:
|
||||||
case Unit.hPa:
|
case Unit.hPa:
|
||||||
@ -281,24 +300,27 @@ namespace Config
|
|||||||
case Unit.psi:
|
case Unit.psi:
|
||||||
case Unit.bar:
|
case Unit.bar:
|
||||||
case Unit.MPa:
|
case Unit.MPa:
|
||||||
return Config.Quantity.Pressure;
|
return Quantity.Pressure;
|
||||||
|
|
||||||
case Unit.RPct:
|
case Unit.RPct:
|
||||||
return Config.Quantity.Humidity;
|
return Quantity.Humidity;
|
||||||
|
|
||||||
case Unit.Pct:
|
|
||||||
case Unit.Promile:
|
case Unit.Promile:
|
||||||
return Config.Quantity.Error;
|
case Unit.Pct:
|
||||||
|
return Quantity.Error;
|
||||||
|
|
||||||
case Unit.mm:
|
case Unit.mm:
|
||||||
case Unit.cm:
|
case Unit.cm:
|
||||||
case Unit.m:
|
|
||||||
case Unit.inch:
|
case Unit.inch:
|
||||||
return Config.Quantity.Length;
|
case Unit.dm:
|
||||||
|
case Unit.foot:
|
||||||
|
case Unit.yard:
|
||||||
|
case Unit.m:
|
||||||
|
return Quantity.Length;
|
||||||
|
|
||||||
case Unit.kgpm3:
|
case Unit.kgpm3:
|
||||||
case Unit.kgpl:
|
case Unit.kgpl:
|
||||||
return Config.Quantity.Density;
|
return Quantity.Density;
|
||||||
|
|
||||||
case Unit.J:
|
case Unit.J:
|
||||||
case Unit.kJ:
|
case Unit.kJ:
|
||||||
@ -306,7 +328,11 @@ namespace Config
|
|||||||
case Unit.Wh:
|
case Unit.Wh:
|
||||||
case Unit.kWh:
|
case Unit.kWh:
|
||||||
case Unit.MWh:
|
case Unit.MWh:
|
||||||
return Config.Quantity.Energy;
|
return Quantity.Energy;
|
||||||
|
|
||||||
|
case Unit.uSpcm:
|
||||||
|
case Unit.mSpm:
|
||||||
|
return Quantity.Conductivity;
|
||||||
|
|
||||||
case Unit.ppl:
|
case Unit.ppl:
|
||||||
case Unit.ppdm3:
|
case Unit.ppdm3:
|
||||||
@ -316,17 +342,14 @@ namespace Config
|
|||||||
case Unit.dm3pp:
|
case Unit.dm3pp:
|
||||||
case Unit.lpdeg:
|
case Unit.lpdeg:
|
||||||
case Unit.dm3pdeg:
|
case Unit.dm3pdeg:
|
||||||
return Config.Quantity.PulsePerLtr;
|
return Quantity.PulsePerLtr;
|
||||||
|
|
||||||
case Unit.ppkWh:
|
case Unit.ppkWh:
|
||||||
case Unit.kWhpp:
|
case Unit.kWhpp:
|
||||||
return Config.Quantity.PulsePerKWh;
|
return Quantity.PulsePerKWh;
|
||||||
|
|
||||||
case Unit.uSpcm:
|
|
||||||
return Config.Quantity.Conductivity;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Config.Quantity.Number;
|
return Quantity.Number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,78 +370,80 @@ namespace Config
|
|||||||
public static bool IsConductivity(Unit units) { return IsQuantity(units, Config.Quantity.Conductivity); }
|
public static bool IsConductivity(Unit units) { return IsQuantity(units, Config.Quantity.Conductivity); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static double ConvertTo(Unit units, double v)
|
public static double ConvertTo(Unit units, double v)
|
||||||
{
|
{
|
||||||
switch (units)
|
switch (units)
|
||||||
{
|
{
|
||||||
/// Volume: internal representation in l
|
/// Volume: internal representation in l
|
||||||
case Unit.dm3:
|
case Unit.ml: return 1000 * v; /// 1 ml = 0.001 l
|
||||||
case Unit.l: return v; /// 1 liter
|
case Unit.USgal: return 0.26417205 * v; /// 1 gal(US) = 3.78541178 l
|
||||||
case Unit.m3: return 0.001 * v; /// 1 m3 = 1000 l
|
case Unit.UKgal: return 0.21996925 * v; /// 1 gal(UK) = 4.54609 l
|
||||||
case Unit.gal_UK: return 0.21996925 * v; /// 1 gal(UK) = 4.54609 l
|
case Unit.cf: return 0.0353146667215 * v; /// 1 cubic foot = 28.316846592 l
|
||||||
case Unit.gal_US: return 0.26417205 * v; /// 1 gal(US) = 3.78541178 l
|
case Unit.m3: return 0.001 * v; /// 1 m3 = 1000 l
|
||||||
|
|
||||||
/// Flow: internal representation in m3/h
|
/// Flow: internal representation in m3/h
|
||||||
case Unit.lph: return 1000 * v; /// 1 liter/h
|
case Unit.lph: return 1000 * v; /// 1 l/h
|
||||||
case Unit.m3ph: return v; /// 1 m3/h = 1000 l/h
|
case Unit.lpm: return v / 0.06; /// 1 l/m
|
||||||
|
case Unit.lps: return v / 3.6; /// 1 l/s
|
||||||
|
case Unit.USgalps: return 0.733811257326 * v; /// 1 US gallon per second
|
||||||
|
case Unit.m3pm: return v / 60; /// 1 m3/m
|
||||||
|
case Unit.cfs: return 0.009809629644858 * v; /// 1 cubic foot per second
|
||||||
|
|
||||||
/// Mass: internal representation in kg
|
/// Mass: internal representation in kg
|
||||||
case Unit.g: return 1000 * v; /// 1 g = 0.001 kg
|
case Unit.g: return 1000 * v; /// 1 g = 0.001 kg
|
||||||
case Unit.kg: return v; /// 1 kilogram
|
case Unit.lb: return 2.2046226 * v; /// 1 lb = 0.45359237 kg
|
||||||
case Unit.t: return 0.001 * v; /// 1 t = 1000 kg
|
case Unit.t: return 0.001 * v; /// 1 t = 1000 kg
|
||||||
case Unit.lb: return 2.2046226 * v; /// 1 lb = 0.45359237 kg
|
|
||||||
|
|
||||||
/// Time or duration: internal representation in seconds [s]
|
/// Time or duration: internal representation in seconds [s]
|
||||||
case Unit.s: return v;
|
case Unit.ms: return 1000 * v;
|
||||||
case Unit.min: return v / 60;
|
case Unit.min: return v / 60;
|
||||||
case Unit.hour: return v / 3600;
|
case Unit.hour: return v / 3600;
|
||||||
case Unit.ms: return 1000 * v;
|
|
||||||
|
|
||||||
/// Temperature: internal representation in °C
|
/// Temperature: internal representation in °C
|
||||||
case Unit.C: return v; /// degree Celsius (°C)
|
case Unit.F: return 1.8 * v + 32; /// degree Fahrenheit
|
||||||
case Unit.F: return 1.8 * v + 32; /// degree Fahrenheit
|
case Unit.K: return v + 273.15; /// degree Kelvin
|
||||||
case Unit.K: return v + 273.15; /// degree Kelvin
|
|
||||||
|
|
||||||
/// Pressure: internal representation in bar = 0.1 MPa
|
/// Pressure: internal representation in bar = 0.1 MPa
|
||||||
case Unit.Pa: return 100000 * v; /// 1 hPa = 100 Pa
|
case Unit.Pa: return 100000 * v; /// 1 hPa = 100 Pa
|
||||||
case Unit.hPa: return 1000 * 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.mbar: return 1000 * v; /// 1 mbar = 1 hPa = 100 Pa
|
||||||
case Unit.kPa: return 100 * v; /// 1 kPa = 10 HPa
|
case Unit.kPa: return 100 * v; /// 1 kPa = 10 HPa
|
||||||
case Unit.inHg: return 29.53 * v; /// 1 inHg =
|
case Unit.inHg: return 29.53 * v; /// 1 inHg =
|
||||||
case Unit.psi: return 14.50377378 * v; /// 1 psi =
|
case Unit.psi: return 14.5037738 * v; /// 1 psi =
|
||||||
case Unit.bar: return v; /// 1 bar = 1000 mbar = 100000 Pa
|
case Unit.MPa: return 0.1 * v; /// 1 MPa = 10000 hPa
|
||||||
case Unit.MPa: return 0.1 * v; /// 1 MPa = 10000 hPa
|
|
||||||
|
|
||||||
/// Error: internal representation in %
|
/// Relative error: internal representation in %
|
||||||
case Unit.Pct: return v; /// 1 %
|
case Unit.Promile: return 10 * v; /// 1 promile = 0.1 %
|
||||||
case Unit.Promile: return 10 * v; /// 1 promile = 0.1 %
|
|
||||||
|
|
||||||
/// Diameter, length: internal representation in mm
|
/// 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.cm: return 0.1 * v; /// 1 cm = 10 mm
|
case Unit.inch: return v / 25.4; /// 1 inch = 25.4 mm
|
||||||
case Unit.m: return 0.001 * v; /// 1 m = 1000 mm
|
case Unit.dm: return 0.01 * v; /// 1 dm = 100 mm
|
||||||
case Unit.inch: return v / 25.4; /// 1 inch = 25.4 mm
|
case Unit.foot: return v / 304.8; /// 1 foot = 304.8 mm
|
||||||
|
case Unit.yard: return v / 914.4; /// 1 yard = 914,4 mm
|
||||||
|
case Unit.m: return 0.001 * v; /// 1 m = 1000 mm
|
||||||
|
|
||||||
/// Density: internal representation in kg/m3
|
/// Density: internal representation in kg/m3
|
||||||
case Unit.kgpm3: return v;
|
|
||||||
case Unit.kgpl: return 0.001 * v;
|
case Unit.kgpl: return 0.001 * v;
|
||||||
|
|
||||||
/// Energy, internal representation in Joul
|
/// Energy, internal representation in Joul
|
||||||
case Unit.J: return v; /// 1 Joul
|
case Unit.kJ: return 0.001 * v; /// 1 kJ = 1000 J
|
||||||
case Unit.kJ: return 0.001 * v; /// 1 kJ = 1000 J
|
case Unit.MJ: return 0.000001 * v; /// 1 kJ = 1000000 J
|
||||||
case Unit.MJ: return 0.000001 * v; /// 1 kJ = 1000000 J
|
case Unit.Wh: return v / 3600.0; /// 1 Wh = 3600 J
|
||||||
case Unit.Wh: return v / 3600.0; /// 1 Wh = 3600 J
|
case Unit.kWh: return v / 3600000.0; /// 1 kWh = 3600000 J
|
||||||
case Unit.kWh: return v / 3600000.0; /// 1 kWh = 3600000 J
|
case Unit.MWh: return v / 3600000000.0; /// 1 MWh = 3600000000 J
|
||||||
case Unit.MWh: return v / 3600000000.0;/// 1 MWh = 3600000000 J
|
|
||||||
|
|
||||||
|
/// Electrical conductivity
|
||||||
|
case Unit.mSpm: return 0.1 * v;
|
||||||
|
|
||||||
|
/// Invert pulses
|
||||||
case Unit.kWhpp:
|
case Unit.kWhpp:
|
||||||
case Unit.lpp:
|
case Unit.lpp:
|
||||||
case Unit.dm3pp:
|
case Unit.dm3pp:
|
||||||
case Unit.lpdeg:
|
case Unit.lpdeg:
|
||||||
case Unit.dm3pdeg: return ((v <= float.Epsilon) ? 0 : 1 / v);
|
case Unit.dm3pdeg: return (v <= float.Epsilon) ? 0 : 1/v;
|
||||||
|
|
||||||
default: return v;
|
default: return v; /// Do not convert
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,72 +452,75 @@ namespace Config
|
|||||||
switch (units)
|
switch (units)
|
||||||
{
|
{
|
||||||
/// Volume: internal representation in l
|
/// Volume: internal representation in l
|
||||||
case Unit.dm3:
|
case Unit.ml: return 0.001 * v; /// 0.001 l
|
||||||
case Unit.l: return v; /// 1 liter
|
case Unit.USgal: return 3.78541178 * v; /// 1 gal(US) = 3.78541178 l
|
||||||
case Unit.m3: return 1000 * v; /// 1000 l
|
case Unit.UKgal: return 4.54609 * v; /// 1 gal(UK) = 4.54609 l
|
||||||
case Unit.gal_UK: return 4.54609 * v; /// 1 gal(UK) = 4.54609 l
|
case Unit.cf: return 28.316846592 * v; /// 1 cubic foot = 28.316846592 l
|
||||||
case Unit.gal_US: return 3.78541178 * v; /// 1 gal(US) = 3.78541178 l
|
case Unit.m3: return 1000 * v; /// 1000 l
|
||||||
|
|
||||||
/// Flow: internal representation in m3/h
|
/// Flow: internal representation in m3/h
|
||||||
case Unit.lph: return 0.001 * v; /// 1 liter/h
|
case Unit.lph: return 0.001 * v; /// 1 l/h
|
||||||
case Unit.m3ph: return v; /// 1 m3/h = 1000 l/h
|
case Unit.lpm: return 0.06 * v; /// 1 l/m
|
||||||
|
case Unit.lps: return 3.6 * v; /// 1 l/s
|
||||||
|
case Unit.USgalps: return 13.627482408 * v; /// 1 US gallon per second
|
||||||
|
case Unit.m3pm: return 60 * v; /// 1 m3/m
|
||||||
|
case Unit.cfs: return 101.9406477312 * v; /// 1 cubic foot per second
|
||||||
|
|
||||||
/// Mass: internal representation in kg
|
/// Mass: internal representation in kg
|
||||||
case Unit.g: return 0.001 * v; /// 1 g = 0.001 kg
|
case Unit.g: return 0.001 * v; /// 1 g = 0.001 kg
|
||||||
case Unit.kg: return v; /// 1 kilogram
|
case Unit.lb: return 0.45359237 * v; /// 1 lb = 0.45359237 kg
|
||||||
case Unit.t: return 1000 * v; /// 1 t = 1000 kg
|
case Unit.t: return 1000 * v; /// 1 t = 1000 kg
|
||||||
case Unit.lb: return 0.45359237 * v; /// 1 lb = 0.45359237 kg
|
|
||||||
|
|
||||||
/// Time or duration: internal representation in seconds [s]
|
/// Time or duration: internal representation in seconds [s]
|
||||||
case Unit.s: return v;
|
case Unit.ms: return 0.001 * v;
|
||||||
case Unit.min: return 60 * v;
|
case Unit.min: return 60 * v;
|
||||||
case Unit.hour: return 3600 * v;
|
case Unit.hour: return 3600 * v;
|
||||||
case Unit.ms: return v / 1000;
|
|
||||||
|
|
||||||
/// Temperature: internal representation in °C
|
/// Temperature: internal representation in °C
|
||||||
case Unit.C: return v; /// degree Celsius (°C)
|
case Unit.F: return 5 * (v - 32) / 9; /// degree Fahrenheit
|
||||||
case Unit.F: return 5 * (v-32) / 9; /// degree Fahrenheit
|
case Unit.K: return v - 273.15; /// degree Kelvin
|
||||||
case Unit.K: return v - 273.15; /// degree Kelvin
|
|
||||||
|
|
||||||
/// Pressure: internal representation in bar = 0.1 MPa
|
/// Pressure: internal representation in bar = 0.1 MPa
|
||||||
case Unit.Pa: return 0.00001 * v; /// 1 hPa = 100 Pa
|
case Unit.Pa: return 0.00001 * v; /// 1 hPa = 100 Pa
|
||||||
case Unit.hPa: return 0.001 * 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.mbar: return 0.001 * v; /// 1 mbar = 1 hPa = 100 Pa
|
||||||
case Unit.kPa: return 0.01 * v; /// 1 kPa = 10 HPa
|
case Unit.kPa: return 0.01 * v; /// 1 kPa = 10 HPa
|
||||||
case Unit.inHg: return 0.033864 * v; /// 1 inHg = 33.864 hPa
|
case Unit.inHg: return 0.033864 * v; /// 1 inHg = 33.864 hPa
|
||||||
case Unit.psi: return 0.0689475729 * v;/// 1 psi = 0.0689475729 bar
|
case Unit.psi: return 0.0689475729 * v; /// 1 psi = 0.0689475729 bar
|
||||||
case Unit.bar: return v; /// 1 bar = 1000 mbar = 100000 Pa
|
case Unit.MPa: return 10 * v; /// 1 MPa = 10000 hPa
|
||||||
case Unit.MPa: return 10 * v; /// 1 MPa = 10000 hPa
|
|
||||||
|
|
||||||
/// Error: internal representation in %
|
/// Relative error: internal representation in %
|
||||||
case Unit.Pct: return v; /// 1 %
|
case Unit.Promile: return 0.1 * v; /// 1 promile = 0.1 %
|
||||||
case Unit.Promile: return 0.1 * v; /// 1 promile = 0.1 %
|
|
||||||
|
|
||||||
/// Diameter, length: internal representation in mm
|
/// 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.cm: return 10 * v; /// 1 cm = 10 mm
|
case Unit.inch: return 25.4 * v; /// 1 inch = 25.4 mm
|
||||||
case Unit.m: return 1000 * v; /// 1 m = 1000 mm
|
case Unit.dm: return 100 * v; /// 1 dm = 100 mm
|
||||||
case Unit.inch: return 25.4 * v; /// 1 inch = 25.4 mm
|
case Unit.foot: return 304.8 * v; /// 1 foot = 304.8 mm
|
||||||
|
case Unit.yard: return 914.4 * v; /// 1 yard = 914,4 mm
|
||||||
|
case Unit.m: return 1000 * v; /// 1 m = 1000 mm
|
||||||
|
|
||||||
/// Density: internal representation in kg/m3
|
/// Density: internal representation in kg/m3
|
||||||
case Unit.kgpm3: return v;
|
|
||||||
case Unit.kgpl: return 1000 * v;
|
case Unit.kgpl: return 1000 * v;
|
||||||
|
|
||||||
/// Energy, internal representation in Joul
|
/// Energy, internal representation in Joul
|
||||||
case Unit.J: return v; /// 1 Joul
|
case Unit.kJ: return 1000 * v; /// 1 kJ = 1000 J
|
||||||
case Unit.kJ: return 1000 * v; /// 1 kJ = 1000 J
|
case Unit.MJ: return 1000000 * v; /// 1 kJ = 1000000 J
|
||||||
case Unit.MJ: return 1000000 * v; /// 1 kJ = 1000000 J
|
case Unit.Wh: return 3600 * v; /// 1 Wh = 3600 J
|
||||||
case Unit.Wh: return 3600 * v; /// 1 Wh = 3600 J
|
case Unit.kWh: return 3600000 * v; /// 1 kWh = 3600000 J
|
||||||
case Unit.kWh: return 3600000 * v; /// 1 kWh = 3600000 J
|
case Unit.MWh: return 3600000000 * v; /// 1 kWh = 3600000000 J
|
||||||
case Unit.MWh: return 3600000000 * v; /// 1 kWh = 3600000000 J
|
|
||||||
|
|
||||||
|
/// Electrical conductivity
|
||||||
|
case Unit.mSpm: return 10 * v;
|
||||||
|
|
||||||
|
/// Invert
|
||||||
case Unit.kWhpp:
|
case Unit.kWhpp:
|
||||||
case Unit.lpp:
|
case Unit.lpp:
|
||||||
case Unit.dm3pp:
|
case Unit.dm3pp:
|
||||||
case Unit.lpdeg:
|
case Unit.lpdeg:
|
||||||
case Unit.dm3pdeg: return ((v == 0) ? 0 : 1 / v);
|
case Unit.dm3pdeg: return (v <= float.Epsilon) ? 0 : 1/v;
|
||||||
|
|
||||||
default: return v;
|
default: return v; /// Do not convert
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,22 +13,28 @@ namespace DataStreamInterface
|
|||||||
degree,
|
degree,
|
||||||
|
|
||||||
/// Volume
|
/// Volume
|
||||||
ml, /// 0.001 l
|
ml, /// 1 ml = 0.001 l
|
||||||
l, /// * 1 liter = 1 l
|
l, /// * 1 liter
|
||||||
dm3, /// 1 dm3 = 1 l
|
dm3, /// 1 dm3 = 1 l
|
||||||
m3, /// 1000 l
|
USgal, /// 1 US gallon = 3.78541178 l
|
||||||
gal_UK, /// 1 gal(UK) = 4.54609 l
|
UKgal, /// 1 imperial gallon = 4.54609 l
|
||||||
gal_US, /// 1 gal(US) = 3.78541178 l
|
cf, /// 1 cubic foot = 28.316846592 l
|
||||||
|
m3, /// 1 m3 = 1000 l
|
||||||
|
|
||||||
/// Flow
|
/// Flow
|
||||||
lph, /// 1 liter/h
|
lph, /// 1 l/h = 0.001 m3/h
|
||||||
m3ph, /// * 1 m3/h = 1000 l/h
|
lpm, /// 1 l/m = 60 l/h = 0.06 m3/h
|
||||||
|
m3ph, /// * 1 m3/h
|
||||||
|
lps, /// 1 liter/s = 3.6 m3/h
|
||||||
|
USgalps, /// 1 US gallon per second = 13.627482408 m3/h
|
||||||
|
m3pm, /// 1 m3/m = 60 m3/h
|
||||||
|
cfs, /// 1 cubic foot per second = 101.9406477312 m3/h
|
||||||
|
|
||||||
/// Mass
|
/// Mass
|
||||||
g, /// 0.001 kg
|
g, /// 0.001 kg
|
||||||
|
lb, /// 0.45359237 kg
|
||||||
kg, /// * 1 kilogram
|
kg, /// * 1 kilogram
|
||||||
t, /// 1000 kg
|
t, /// 1000 kg
|
||||||
lb, /// 0.45359237 kg
|
|
||||||
|
|
||||||
/// Time
|
/// Time
|
||||||
ms, /// 1 ms = 0.001 s
|
ms, /// 1 ms = 0.001 s
|
||||||
@ -47,6 +53,7 @@ namespace DataStreamInterface
|
|||||||
mbar, /// 1 mbar = 1 hPa = 100 Pa
|
mbar, /// 1 mbar = 1 hPa = 100 Pa
|
||||||
kPa, /// 1 kPa = 10 HPa
|
kPa, /// 1 kPa = 10 HPa
|
||||||
inHg, /// 1 inHg = 33.864 hPa
|
inHg, /// 1 inHg = 33.864 hPa
|
||||||
|
psi, /// 1 psi = 0.0689475729 bar
|
||||||
bar, /// * 1 Bar = 1000 mbar = 0.1 MPa = 100000 Pa
|
bar, /// * 1 Bar = 1000 mbar = 0.1 MPa = 100000 Pa
|
||||||
MPa, /// 1 MPa = 10000 hPa
|
MPa, /// 1 MPa = 10000 hPa
|
||||||
|
|
||||||
@ -61,7 +68,9 @@ namespace DataStreamInterface
|
|||||||
mm, /// * 1 millimeter
|
mm, /// * 1 millimeter
|
||||||
cm, /// 1 cm = 10 mm
|
cm, /// 1 cm = 10 mm
|
||||||
inch, /// 1 inch = 25.4 mm
|
inch, /// 1 inch = 25.4 mm
|
||||||
|
dm, /// 1 dm = 100 mm
|
||||||
foot, /// 1 foot = 304.8 mm
|
foot, /// 1 foot = 304.8 mm
|
||||||
|
yard, /// 1 yard = 914.4 mm
|
||||||
m, /// 1 m = 1000 mm
|
m, /// 1 m = 1000 mm
|
||||||
|
|
||||||
/// Density
|
/// Density
|
||||||
@ -76,20 +85,317 @@ namespace DataStreamInterface
|
|||||||
kWh, /// 1 kWh = 3600000 J
|
kWh, /// 1 kWh = 3600000 J
|
||||||
MWh, /// 1 MWh = 3600000000 J
|
MWh, /// 1 MWh = 3600000000 J
|
||||||
|
|
||||||
|
/// Electrical conductivity
|
||||||
|
uSpcm, /// * 1 uS/cm
|
||||||
|
mSpm, /// 1 mS/m = 10 uS/cm
|
||||||
|
|
||||||
/// Meter coefficient - volume
|
/// Meter coefficient - volume
|
||||||
ppl, /// * 1 pulse/l
|
ppl, /// * 1 pulse/l
|
||||||
ppdm3, /// * 1 pulse/dm3
|
ppdm3, /// 1 pulse/dm3
|
||||||
degpl, /// * 1 degree/l
|
degpl, /// 1 degree/l
|
||||||
degpdm3, /// * 1 degree/dm3
|
degpdm3, /// 1 degree/dm3
|
||||||
lpp, /// * 1 l/pulse
|
lpp, /// 1 l/pulse
|
||||||
dm3pp, /// * 1 dm3/pulse
|
dm3pp, /// 1 dm3/pulse
|
||||||
lpdeg, /// * 1 l/degree
|
lpdeg, /// 1 l/degree
|
||||||
dm3pdeg, /// * 1 dm3/degree
|
dm3pdeg, /// 1 dm3/degree
|
||||||
|
|
||||||
/// Meter coefficient - energy
|
/// Meter coefficient - energy
|
||||||
ppkWh, /// * 1 pulse/kWh
|
ppkWh, /// * 1 pulse/kWh
|
||||||
kWhpp, /// * 1 kWh/pulse
|
kWhpp, /// 1 kWh/pulse
|
||||||
|
|
||||||
Count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Quantity
|
||||||
|
{
|
||||||
|
/// Quantities with units and conversions (double -> double)
|
||||||
|
Volume,
|
||||||
|
Flow,
|
||||||
|
Mass,
|
||||||
|
Time,
|
||||||
|
Temperature,
|
||||||
|
Pressure,
|
||||||
|
Humidity,
|
||||||
|
Error,
|
||||||
|
Length,
|
||||||
|
Density,
|
||||||
|
Energy,
|
||||||
|
Pulses,
|
||||||
|
PulsePerLtr,
|
||||||
|
PulsePerKWh,
|
||||||
|
Conductivity,
|
||||||
|
|
||||||
|
/// Quantities without units and conversions
|
||||||
|
Number,
|
||||||
|
String,
|
||||||
|
Boolean,
|
||||||
|
DateTime,
|
||||||
|
Enumerated,
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Units
|
||||||
|
{
|
||||||
|
public static bool IsDefaultUnit(Unit unit)
|
||||||
|
{
|
||||||
|
return unit == Unit.l || unit == Unit.m3ph || unit == Unit.kg || unit == Unit.s || unit == Unit.C ||
|
||||||
|
unit == Unit.bar || unit == Unit.RPct || unit == Unit.Pct || unit == Unit.mm || unit == Unit.kgpm3 ||
|
||||||
|
unit == Unit.J || unit == Unit.uSpcm || unit == Unit.ppl || unit == Unit.ppkWh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Quantity GetQuantity(Unit units)
|
||||||
|
{
|
||||||
|
switch (units)
|
||||||
|
{
|
||||||
|
case Unit.pulse:
|
||||||
|
case Unit.degree:
|
||||||
|
return Quantity.Pulses;
|
||||||
|
|
||||||
|
case Unit.ml:
|
||||||
|
case Unit.l:
|
||||||
|
case Unit.dm3:
|
||||||
|
case Unit.USgal:
|
||||||
|
case Unit.UKgal:
|
||||||
|
case Unit.cf:
|
||||||
|
case Unit.m3:
|
||||||
|
return Quantity.Volume;
|
||||||
|
|
||||||
|
case Unit.lph:
|
||||||
|
case Unit.lpm:
|
||||||
|
case Unit.m3ph:
|
||||||
|
case Unit.lps:
|
||||||
|
case Unit.USgalps:
|
||||||
|
case Unit.m3pm:
|
||||||
|
case Unit.cfs:
|
||||||
|
return Quantity.Flow;
|
||||||
|
|
||||||
|
case Unit.g:
|
||||||
|
case Unit.lb:
|
||||||
|
case Unit.kg:
|
||||||
|
case Unit.t:
|
||||||
|
return Quantity.Mass;
|
||||||
|
|
||||||
|
case Unit.ms:
|
||||||
|
case Unit.s:
|
||||||
|
case Unit.min:
|
||||||
|
case Unit.hour:
|
||||||
|
return Quantity.Time;
|
||||||
|
|
||||||
|
case Unit.C:
|
||||||
|
case Unit.F:
|
||||||
|
case Unit.K:
|
||||||
|
return Quantity.Temperature;
|
||||||
|
|
||||||
|
case Unit.Pa:
|
||||||
|
case Unit.hPa:
|
||||||
|
case Unit.mbar:
|
||||||
|
case Unit.kPa:
|
||||||
|
case Unit.inHg:
|
||||||
|
case Unit.psi:
|
||||||
|
case Unit.bar:
|
||||||
|
case Unit.MPa:
|
||||||
|
return Quantity.Pressure;
|
||||||
|
|
||||||
|
case Unit.RPct:
|
||||||
|
return Quantity.Humidity;
|
||||||
|
|
||||||
|
case Unit.Promile:
|
||||||
|
case Unit.Pct:
|
||||||
|
return Quantity.Error;
|
||||||
|
|
||||||
|
case Unit.mm:
|
||||||
|
case Unit.cm:
|
||||||
|
case Unit.inch:
|
||||||
|
case Unit.dm:
|
||||||
|
case Unit.foot:
|
||||||
|
case Unit.yard:
|
||||||
|
case Unit.m:
|
||||||
|
return Quantity.Length;
|
||||||
|
|
||||||
|
case Unit.kgpm3:
|
||||||
|
case Unit.kgpl:
|
||||||
|
return Quantity.Density;
|
||||||
|
|
||||||
|
case Unit.J:
|
||||||
|
case Unit.kJ:
|
||||||
|
case Unit.MJ:
|
||||||
|
case Unit.Wh:
|
||||||
|
case Unit.kWh:
|
||||||
|
case Unit.MWh:
|
||||||
|
return Quantity.Energy;
|
||||||
|
|
||||||
|
case Unit.uSpcm:
|
||||||
|
case Unit.mSpm:
|
||||||
|
return Quantity.Conductivity;
|
||||||
|
|
||||||
|
case Unit.ppl:
|
||||||
|
case Unit.ppdm3:
|
||||||
|
case Unit.degpl:
|
||||||
|
case Unit.degpdm3:
|
||||||
|
case Unit.lpp:
|
||||||
|
case Unit.dm3pp:
|
||||||
|
case Unit.lpdeg:
|
||||||
|
case Unit.dm3pdeg:
|
||||||
|
return Quantity.PulsePerLtr;
|
||||||
|
|
||||||
|
case Unit.ppkWh:
|
||||||
|
case Unit.kWhpp:
|
||||||
|
return Quantity.PulsePerKWh;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Quantity.Number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ConvertTo(Unit units, double v)
|
||||||
|
{
|
||||||
|
switch (units)
|
||||||
|
{
|
||||||
|
/// Volume: internal representation in l
|
||||||
|
case Unit.ml: return 1000 * v; /// 1 l = 1000 ml
|
||||||
|
case Unit.USgal: return 0.26417205 * v; /// 1 gal(US) = 3.78541178 l
|
||||||
|
case Unit.UKgal: return 0.21996925 * v; /// 1 gal(UK) = 4.54609 l
|
||||||
|
case Unit.cf: return 0.0353146667215 * v; /// 1 cubic foot = 28.316846592 l
|
||||||
|
case Unit.m3: return 0.001 * v; /// 1 m3 = 1000 l
|
||||||
|
|
||||||
|
/// Flow: internal representation in m3/h
|
||||||
|
case Unit.lph: return 1000 * v; /// 1 l/h
|
||||||
|
case Unit.lpm: return v / 0.06; /// 1 l/m
|
||||||
|
case Unit.lps: return v / 3.6; /// 1 l/s
|
||||||
|
case Unit.USgalps: return 0.733811257326 * v; /// 1 US gallon per second
|
||||||
|
case Unit.m3pm: return v / 60; /// 1 m3/m
|
||||||
|
case Unit.cfs: return 0.009809629644858 * v; /// 1 cubic foot per second
|
||||||
|
|
||||||
|
/// Mass: internal representation in kg
|
||||||
|
case Unit.g: return 1000 * v; /// 1 g = 0.001 kg
|
||||||
|
case Unit.lb: return 2.2046226 * v; /// 1 lb = 0.45359237 kg
|
||||||
|
case Unit.t: return 0.001 * v; /// 1 t = 1000 kg
|
||||||
|
|
||||||
|
/// Time or duration: internal representation in seconds [s]
|
||||||
|
case Unit.ms: return 1000 * v;
|
||||||
|
case Unit.min: return v / 60;
|
||||||
|
case Unit.hour: return v / 3600;
|
||||||
|
|
||||||
|
/// Temperature: internal representation in °C
|
||||||
|
case Unit.F: return 1.8 * v + 32; /// degree Fahrenheit
|
||||||
|
case Unit.K: return v + 273.15; /// degree Kelvin
|
||||||
|
|
||||||
|
/// Pressure: internal representation in bar = 0.1 MPa
|
||||||
|
case Unit.Pa: return 100000 * v;
|
||||||
|
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.inHg: return 29.53 * v; /// 1 inHg =
|
||||||
|
case Unit.psi: return 14.5037738 * v; /// 1 psi =
|
||||||
|
case Unit.MPa: return 0.1 * v; /// 1 MPa = 10000 hPa
|
||||||
|
|
||||||
|
/// Relative error: internal representation in %
|
||||||
|
case Unit.Promile: return 10 * v; /// 1 promile = 0.1 %
|
||||||
|
|
||||||
|
/// Diameter, length: internal representation in mm
|
||||||
|
case Unit.cm: return 0.1 * v; /// 1 cm = 10 mm
|
||||||
|
case Unit.inch: return v / 25.4; /// 1 inch = 25.4 mm
|
||||||
|
case Unit.dm: return 0.01 * v; /// 1 dm = 100 mm
|
||||||
|
case Unit.foot: return v / 304.8; /// 1 foot = 304.8 mm
|
||||||
|
case Unit.yard: return v / 914.4; /// 1 yard = 914,4 mm
|
||||||
|
case Unit.m: return 0.001 * v; /// 1 m = 1000 mm
|
||||||
|
|
||||||
|
/// Density: internal representation in kg/m3
|
||||||
|
case Unit.kgpl: return 0.001 * v;
|
||||||
|
|
||||||
|
/// Energy, internal representation in Joul
|
||||||
|
case Unit.kJ: return 0.001 * v; /// 1 kJ = 1000 J
|
||||||
|
case Unit.MJ: return 0.000001 * v; /// 1 kJ = 1000000 J
|
||||||
|
case Unit.Wh: return v / 3600.0; /// 1 Wh = 3600 J
|
||||||
|
case Unit.kWh: return v / 3600000.0; /// 1 kWh = 3600000 J
|
||||||
|
case Unit.MWh: return v / 3600000000.0; /// 1 MWh = 3600000000 J
|
||||||
|
|
||||||
|
/// Electrical conductivity
|
||||||
|
case Unit.mSpm: return 0.1 * v;
|
||||||
|
|
||||||
|
/// Invert pulses
|
||||||
|
case Unit.kWhpp:
|
||||||
|
case Unit.lpp:
|
||||||
|
case Unit.dm3pp:
|
||||||
|
case Unit.lpdeg:
|
||||||
|
case Unit.dm3pdeg: return (v <= float.Epsilon) ? 0 : 1/v;
|
||||||
|
|
||||||
|
default: return v; /// Do not convert
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ConvertFrom(Unit units, double v)
|
||||||
|
{
|
||||||
|
switch (units)
|
||||||
|
{
|
||||||
|
/// Volume: internal representation in l
|
||||||
|
case Unit.ml: return 0.001 * v; /// 0.001 l
|
||||||
|
case Unit.USgal: return 3.78541178 * v; /// 1 gal(US) = 3.78541178 l
|
||||||
|
case Unit.UKgal: return 4.54609 * v; /// 1 gal(UK) = 4.54609 l
|
||||||
|
case Unit.cf: return 28.316846592 * v; /// 1 cubic foot = 28.316846592 l
|
||||||
|
case Unit.m3: return 1000 * v; /// 1000 l
|
||||||
|
|
||||||
|
/// Flow: internal representation in m3/h
|
||||||
|
case Unit.lph: return 0.001 * v; /// 1 l/h
|
||||||
|
case Unit.lpm: return 0.06 * v; /// 1 l/m
|
||||||
|
case Unit.lps: return 3.6 * v; /// 1 l/s
|
||||||
|
case Unit.USgalps: return 13.627482408 * v; /// 1 US gallon per second
|
||||||
|
case Unit.m3pm: return 60 * v; /// 1 m3/m
|
||||||
|
case Unit.cfs: return 101.9406477312 * v; /// 1 cubic foot per second
|
||||||
|
|
||||||
|
/// Mass: internal representation in kg
|
||||||
|
case Unit.g: return 0.001 * v; /// 1 g = 0.001 kg
|
||||||
|
case Unit.lb: return 0.45359237 * v; /// 1 lb = 0.45359237 kg
|
||||||
|
case Unit.t: return 1000 * v; /// 1 t = 1000 kg
|
||||||
|
|
||||||
|
/// Time or duration: internal representation in seconds [s]
|
||||||
|
case Unit.ms: return 0.001 * v;
|
||||||
|
case Unit.min: return 60 * v;
|
||||||
|
case Unit.hour: return 3600 * v;
|
||||||
|
|
||||||
|
/// Temperature: internal representation in °C
|
||||||
|
case Unit.F: return 5 * (v - 32) / 9; /// degree Fahrenheit
|
||||||
|
case Unit.K: return v - 273.15; /// degree Kelvin
|
||||||
|
|
||||||
|
/// 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.inHg: return 0.033864 * v; /// 1 inHg = 33.864 hPa
|
||||||
|
case Unit.psi: return 0.0689475729 * v; /// 1 psi = 0.0689475729 bar
|
||||||
|
case Unit.MPa: return 10 * v; /// 1 MPa = 10000 hPa
|
||||||
|
|
||||||
|
/// Relative error: internal representation in %
|
||||||
|
case Unit.Promile: return 0.1 * v; /// 1 promile = 0.1 %
|
||||||
|
|
||||||
|
/// Diameter, length: internal representation in mm
|
||||||
|
case Unit.cm: return 10 * v; /// 1 cm = 10 mm
|
||||||
|
case Unit.inch: return 25.4 * v; /// 1 inch = 25.4 mm
|
||||||
|
case Unit.dm: return 100 * v; /// 1 dm = 100 mm
|
||||||
|
case Unit.foot: return 304.8 * v; /// 1 foot = 304.8 mm
|
||||||
|
case Unit.yard: return 914.4 * v; /// 1 yard = 914,4 mm
|
||||||
|
case Unit.m: return 1000 * v; /// 1 m = 1000 mm
|
||||||
|
|
||||||
|
/// Density: internal representation in kg/m3
|
||||||
|
case Unit.kgpl: return 1000 * v;
|
||||||
|
|
||||||
|
/// Energy, internal representation in Joul
|
||||||
|
case Unit.kJ: return 1000 * v; /// 1 kJ = 1000 J
|
||||||
|
case Unit.MJ: return 1000000 * v; /// 1 kJ = 1000000 J
|
||||||
|
case Unit.Wh: return 3600 * v; /// 1 Wh = 3600 J
|
||||||
|
case Unit.kWh: return 3600000 * v; /// 1 kWh = 3600000 J
|
||||||
|
case Unit.MWh: return 3600000000 * v; /// 1 kWh = 3600000000 J
|
||||||
|
|
||||||
|
/// Electrical conductivity
|
||||||
|
case Unit.mSpm: return 10 * v;
|
||||||
|
|
||||||
|
/// Invert
|
||||||
|
case Unit.kWhpp:
|
||||||
|
case Unit.lpp:
|
||||||
|
case Unit.dm3pp:
|
||||||
|
case Unit.lpdeg:
|
||||||
|
case Unit.dm3pdeg: return (v <= float.Epsilon) ? 0 : 1/v;
|
||||||
|
|
||||||
|
default: return v; /// Do not convert
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -926,9 +926,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|||||||
switch (units)
|
switch (units)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case VolumeUnits.m3: return Config.Units.ConvertFrom(Config.Unit.m3, 1.0); /// liter
|
case VolumeUnits.m3: return Config.Units.ConvertFrom(Config.Unit.m3, 1.0); /// 1 liter
|
||||||
case VolumeUnits.UK_gallon: return Config.Units.ConvertFrom(Config.Unit.gal_UK, 1.0); /// liter
|
case VolumeUnits.UK_gallon: return Config.Units.ConvertFrom(Config.Unit.UKgal, 1.0); /// 1 imperial gallon
|
||||||
case VolumeUnits.US_gallon: return Config.Units.ConvertFrom(Config.Unit.gal_US, 1.0); /// liter
|
case VolumeUnits.US_gallon: return Config.Units.ConvertFrom(Config.Unit.USgal, 1.0); /// 1 US gallon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user