0

I'm having a problem with compiling via f2py. I have an f90 module with several subroutines in it. It has been compiling fine up to this point for use in a python script. However, now when I try to compile it and build it, it complains with this error:

build/src.macosx-10.5-x86_64-2.7/PyCosmology/sims/fort/read_sim-f2pywrappers2.f90:355.17:

   allocate(d())
             1
Error: Shape specification for allocatable scalar at (1)

It also has two other errors, but these just result from d() not being allocated correctly here. You can see that the file it is compiling is the f2py wrapper. More strangely, when I actually look at the wrapper file that it points to, line 355 is in fact:

       allocate(d(s(1),s(2)))

so I have no idea why the compiler is telling me there are no shape specifiers in the allocate statement. And because of that, I have no idea how to fix it!

Note that I have changed the module a little since last it compiled correctly, but the array for which this error occurs I have not touched at all, neither have I touched the particular subroutine it exists in.

StevenMurray
  • 742
  • 2
  • 7
  • 18
  • After some digging I have found that the subroutine that the error is occurring in is not one that I need to call from python (it just needs to be called by subroutines in the module). However, I've had trouble before with keeping these subroutines out of the file - see http://stackoverflow.com/questions/11148841/f2py-giving-redefinition-of-foo-previous-definition-was-here, so barring that, is there any way to let f2py know NOT to make interfaces for these unused routines? Or do I have to manually edit the pyf file? – StevenMurray Jul 25 '12 at 01:02
  • 1
    yes, in f2py, just use the command-line option "only: routine1 routine2 :" to select certain routines, or "skip" to just avoid specific ones. – DaveP Jul 25 '12 at 01:22
  • @DaveP Thanks very much. I am compiling and building using numpy.distutils, so is there a place to put these commands within the setup.py script? – StevenMurray Jul 25 '12 at 01:34
  • 1
    yes, just add f2py_options=["only:","routine1", "routine2", ":"] to the Extension object – DaveP Jul 25 '12 at 02:00
  • @DaveP Cheers you're a lifesaver. Seems to have worked! – StevenMurray Jul 25 '12 at 02:11
  • So it seems that although it doesn't give any errors relating to the skipping etc., I'm still getting the same error as in the original post. This is strange since it should be completely skipping the routine which has the array which is giving the error now. – StevenMurray Jul 25 '12 at 02:26
  • No worries. My guess is that there is some error in your code which may be only slightly related to the error message. I have found that f2py can give very unhelpful error messages at times, or even throw an exception. A good check is to compile the code directly with your fortran compiler - this can give a meaningful error or warning message when f2py just gives up. – DaveP Jul 25 '12 at 03:14

1 Answers1

0

Figured it out.

I was trying to allocate to an integer. Sorry.

StevenMurray
  • 742
  • 2
  • 7
  • 18