Next: , Previous: Debug, Up: Top


10 Handling units

It's often handy for users to input numbers with unit specifications, so that they can work in units appropriate to them, rather than to the program. This subpackage helps parse such specifications, as well as convert between units.

Each type of unit is assigned an id, which is a non-negative integer. The id serves as an index into an array of UnitConvert structures, which contain multiplicative conversion factors from the given unit to a fiducial one. For example, length may be specified in kilometers, meters, or millimeters. If millimeters is the fiducial unit, than the conversion factors would be 1000, 1, .001, respectively. UnitConvert structures are bundled into a UnitConvertList for ease of access.

Names are mapped to units via a TokList structure, with the units' ids specified in the TokListToken id field. There may be more than one name for a given unit (e.g. ‘kilometer’, ‘km’).

These two data structures are bundled together via the UnitsList structure.

This subpackage provides a set of linear, angular, temporal and energy units via UnitsLinear_def, UnitsAngular_def, UnitsTime_def, and UnitsEnergy_def. Their definitions are available in suplib/units_linear.h, suplib/units_angular.h, suplib/units_time.h, and suplib/units_energy.h, respectively