need to get f2py working, but don't know any fortran

567 views Asked by At

I want to use function OPAC from this source code: http://opalopacity.llnl.gov/codes/xztrin21.f

i don't uderstand the code very well, I just want to use it as Python module. I run the following:

f2py -c xztrin21.f -m opal_opacity

but I always get this error:

/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c: In function ‘f2py_init_cst’:
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c:1828:35: note: each undeclared identifier is reported only once for each function it appears in
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/tmpWe2VM7/src.linux-x86_64-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c /tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.c -o /tmp/tmpWe2VM7/tmp/tmpWe2VM7/src.linux-x86_64-2.7/opal_opacitymodule.o" failed with exit status 1

I don't think there's really anything wrong with the code. I believe others got it working alright, so I guess I must have a wrong Fortran complier or something. I'm not sure what to do about it though.

Any help apprecitated

edit: if I try to compile the code with gfortran I get following:

xztrin21.f:1025.72:

      IF (H.EQ.0.) PAUSE 'Bad XA input.'                                
                                                                        1
Warning: Deleted feature: PAUSE statement at (1)
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
3

There are 3 answers

0
Tom83B On BEST ANSWER

So I solved the problem by creating a signature file first. I ran command

f2py -h opal.pyf -m opal xztrin21.f

and than

f2py -c add.pyf add.f95

and it works fine now. I used this tutorial: http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html

1
Syed Moez On
f2py -c --fcompiler=gnu95 -m modulename filename.f95

This command should work.

http://www.ucs.cam.ac.uk/docs/course-notes/unixcourses/pythonfortran/files/f2py.pdf

This is a very simple document that addresses how to use fortran module in python. This was very helpful to me.

5
Alexander McFarlane On

Ok so this doesn't look like a problem with the Fortran code you linked.

Your actual errors are all found In function ‘f2py_init_cst’:

  • :1828:35: error: ‘f2py_setup_cst’ undeclared (first use in this function)
  • :1819:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘!’ token

Judging by the name, this suggests an issue with the python package f2py. The syntax of the above means that the compiler found errors on line: 1828, column:35 and line:1819, column:71 in the f2py code.

  • I would suggest you check the documentation on f2py website and ensure that you are compiling it correctly
  • As a test, work through the examples shown in the f2py docs and ensure you can compile them