Hi,

die...@duenenhof-wilhelm.de (H. Dieter Wilhelm) writes:

>   But what is missing is to assign variables within a source block
>   
>     #+BEGIN_SRC calc :var L1 = "5 mm" 
>     L2 := cvun( L1, m)
>     #+END_SRC    
>   
>   Unfortunately this is not working.  Do you have an idea how to
>   implement this?
>
> - Are you using (better) alternatives?

I like Python and in Python I like Pint for units.

  http://pint.readthedocs.org

Below is an example org document that should "run" and shows a couple
ways to use snippets of Pint code to do unit conversion.  Not shown but
Pint Quantity objects support arithmetic so are useful for carrying
units through some calculation.

For assigning to variables - presumably for use in later blocks - maybe
you can investigate using the :session header argument to source blocks.


Have fun,
-Brett.

One way to install Pint is:

#+BEGIN_SRC sh :results silent
  pip install --user pint
#+END_SRC

Here is an example:

#+name: uconv
#+header: :var val="10m" :var unit="inch" 
#+BEGIN_SRC python
  import pint
  units = pint.UnitRegistry()
  return units.Quantity(val).to(unit)
#+END_SRC

#+RESULTS: uconv
: 393.700787402 inch

Now call =uconv= do to some other conversion:

#+call: uconv("2.54cm","inch")

#+RESULTS:
: 1.0 inch

Attachment: pgpGnSjfoKUX4.pgp
Description: PGP signature

Reply via email to