Last active
January 12, 2023 03:12
-
-
Save Sleepingwell/df93c55f1598ef0ddcf6f2c61056c5c1 to your computer and use it in GitHub Desktop.
A minimal example of calling a python function via a callback passed to a fortran subroutine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: venv | |
VENV_PATH=venv | |
TIMESTAMP_FILE=$(VENV_PATH)/.f2pytest-creation-timestamp | |
test: venv test.f90 | |
. $(VENV_PATH)/bin/activate && \ | |
python -m numpy.f2py -c test.f90 -m test | |
venv: $(TIMESTAMP_FILE) | |
$(TIMESTAMP_FILE): | |
virtualenv -p python3 $(VENV_PATH) | |
. $(VENV_PATH)/bin/activate && pip install numpy scipy | |
touch $(TIMESTAMP_FILE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test | |
def func(x): | |
print('x is {}'.format(x)) | |
return x * 2 | |
test.test(func) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subroutine test(py_func) | |
integer x,y,py_func | |
external py_func | |
x = 42 | |
y = py_func(x) | |
end subroutine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment