@vsnyder (cc @everythingfunctional), I have written down my questions. I think I understand the specifications in document N2113, so I hope these questions to be to the point ;).
Questions and remarks regarding document N2113:
(Quite possibly I have overlooked one or more or even all things in the
text and are all the answers to my questions already there)
Just a few nitpicks:
The units kelvin and ampère should be written with lower-case.
(page V for instance)
Unit names are part of the same namespace as variables and functions,
Can the names of units be imported via the “import” statement?
Use of the unit coercion function is clear, but how does one use the
Suppose I have a function like this:
function fpoly( a, x )
real, dimension(:), intent(in) :: a
real, intent(in) :: x
real :: fpoly
integer :: i
fpoly = a(1)
do i = 2,size(a)
fpoly = fpoly + a(i) * x**(i-1)
How would I make sure that the units of the arguments are used
correctly? This solution seems a poor workaround:
! f_unit is the unit for the function result
real, unit(f_unit) :: f
f = f_unit( fpoly( unitless(a), unitless(x) ) )
Just a thought:
real, unit(length) :: x
real, unit_of(x) :: y
in a similar vein as the length of character strings or kinds etc.
Another example (finite differences):
subroutine diffxy( p, dx, dy, dpdx, dpdy )
real, dimension(:,:), unit(p_unit) :: p
unit :: pdiff_unit = p_unit / length
real, unit(length) :: dx
real, unit_of(dy) :: dy ! Both dx and dy should be expressed
! in the same unit, meter or foot, so
! not just a "length unit"
real, unit(pdiff_unit) :: dpdx, dpdy
end subroutine diffxy
I suspect that pointers to targets that have a unit should have the very
same unit (or equivalent). What about unlmited polymorphic variables?
Should the “select type” construct be extended to include units? (Useful
in combination with abstract units?)
Ignoring the case (lower/upper case) with input seems problematic to me:
consider milligrams (mm) and megagrams (Mg) or specific heat capacity -
J/kg/K could also be J/K/g or J/Kg (perhaps contrived, but still)
How does one define the strings to represent the units?
Arrays: What would happen if the first element has one unit (cm, say)
and the last has another unit (inch, say)? Automatic onversion? What
would be the end result?
Are conversions between units automatic? The notes seem to imply that
they are not automatic, but that it is a distinct possibility. However,
is it possible to unambiguously determine the resulting unit? For
real, unit(cm) :: one_cm = cm(1.0)
real, unit(cm) :: one_inch = inch(1.0)
write(*,*) add( one_cm, one_inch )
What would be the result (expressed in what unit)? The one that is not a
Is an expression like “x = one_cm + one_inch” allowed?