J3/04-245 Date: 13 Feb 2004 To: J3 From: Dan Nagle Subject: New Kinds of Kinds There have been several requests for values specified to have units. A superset of this functionality might be had with less effort via a different approach. Specifically, this might be done by extending the derived type parameter system to allow REAL and CHARACTER parameters in a variable definition. The current integer length parameters may be employed to specify the dimensions of a quantity. For example, specifying length parameters m, l, t, q, a might be employed to specify the integral powers (positive or negative) of mass, length, time, charge and angle. All that must be added to specify the units, rather than merely the dimension, is the scale. Being able to name and label quantities is also useful. A real type parameter may specify the scale of the units used to measure a quantity. A character parameter may specify the name or (default) format of a variable. I suppose there might be a reason to allow logical kind parameters, but since I can't think of a good one, I won't propose it here. Number: Title: New Derived Type Parameters Submitted By: J3 Status: For Consideration References: Basic Functionality: Allow real and character derived type parameters Rationale: Using integer DT parameters, a dimensionally correct derived type may be constructed, to wit: integer, len :: m, l, t, q, a where these type parameters represent the power of mass, length, time, charge and angle of the variables of the PDT. To go from here to a full unit variable, one must add the real scale factor. To complete the unit-ized PDT, one might want to specify the name and/or preferred format to be used. Estimated Impact: The compiler must recognize new derived type parameters, but would not be required to process them other than to supply them when the code specifies. Detailed Specification: Allow real and character DT parameters, as in the following example: type :: velcocity_t( s, n, f) real, scale :: s character( len= chlen), string :: n, f real :: vx, vy, vz end type velocity_t The additional keywords SCALE and STRING are present to allow future expansion, if desired. type( velocity_t( 1.0, 'meters per second', & '3en16.8, " m/s"') :: vm Here, variable v is a velocity with units of m/s. It has a name of "meters per second", and a format of 3en16.8 m/s. type( velocity_t( 0.3, 'feet per second', & '3en16.8, " ft/s"') :: vf If an attempt is made to assign vm = vf the assignment routine could be coded to compare vm% s == vf% s and report the error when the match fails, or the assignment procedure might apply the ratio of the scales when performing the assignment. To print this variable, one might use: write( *, '(' // vm% f // ')' ) vm History: