by theamk · 3y ago · 0 comments
That particular tool, "GNU Units"? Nope. It is pretty good command-line calculator (especially if you give inputs on command line so that history is preserved), but it is not really scriptable, and you'd _definitely_ want to avoid all manual calculations in any sort of important process.
as an example of scriptability, i just added this function to ~/.units
# note that theta is the angle from the central axis of the cone to its side
conesolidangle(theta) units=[radian;sr] range=[0,) 2 pi (1 - cos(theta)) sr ; \
acos(1 - conesolidangle/sr/2/pi)
(sadly it is not smart enough to figure out the inverse formula itself, even in a simple acyclic case like this)with this i can calculate, for example, the convergence angle required for concentrated sunlight to melt iron (asymptotically, assuming no heat losses to conduction or convection)
You have: 2 ~conesolidangle(conesolidangle(asin(sunradius/sundist)) tempC(1538)**4 stefanboltzmann / (1000W/m2))
You want: dms
13 deg + 10 arcmin + 34.428619 arcsec
it would be highly desirable to have conditionals and loops, of course, or even numpy-style vectors with broadcasting, as well as either functions of more than one argument or higher-order functions, and it doesn't have any of thoseThere is some solution for most programming languages:
https://gmpreussner.com/research/dimensional-analysis-in-pro...
How well it works mostly depends on features of a programming language or it's compiler.
That said it's rare for a programming language to have a type system with extra features and unit checking support in it's standard library like F# or GNAT does:
https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
https://gcc.gnu.org/onlinedocs/gnat_ugn/Performing-Dimension...