-1

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
Tom83B
  • 2,059
  • 4
  • 18
  • 28

3 Answers3

1

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
Alexander McFarlane
  • 10,643
  • 9
  • 59
  • 100
  • i ran the first example without any trouble. might be problem with the compiler afterall. see my edit – Tom83B Jun 09 '15 at 21:32
  • or do I need to have main() function somewhere in the code? – Tom83B Jun 09 '15 at 21:34
  • I don't think there is an issue with your compiler, it must be the way in which you are calling it. Just read through the docs carefully on `f2py`. Furthermore, the second issue you are having is because you are compiling a `SUBROUTINE` with no `PROGRAM`. It is looking for a `PROGRAM` and `END PROGRAM` but I'm guessing you don't have one. So it fails to find `main` because you have no program to compile! See [here](http://www.see.ed.ac.uk/~jwp/pse2/modelling/fortran/simple.html) on how to write a simple `Fortran` program and it should find `main` that way. – Alexander McFarlane Jun 09 '15 at 21:59
  • I suggest you call the program from within some basic `Fortran` code first before interfacing it with python – Alexander McFarlane Jun 09 '15 at 22:02
  • i got it working now with this tutorial http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html see my own answer. thank you for your effort alex – Tom83B Jun 09 '15 at 22:15
0

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

Tom83B
  • 2,059
  • 4
  • 18
  • 28
0
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.

Syed Moez
  • 129
  • 15
  • Also before using f2py. You need to make sure that you have defined the "intent" of the variables correctly. whether its intent(in)or intent(out). If this is not done in the fortran code by default. You can use "!f2py intent(in) var_name" This would be considered as a comment in fortran code but would be picked up by f2py. – Syed Moez Jun 10 '15 at 04:18