Basic demo¶
Here we show a very basic demo of how to use the package. The actual behaviour isn't so interesting, but it demonstrates that we can wrap code that is ultimately written in Fortran.
Imports¶
import pint
from example_fgen_basic.error_v import ErrorV
from example_fgen_basic.error_v.creation import create_error, create_errors
from example_fgen_basic.error_v.passing import pass_error, pass_errors
from example_fgen_basic.get_wavelength import get_wavelength, get_wavelength_plain
Calculation with basic types¶
Here we show how we can use a basic wrapped function. This functionality isn't actually specific to our wrappers (you can do the same with f2py), but it's a useful starting demonstration.
# `_plain` because this works on plain floats,
# not quantities with units (see below for this demonstration)
get_wavelength_plain(400.0e12)
7.4948e-07
With these python wrappers, we can also do nice things like support interfaces that use units (this would be much more work to implement directly in Fortran).
ur = pint.get_application_registry()
get_wavelength(ur.Quantity(400.0, "THz")).to("nm")
Receiving and passing derived types¶
TODO: more docs and cross-references on how this actually works
We can receive a Python-equivalent of a Fortran derived type.
create_error(3)
ErrorV(code=0, message='')
Or multiple derived types.
create_errors([1, 2, 1, 5])
(ErrorV(code=0, message=''), ErrorV(code=1, message='Even number supplied'), ErrorV(code=0, message=''), ErrorV(code=0, message=''))
We can also pass Python-equivalent of Fortran derived types back into Fortran.
pass_error(ErrorV(code=0))
False
pass_errors([ErrorV(code=0), ErrorV(code=3), ErrorV(code=5), ErrorV(code=-2)])
array([False, True, True, True])