Skip to content

f2py fortran parsing fails in case commented line present in parameter list #2848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jdkloe opened this issue Dec 20, 2012 · 7 comments · Fixed by #18416
Closed

f2py fortran parsing fails in case commented line present in parameter list #2848

jdkloe opened this issue Dec 20, 2012 · 7 comments · Fixed by #18416

Comments

@jdkloe
Copy link

jdkloe commented Dec 20, 2012

A simple piece of valid fortran code, using commented lines in between parameters in a subroutine parameter list currently lets f2py produce bogus results.

See for example this code:

subroutine parametertest( &
     ! first 2 parameters
     par1, par2,&
     ! last 2 parameters
     par3, par4)

  integer, intent(in)  :: par1, par2
  integer, intent(out) :: par3, par4

  par3 = par1
  par4 = par2

end subroutine parametertest

this gfortran statements compiles the code without a single warning:

 >gfortran -c  -Wall test.F90

When producing the signature file the following warning is shown:

>f2py -h sign.pyf test.F90 -m parametertest
Reading fortran codes...
        Reading file 'test.F90' (format:free)
Line #2 in test.F90:"subroutine parametertest( "
        analyzeline: No name/args pattern found for line.
Post-processing...
        Block: parametertest
                        Block: unknown_subroutine
Post-processing (stage 2)...
Saving signatures to file "./sign.pyf"
>

In the signature file subroutine name and associated parameter list remain undefined and a bogus subroutine named unknown_subroutine without parameters is defined in stead:

python module parametertest ! in 
    interface  ! in :parametertest
        subroutine unknown_subroutine ! in :parametertest:test.F90
        end subroutine unknown_subroutine
    end interface 
end python module parametertest

after removing the 2 comments the test runs just fine:

>f2py -h sign2.pyf test2.F90 -m parametertest
Reading fortran codes...
        Reading file 'test2.F90' (format:free)
Post-processing...
        Block: parametertest
                        Block: parametertest
Post-processing (stage 2)...
Saving signatures to file "./sign2.pyf"
>

The f2py version used for testing was: numpy-f2py-1.6.2-1.fc17.x86_64
python version was: python-2.7.3-7.2.fc17.x86_64
gfortran version was: gcc-gfortran-4.7.2-2.fc17.x86_64

executed 20-Dec-2012 on Fedora 17 (64-bit)

@jdkloe
Copy link
Author

jdkloe commented Dec 20, 2012

I would like to attach the test and pyf files to this report. If this is possible here could anyone tell me how to do this, since this is not obvious at all to me.

@rgommers
Copy link
Member

You can put them up as gists (https://gist.github.com/) or put them somewhere else and link to them. Unfortunately Github doesn't support attachments too well.

@jdkloe
Copy link
Author

jdkloe commented Jan 29, 2013

Thanks for your help. The files are here: https://gist.github.com/4664883
Probably not much of an improvement to have them in another location, if you also could cut and paste them from here, but it is always nice to have an alternative in case the fragments become very large.

@RosterIn
Copy link

Is this still an issue?

@jdkloe
Copy link
Author

jdkloe commented Apr 23, 2019

yes, this issue is still present.
My current f2py version is: 1.15
(from package python2-numpy-f2py-1.15.1-1.fc29.x86_64)
but the behaviour is still exactly the same.

@jdkloe
Copy link
Author

jdkloe commented Apr 23, 2019

python3 version gives the same error.

@pearu
Copy link
Contributor

pearu commented Feb 15, 2021

#18416 contains the fix.

@pearu pearu self-assigned this Feb 15, 2021
mattip added a commit that referenced this issue Feb 15, 2021
BUG: Fix f2py parsing continued lines that follow comment lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants