1

I am attempting to build a python wrap for some fortran code I have using f2py and am experiencing a very odd problem.

I am using Python 3.4.3 32 bit, gfortran 4.8.1, and numpy 1.9.2 on Windows 8.

f2py compiles the fortran code so I can call it from python. The code has multiple subroutines. Some of them work, but two do not. The important difference seems to be subroutine declaration spanning multiple lines. The working subroutines are declared on a single line. The ones that fail span multiple lines.

Example:

The Python call

    # import QC1_LIB ("library" of fortran code).
    import QC1_LIB
    TSDs = []
    message += "Duplicate and TSD Check have started...\n"
    QC1_LIB.dupandtsdchck(ts[0:##], data[0:##], ##, ##, ##, file, TSDs[0:##], ##)

where ## are some integers that are determined and assigned elsewhere.

The Fortran subroutine declaration

1234567
      SUBROUTINE DUPANDTSDCHCK(ts,data,nlines,nchar,frd,flnm,
     $     TSDs,counter)

The python does not recognize TSDs from the fortran code, i.e. it thinks there are only 7 arguments when in fact there are 8. It returns the error IndexError: QC1_LIB.dupandtsdchck() 7th argument (counter) can't be converted to int

I have not found this kind of problem mentioned anywhere. What is happening and how can I fix it?

Note: I realize I need to make some changes to the fortran code to actually get my desired output into the python workspace as f2py makes the subroutine into a function, but I'll worry about that later.

3
  • If TSDs is an output parameter, then f2py probably removed it from the call arguments and is returning it. instead. Jun 29, 2015 at 19:07
  • TSDs is meant to be both an input and output (goes in empty, comes out with ## strings in it). I have not done any of the intent(in)/intent(out) stuff that I know I need to do eventually. Are you suggesting including those will correct this problem?
    – jknicely
    Jun 29, 2015 at 19:24
  • Yes, I am suggesting that. With fortran 90 f2py has a better time guessing your intent, but in fortran 77 you pretty much need those declarations. Jun 29, 2015 at 19:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.