2using System.Collections.Generic;
27 PUI_RATIO_SI_UNITS = 1,
34 PUI_LOG10_SI_UNITS = 2,
41 PUI_LOG10_RATIO_SI_UNITS = 3,
125 LinkedList<KeyValuePair<AtomicUnit, int>> Parts =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
128 if (unitPerBase64.TryGetValue(Convert.ToBase64String(
this.Binary), out
string s))
131 if (this.AddStep(Parts,
"rad", this.Radians, ref
Prefix, 0) &&
132 this.AddStep(Parts,
"sr", this.Steradians, ref
Prefix, 0) &&
133 this.AddStep(Parts,
"m", this.Meters, ref
Prefix, 0) &&
134 this.AddStep(Parts,
"g", this.Kilograms, ref
Prefix, 3) &&
135 this.AddStep(Parts,
"s", this.Seconds, ref
Prefix, 0) &&
136 this.AddStep(Parts,
"A", this.Amperes, ref
Prefix, 0) &&
137 this.AddStep(Parts,
"K", this.Kelvins, ref
Prefix, 0) &&
138 this.AddStep(Parts,
"mol", this.Moles, ref
Prefix, 0) &&
139 this.AddStep(Parts,
"cd", this.Candelas, ref
Prefix, 0))
147 private const byte _ = 128;
148 private const byte p1 = 130;
149 private const byte p2 = 132;
150 private const byte p3 = 134;
151 private const byte p4 = 136;
152 private const byte m1 = 126;
153 private const byte m2 = 124;
154 private const byte m3 = 122;
155 private static readonly KeyValuePair<string, byte[]>[] specialUnits =
new KeyValuePair<string, byte[]>[]
157 new KeyValuePair<string, byte[]>(
"Pa",
new byte[] { 0, _, _, m1, p1, m2, _, _, _, _ }),
158 new KeyValuePair<
string,
byte[]>(
"Ω",
new byte[] { 0, _, _, p2, p1, m3, m2, _, _, _ }),
159 new KeyValuePair<
string,
byte[]>(
"C",
new byte[] { 0, _, _, _, _, p1, p1, _, _, _ }),
160 new KeyValuePair<
string,
byte[]>(
"J",
new byte[] { 0, _, _, p2, p1, m2, _, _, _, _ }),
161 new KeyValuePair<
string,
byte[]>(
"Hz",
new byte[] { 0, _, _, _, _, m1, _, _, _, _ }),
162 new KeyValuePair<
string,
byte[]>(
"N",
new byte[] { 0, _, _, p1, p1, m2, _, _, _, _ }),
163 new KeyValuePair<
string,
byte[]>(
"W",
new byte[] { 0, _, _, p2, p1, m3, _, _, _, _ }),
164 new KeyValuePair<
string,
byte[]>(
"V",
new byte[] { 0, _, _, p2, p1, m3, m1, _, _, _ }),
165 new KeyValuePair<
string,
byte[]>(
"F",
new byte[] { 0, _, _, m2, m1, p4, p2, _, _, _ }),
166 new KeyValuePair<
string,
byte[]>(
"S",
new byte[] { 0, _, _, m2, m1, p3, p2, _, _, _ }),
167 new KeyValuePair<
string,
byte[]>(
"Wb",
new byte[] { 0, _, _, p2, p1, m2, m1, _, _, _ }),
168 new KeyValuePair<
string,
byte[]>(
"T",
new byte[] { 0, _, _, _, p1, m2, m1, _, _, _ }),
169 new KeyValuePair<
string,
byte[]>(
"H",
new byte[] { 0, _, _, p2, p1, m2, m2, _, _, _ }),
170 new KeyValuePair<
string,
byte[]>(
"lm",
new byte[] { 0, _, p1, _, _, _, _, _, _, p1 }),
171 new KeyValuePair<
string,
byte[]>(
"lx",
new byte[] { 0, _, p1, m2, _, _, _, _, _, p1 })
173 private static readonly Dictionary<string, string> unitPerBase64 = OrderUnits();
175 private static Dictionary<string, string> OrderUnits()
177 Dictionary<string, string> Result =
new Dictionary<string, string>();
179 foreach (KeyValuePair<
string,
byte[]> P
in specialUnits)
180 Result[Convert.ToBase64String(P.Value)] = P.Key;
185 private bool AddStep(LinkedList<KeyValuePair<AtomicUnit, int>> Parts,
string Unit,
byte Exponent,
197 Parts.AddLast(
new KeyValuePair<AtomicUnit, int>(
new AtomicUnit(
Unit), i));
198 Prefix += ExponentModifier;
232 foreach (KeyValuePair<AtomicUnit, int> P
in Unit.
Factors)
234 int Exponent = 128 + (P.Value << 1);
235 if (Exponent < 0 || Exponent > 255)
238 byte Exp = (byte)Exponent;
247 Units.Steradians = Exp;
255 Units.Kilograms = Exp;
256 Value *= Math.Pow(1000, -P.Value);
257 NrDecimals += P.Value;
277 Units.Candelas = Exp;
289 Value *= Math.Pow(10, i);
Represents an atomic unit.
bool HasFactors
If the unit has any factors.
Unit ToReferenceUnits(ref double Magnitude)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
ICollection< KeyValuePair< AtomicUnit, int > > Factors
Sequence of atomic unit factors, and their corresponding exponents.
Prefix Prefix
Associated prefix.
Prefix
SI prefixes. http://physics.nist.gov/cuu/Units/prefixes.html
Ieee1451_0PhysicalUnitsInterpretation
How to interpret physical units.
byte Kelvins
(2 * <exponent of kelvins>) + 128
Unit TryCreateUnit()
Tries to create a unit from the description available in the object.
byte Kilograms
(2 * <exponent of kilograms>) + 128
byte[] Binary
Binary byte array representation of the physical unit.
byte Candelas
(2 * <exponent of candelas>) + 128
byte Radians
(2 * <exponent of radians>) + 128
Ieee1451_0PhysicalUnitsInterpretation Interpretation
Physical Units interpretation
byte Meters
(2 * <exponent of meters>) + 128
byte Amperes
(2 * <exponent of amperes>) + 128
static bool TryCreate(Unit Unit, ref double Value, ref double NrDecimals, out PhysicalUnits Units)
Tries to create an IEEE 1451 units object from a script unit.
byte Steradians
(2 * <exponent of steradians>) + 128
byte Seconds
(2 * <exponent of seconds>) + 128
byte Moles
(2 * <exponent of moles>) + 128