Re: [f2py] help using fparser

David Froger <[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
David Froger <david.froger@...> writes:

> and I'm searching to write a Python script which obtain the
> same results as this
> one:
> 
> #!/usr/bin/env python
> 
> import sys
> sys.path.append('/home/dfroger/travail/codes/f2py/fparser')
> from readfortran import *
> from parsefortran import *
> 
> reader = FortranFileReader('example.f90')
> parser = FortranParser(reader)
> parser.parse()
> 
> print 'THE UNIT:'
> print parser.block.content[0].name
> print 'NEEDS THE UNITS:'
> print '== ',parser.block.content[0].content[6].designator
> print '== ',parser.block.content[0].content[7].designator
> print
> print 'THE UNIT:'
> print parser.block.content[1].name
> print 'NEEDS THE UNITS:'
> print '== ',parser.block.content[1].content[5].designator
> print '== ',parser.block.content[1].content[6].designator
> print
> print 'THE UNIT:'
> print parser.block.content[2].name
> print 'NEEDS THE UNITS:'
> print
> print 'THE UNIT:'
> print parser.block.content[2].name
> print 'NEEDS THE UNITS:'
> 
> thanks everybody for having read this post, and for any help!
> 
> David
> 

I think I've found how to do, using "isintance", I'm not sure it's the pythonic
way...?


#!/usr/bin/env python

# dependance = {'unitname':['unitname' ,...] ,...}

import sys
import os
sys.path.append(os.path.expanduser("~/travail/codes/f2py/fparser"))
from readfortran import *
from parsefortran import *
from statements import Call

reader = FortranFileReader('example.f90')
parser = FortranParser(reader)
parser.parse()

dependance = {}

for unit in parser.block.content:
    dependance[unit.name] = []
    for statement in unit.content:
        if isinstance(statement,Call):
            dependance[unit.name].append(statement.designator)

for unit,units_dependance in dependance.iteritems():
    print 'THE UNIT:'
    print unit
    print 'NEEDS THE UNITS:'
    for unit_dependance in units_dependance:
        print '== ',unit_dependance
    print
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.