comp.lang.ada
 help / color / mirror / Atom feed
From: 18k11tm001@sneakemail.com (Russ)
Subject: Re: Expressing physical units (Was: Reprise: 'in out' parameters for functions)
Date: 14 Apr 2004 00:10:35 -0700
Date: 2004-04-14T00:10:35-07:00	[thread overview]
Message-ID: <bebbba07.0404132310.3afa1147@posting.google.com> (raw)
In-Reply-To: c5gh04$1ba02$1@ID-77047.news.uni-berlin.de

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message news:<c5gh04$1ba02$1@ID-77047.news.uni-berlin.de>...
> Russ wrote:
> 
> > "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> > news:<c5dr33$gkic$3@ID-77047.news.uni-berlin.de>...
> >> Russ wrote:
> >> 
> >> > By the way, I work in the field of air traffic management (ATM), and
> >> > I'd really like to see a practical way to guarantee units consistency.
> >> > The general mks system is inappropriate for ATM. The traditional units
> >> > for ATM are nautical miles (nmi) for horizontal length, and feet (ft)
> >> > for altitude. That won't change in our lifetimes -- and probably
> >> > never. As for time, it can be in seconds, minutes, or hours.
> >> > Horizontal speed in usually given in terms of knots (kn), which is
> >> > nmi/hr, but altitude rate is usually given in terms of ft/min. Heading
> >> > is normally given in degrees.
> >> > 
> >> > In my experience, the most common units problem is confusion between
> >> > degrees and radians. Radians are preferable for use inside programs,
> >> > but degrees are preferable for I/O. This problem really needs to be
> >> > licked once and for all.

> Now to templates and C++. You are wrong thinking that units can be properly
> done in C++. What indeed can be, is a tiny part of what is really
> necessary. Consider the following issues:
> 
> 1. Shifted units, like Celsius degree.
> 2. Dealing with units unknown at compile time. How would you communicate
> with a data base, or develop a gauge widget, or write a unit calculator?
> How to write a unit I/O package?
> 3. Dealing with multiple unit systems. The C++ solution actually works in
> SI. It means that a measure in [ft] has to be converted to [m]. It is OK as
> long as:
> 3.a. There is no range problems. In an emedded system one could use a fixed
> arithmetics with would overflow if the distance is measured in [m], but
> work fine for [km].
> 3.b. One can ignore inevitable precission loss caused by unit conversions.
> This might be critical for some applications.
> 5. How to handle logarithmic units and other non-linear scales?
> 6. Container problem. Surely a vector, matrix etc of dimensioned values
> should have a dimension. Possibly it could be handled by templates, but I
> am afraid it would not be so easy.
> 7. Any generic (template) solution would make everything based upon it also
> generic.

You're talking about the Grand Unified system of units. That's fine,
but I'm just talking about something that can make air traffic
management (ATM) software more robust. As I wrote before, the most
important units in ATM are few in number.

Here is an outline of what I was working on in my free time before my
hard drive died. You define a dozen or so Ada types for commonly used
units, such as

nmi (nautical miles)
feet
FL (flight level, or 100 ft)
kft (1000 ft)
deg
rad (radian)
knots
fpm (feet per minute, for altitude rate)
klb (1000 pounds)
sec (second)
minute
hour

and perhaps a few others.

You then define operators for all the likely operations among these
types. Each type can be added to or subtracted from its own type, for
example. When you divide a type by the same type, you get a
dimensionless number. Multiplication of like types is prohibited
unless it really makes sense. If you divide nmi by hour, you get
knots. If you divide nmi by sec, the compiler coughs and tells you
that you can't do that -- so you go and convert the seconds to hours
(using a predefined conversion function). You get the idea.

As new units or combinations come up, you add them into the
repertoire. Perhaps the total number of units and reasonable
combinations would be managable.

The idea here is not to have all units converted automagically but
rather simply to have the compiler catch any potentially inconsistent
use of units. The days of using degrees for radians, or dividing nmi
by sec and adding it to knots, would be mercifully over. And no
generics are needed.

Is this a reasonable approach?



  parent reply	other threads:[~2004-04-14  7:10 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <u4qrv5hwr.fsf@acm.org>
2004-04-08 17:19 ` Reprise: 'in out' parameters for functions Alexander E. Kopilovich
     [not found] ` <bRecOT0TxF@VB1162.spb.edu>
2004-04-08 23:46   ` Stephen Leake
2004-04-09  9:23     ` Florian Weimer
2004-04-09 10:04       ` Dmitry A. Kazakov
2004-04-09 11:23         ` Martin Krischik
2004-04-09 12:44           ` Dmitry A. Kazakov
2004-04-09 22:48             ` Randy Brukardt
2004-04-14 14:40               ` Robert I. Eachus
2004-04-14 21:20                 ` Randy Brukardt
2004-04-09 22:47         ` Florian Weimer
2004-04-10 10:49           ` Dmitry A. Kazakov
2004-04-10 11:11             ` Florian Weimer
2004-04-10 13:26               ` Dmitry A. Kazakov
2004-04-10 20:50                 ` Georg Bauhaus
2004-04-11 10:31                   ` Dmitry A. Kazakov
2004-04-09 11:27       ` Stephen Leake
2004-04-09 22:46       ` Randy Brukardt
2004-04-09 13:12     ` Wojtek Narczynski
2004-04-09 15:48       ` Expressing physical units (Was: Reprise: 'in out' parameters for functions) Jacob Sparre Andersen
2004-04-10 13:07         ` Wojtek Narczynski
2004-04-10 13:52           ` Jacob Sparre Andersen
2004-04-11  2:45             ` Hyman Rosen
2004-04-11 10:14               ` Expressing physical units Jacob Sparre Andersen
2004-04-11 16:05                 ` Hyman Rosen
2004-04-12  6:58               ` Expressing physical units (Was: Reprise: 'in out' parameters for functions) Russ
2004-04-12 10:29                 ` Dmitry A. Kazakov
2004-04-13  6:52                   ` Russ
2004-04-13 10:55                     ` Dmitry A. Kazakov
2004-04-14  4:50                       ` Hyman Rosen
2004-04-14  8:49                         ` Dmitry A. Kazakov
2004-04-14 16:49                           ` Hyman Rosen
2004-04-15 10:37                             ` Dmitry A. Kazakov
2004-04-14  7:10                       ` Russ [this message]
2004-04-14  8:53                         ` tmoran
2004-04-14  9:01                           ` Vinzent 'Gadget' Hoefler
2004-04-14  9:21                         ` Dmitry A. Kazakov
2004-04-13  9:53             ` Wojtek Narczynski
2004-04-15 21:27               ` Expressing physical units Jacob Sparre Andersen
2004-04-16 11:40                 ` Dmitry A. Kazakov
2004-04-09 16:17       ` Reprise: 'in out' parameters for functions Georg Bauhaus
2004-04-10  2:28         ` Wojtek Narczynski
2004-04-10  9:46           ` Georg Bauhaus
2004-04-10 10:49           ` Dmitry A. Kazakov
2004-04-10 15:35             ` Wojtek Narczynski
2004-04-10 21:01               ` Georg Bauhaus
2004-04-10 21:16               ` Georg Bauhaus
2004-04-11 13:20                 ` exception parameters Stephen Leake
2004-04-12 10:29                   ` Dmitry A. Kazakov
2004-04-13  0:58                     ` Stephen Leake
2004-04-13  1:30                       ` Randy Brukardt
2004-04-13  8:04                   ` Jean-Pierre Rosen
2004-04-11 10:31               ` Reprise: 'in out' parameters for functions Dmitry A. Kazakov
2004-04-12 22:02                 ` Randy Brukardt
2004-04-13 10:56                   ` Dmitry A. Kazakov
2004-04-14 21:12                     ` Randy Brukardt
2004-04-15 10:37                       ` Dmitry A. Kazakov
2004-04-13  9:30                 ` Wojtek Narczynski
2004-04-13 12:00                   ` Dmitry A. Kazakov
2004-04-13 22:41                     ` Wojtek Narczynski
2004-04-14  8:49                       ` Dmitry A. Kazakov
2004-04-14 15:03                         ` Wojtek Narczynski
2004-04-15 10:37                           ` Dmitry A. Kazakov
2004-04-16  0:29                             ` Wojtek Narczynski
2004-04-16 11:36                               ` Dmitry A. Kazakov
2004-04-16 19:25                                 ` Wojtek Narczynski
2004-04-14 15:57             ` Robert I. Eachus
2004-04-15  8:04               ` Dmitry A. Kazakov
2004-04-10 12:32           ` Wojtek Narczynski
2004-04-14 15:46           ` Robert I. Eachus
2004-04-16  1:52             ` Wojtek Narczynski
2004-04-16  5:40               ` Robert I. Eachus
2004-04-16 11:38                 ` Wojtek Narczynski
2004-04-16 16:30                   ` Robert I. Eachus
2004-04-16 18:38                   ` Randy Brukardt
2004-04-16 22:15                     ` Wojtek Narczynski
2004-04-17  1:20                       ` Robert I. Eachus
2004-04-17 11:42                         ` Wojtek Narczynski
2004-04-17 14:14                           ` Robert I. Eachus
2004-04-16 19:28                   ` Wojtek Narczynski
2004-04-09 17:09       ` Pascal Obry
2004-04-10  2:37         ` Wojtek Narczynski
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox