@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,
right?
-
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
confirmation function?
Semantic/syntactic questions:
Ad 5.5
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)
enddo
end function
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) ) )
Ad 5.5
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
Ad 5.5
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?)
Ad 5.10.2/5.10.3
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?
Ad 5.11.3
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
instance:
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
conversion unit?
Is an expression like “x = one_cm + one_inch” allowed?