Automated Computation and Consistency Checking of Physical Dimensions and Units in Scientific Programs

Fellow scientists/programmers:

The software package described on this page is an outgrowth of a paper that we published in the journal  Software - Practice and Experience . It addresses the automated computation and consistency checking of physical dimensions and units in scientific programs.  A  ready-to-use prototype Fortran-90 module that fully implements the proposed system is available below.  Legacy Fortran-77 code can be easily converted to utilize the system with only minor recoding.

The module is most likely to be useful in scientific programs, such as geophysical models and satellite retrieval algorithms, that are forced to deal with heterogeneous systems of units and/or complex formulas involving physically dimensioned constants and variables. For example, some old canned cloud physics subroutines in our own software library expect water densities in g/cm3; others expect kg/m3 . Many similar examples exist for drop sizes, fall speeds, scattering cross-sections, extinction coefficients, and the like.

We were motivated to develop this system by the realization that we were spending way too many hours debugging and painstakingly validating otherwise simple programs because of these inconsistencies in units.  Why should it be necessary for a programmer to manually figure out how to convert a viscosity from cgs to mks units, when the capability exists for a programming language to perform these conversions automatically and transparently?  Also, why shouldn't a dimensionally invalid operation, such as the addition of a length to an area, trigger the same kind of fatal run-time error as division by zero?  The PHYSUNITS module addresses both problems and allows the programmer to code up physical relationships simply and generically by eliminating the need for embedded conversion factors.   A simple example program that demonstrates the principle may be found HERE.

This  facility was designed not for computational efficiency but rather programming/debugging efficiency.   Depending on the application, the modest increase in computational overhead might be an acceptable price to pay for a reduced likelihood of  subtle errors in unit conversion or in the coding of a physical formula.  (Note that once a program has been thoroughly tested, it is possible to virtually eliminate the extra overhead without rewriting the code, simply by substituting "dummy" definitions of the new data types and operators.)

The published paper can be viewed HERE. The reference is

Petty, G.W. 2001:  Automated computation and consistency checking of physical dimensions and units in scientific programs.  Software - Practice and Experience,  31, 1067-1076

The PHYSUNITS  modules are freeware and are distributed here under the Gnu Lesser Public License .  They can be downloaded via the following link:

 physunits1.10.tar.gz (gzipped tar file containing paper preprint,  F90 module source and demo programs)

I welcome your questions, comments and any suggested improvements  -- e-mail me at gpetty@aos.wisc.edu.    Upgraded versions and bug fixes (if required) will be posted to this page as they become available.   Your assistance in drawing attention to the possibility of dimension-awareness in scientific programs is also welcome -- please consider forwarding this URL to others  who might be intereested.

 ________________________________________
Grant W. Petty
Professor of Atmospheric Science
Atmospheric and Oceanic Sciences
1225 W. Dayton Street
University of Wisconsin-Madison
Madison, WI  53706

gpetty@aos.wisc.edu
Tel: (608) 263-3265
Fax: (608) 262-0166