UoM - Units of measurement library
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 definitions of more than 2500 units from more than 250 different quantities. 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.
UoM for Java: Javadoc
UoM for .Net: Doxygen
The easiest way to get started with UoM is to explore the predefined
Energistics quantities and units:
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
and convert in GUI 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 done 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:
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 symbols defined
by Energistics, but have added many aliases for common notations.
In addition, client applications can easily supply their own:
The typical approach would be to read these from a properties file during startup.
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:
As for unit aliases, it is possible for clients to supply their own specific display symbols through the UnitManager.setDisplaySymbol() method.
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: