When dealing with scientific data it is essential to know the units of measurement in order to understand and present the information correctly.Likewise, in order to do computations with scientific data it is essential that software is able to convert data into a common unit framework.
The Petroware UoM library is a convenient, extensible front-end to the Energistics Unit of Measure database. It contains more than 250 different quantities and more than 2500 unit definitions. The API is simple, well documented and easy to use, and the library is trivial to embed in any scientific software system.
UoM is available for Java (Uom.jar
) and .Net (Uom.dll
). The library is lightweight (< 0.1MB) and self-contained; It embeds the complete Energistics unit database and has no external dependencies.
The easiest way to get started with UoM is to explore the predefined Energistics quantities and units:
Unit conversion
Basic unit conversion is done through UnitManager
using instances of Unit
or the unit symbols directly:
Making a user interface units aware includes associating GUI components with quantities and then provide unit conversions, either per element or as overall preference settings.
It is essential that the application knows the initial unit of measure of the values involved. A common advice to reduce complexity and risk of errors is to keep the entire data model in base units (typically SI or similar) and convert in GUI only on users request. The associated units will then be implied, effectively making the entire business logic unitless. Conversions to and from base units can be performed directly on the Unit
instances:
It may make sense to provide unit conversion even if the quantity of a measure is unknown. In these cases it is possible to obtain the quantity, but it might be more convenient to get all convertible units directly:
Unit aliases
There is no universal accepted standard or convention for unit symbols, and to make the module more robust when dealing with units from various sources it is possible to add unit aliases. UoM uses the unit symbol defined by Energistics, but have added many aliases for common notations. In addition, client applications can supply their own:
The typical approach would be to read these from a properties file during startup.
Display symbols
Unit symbols should be regarded as IDs, and clients should never expose these in a user interface. A GUI friendly display symbol may be obtained through the UnitManager.getDisplaySymbol()
method.
The table below indicates the connection between unit name, unit symbol and display symbol:
Unit name | Unit symbol | Display symbol |
---|---|---|
microseconds per foot | us/ft | µs/ft |
ohm meter | ohmm | Ω·m |
cubic centimeters | cm3 | cm3 |
degrees Celcius | degC | °C |
meter/second squared | m/s2 | m/s2 |
etc. |
As for unit aliases, it is possible for clients to supply their own specific display symbols through the UnitManager.setDisplaySymbol()
method.
Extensibility
If the predefined set of quantities and units is not sufficient, a client may easily supply their own:
It is also possible to add units to existing quantities: