Unit Conversion
Overview
The unit conversion is a complicated process while a large number of unit types are involved. In our implementation, we try to organize the unit types in a special data structure which can be easily stored in a relational database. Meanwhile, we try to keep the maximum flexibility.
The paper is presented in three sections:
1. Data Structure: how to organize the unit types, how to code them, etc.
2. How to convert: how to make the actual conversion with the above data structure
3. Where to store unit information: where can we get the unit information, priority, etc.
Data Structure
Data structure is the internal organization of data. The user may not even know their existance. A system designer or programmer should have a very clear idea about it and make sure it supports the sufficient flexibility and quick response time.

RUSLE2 suggests using IDs that map to a name string, unit type, conversion factor, etc. We try to extend the idea which will make it easy to convert units. The basic idea is to hide some information in the IDs which represent the units.
For each unit, we use a 6-digit number to represent it.
The meaning of each digit is as follows:
|
|
Digit # |
|
|
| 1 | 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

To store all these information in a relational database, we use several tables.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For unit "ft" (101100), it belong to the english unit system which is not the standard unit system (code #1: 1). It is a preferred unit (code #3: 1 and code #4: 00). The conversion factor is related to the preferred unit under the same unit type of the standard unit system, "m". That is
1 ft = 0.3048 m.
Note: If we know ft-m convresion factor, we also konw m-ft conversion factor. Also note the table above should have two index, ID and unit, so that we can search the record using either of them.
How to Convert?
With the data structure above, we can easily do conversions between any two convertable units. Convertable means they share the same unit type, i.e. same code #2 value. There are several possibilities for the unit conversion.

As indicated in figure 3, conversion within one unit system is easy. Just use the preferred unit as the bridge.

In figure 4, we show two cases of unit conversion between two unit systems. The first one is simple. It converts from one preferred unit type to another preferred unit type. Since in the unit table, we already keep the conversion factor from ft to m. So we can convert either direction.
The second case is the most complicated one. In figure 4, red line 2 represents the unit conversion from "mm" to "in". Since we can get mm-m, m-ft and ft-in conversion factors in the table, the convertion factor for mm-in can be calculated by multiplying these three factors.
mm -> m -> ft -> in
001001 001100 101100 101001
Before we make the conversion, we know the ID for both mm and in. We can get the ID of the intermediate preferred units by changing related ID digits. For example, we can get the parent of "mm" by changing the last three digits to 100. With all these IDs as the keys, we can get the conversion factor very quickly.
In the above explanation, we may do any conversion between two convertable units. But it may be slow especially for two non-preferred units across two different unit systems. To make this conversion faster, we can keep a cache table in memory with the two ID combined as the key.
Where Do We Store the Unit Information?
WEPS suggests three-level of unit information storage, i.e. DB-level, model-level (global) and view-level (local). At the DB-level, we store the unit information along with the database and/or files. At the model-level, unit information is attached with data elements. At the view-level, unit information is stored with each view. The priority order is view-level first, model-level next and DB-level last.
DB-Level
At DB-level, we have two choices for storing the unit information.
1. Store unit information along with all data elements. In this case, we need to setup a unit field in the database. Though it is space-consuming, it provides the maximum flexibility.
2. Use one single unit system and its preferred units. In this case, we just save the Code ID for the unit system. All the data in the database are stored with one unit system such as metric.
Model-Level (Global)
While the system is running, we keep model data in memory. The model data should have unit informaiton with it. That means when we read data from database, we may need to make a unit conversion to fit the user selected unit system. Unit conversion is also happened when the user selects a new unit system.
View-Level (Local)
Each view can have its own unit specification. This provides the maximum flexibility. User can set unit for any element in a view if the view allows. For example, in a table view, user may change a unit for one column and/or even one cell. The view will be responsible to keep track of what units are used.
Conclusion
The design of the system is to get the maximum flexibility. For example, we can create user-defined units such as PRECIP, FIELD_AREA, LENGTH-SHORT at the bottom of the tree. The system will treat them the same as other standard units. To make the conversion quicker, we use a cache table.
The system is still in the design stage. Please send your comments and suggestions to WEPS group.