A Fortran 90 module for the Automated Computation and Consistency Checking of Physical Dimensions and Units in Scientific Programs

The software package described on this page is an outgrowth of a paper that we published in the journal  Software – Practice and Experience .  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 viewed 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.)


Petty, G.W. 2001:  Automated computation and consistency checking of physical dimensions and units in scientific programs.  Software – Practice and Experience, 31, 1067-1076.     View the paper abstract in the Wiley Online Library


The PHYSUNITS  modules are freeware and are distributed here.