Skip to content

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

Closed
@jdkloe

Description

@jdkloe

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions