0

I need to run an existing model which includes multiple Fortran files and a Python file.

To run the Python file, I am trying to transform Fotran codes to Python modules using f2py. I got no issues on simpler Fortran files but in in a case where Fortran file uses another Fortran module(second.mod) it was unsuccessful. F2py is working fine on creating .so file but when importing it gives an error which is:

>>> import first
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./firstmod.so: undefined symbol: __second_MOD_secondr

To solve this I have used the command below which is also proposed in another topic(F2PY doesn't find a module):

f2py -c --fcompiler=gfortran -I"~/Documents" --fcompiler=gfortran -I"~/Documents" -lsecond -m first first.f90 -m first first.f90

But this time I get this error:

error: unknown file type '' (from '-m')

At this point I don't know what to do. Since the model is not written by me, I can't consider sharing it. I am using Ubuntu 16.04 LTS.

To clarify more, there are 4 fortran modules actually but now I got issues with connecting only two of them (first and second). In the first one these lines exist:

use second(...)
call secondr(...)

And I guess I need to find a proper way of including this second .mod file in creating my python module. Command that I provided includes duplicates but, since I am new to this I just copied it from the other topic with no questions asked.

Thank you for your help.

Kadir
  • 23
  • 1
  • 5
  • 1
    `-m first first.f90` -> `unknown file type '' (from '-m')` — Isn't there a typo? Did you just mean `-m first.f90`? – 9000 Oct 05 '17 at 16:15
  • Actually I just copied and modified the command that I get from the other topic. Therefore, I don't know if it is typo but, in both cases I got the same error. – Kadir Oct 05 '17 at 17:05
  • 1
    Also, `-m first first.f90` is duplicated. – Pierre de Buyl Oct 05 '17 at 18:22
  • Are there two Fortran modules.in `first.f90` or where is the other Fortran module? – Vladimir F Героям слава Oct 06 '17 at 06:00
  • Try replacing `-lsecond` by `secondmod.o` at the end of the *build* command of f2py. By linking, you leave the task of loading the shared object to after the build. It should be possible to fix this but I'd try the method of bundling the `.o` file instead (the `.o` file is obtained by direct compilation, i.e. `gfortran -c secondmod.f90`). – Pierre de Buyl Oct 06 '17 at 08:02
  • Thanks for advice. I tried it but it still gives the same unknown file type error. – Kadir Oct 06 '17 at 17:56

0 Answers0