I don't know a lot about f2py
but it looks like there is a command line version and a module version.
To use the commmand line option, I see two options:
- Modify the fortran to find the path
- Wrap the command line with a wrapper
For a wrapper, you could use a bash script that does something like this:
#!/bin/sh
dir=$(dirname $0) # gets relative path
dir=$(readlink -f $dir) # to get absolute
cd $dir
# Now call p2py
If you use the module version, you can use os.chdir()
to change the directory before running your pythonized fortran source:
fortran_file = "foo.f"
dir = os.path.dirname(os.path.abspath(fortran_file))
os.chdir(dir)
# Now run p2py against fortran_file
Only other option I can think of is to see if you can inject the path into the fortran code. Maybe you can read the code, change the path in the source in memory, and then use f2py.compile()
against that dynamically modified code.