Unit Conversion


Unit conversion is both implementation and design related. In this paper, we present some of the ideas on how to implement the unit conversion in MOSES for discussion. 

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.

figure 1: Unit Structure

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.


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.


This page last updated on July 09, 1997.