[f2py] help using fparser

David Froger <[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Hello,

I spent a lot of time working on Fortran code, and would like to automate some
tasks with Python scripts based on fparser.

I have read f2py/fparser/doc.txt, but I still have some diffculties.

As an example of script, I would like to scan fortran files and have this kind
of informations:

 - subroutine foo1 calls subroutines foo10, foo 11 and foo12,
 - subroutine foo2 calls subroutines foo10, foo13 and function foo20,
 - subroutine foo10 calls subroutine foo21,
 - etc...

I write this stupid-program as test (example.f90):





!=============================================================================
program ex
!=============================================================================

    implicit none

    real(4):: a,b,c
    real(4):: average,division

    a = 1.
    b = 2.
    c = 3.

    call div(c,b,division)

    call avg(a,b,c,average)

    write(*,*) 'average a b c ',average
    write(*,*) 'c/b',division

end program ex


!=============================================================================
subroutine avg(a,b,c,average)
!=============================================================================

    implicit none

    real(4),intent(in):: a,b,c
    real(4),intent(out):: average
    real(4):: y

    real(4):: total

    call add(a,b,c,total)
    call div(total,3.,average)

end subroutine avg


!=============================================================================
subroutine div(x,y,division)
!=============================================================================

    implicit none

    real(4),intent(in):: x,y
    real(4),intent(out):: division

    division = x/y

end subroutine div

!=============================================================================
subroutine add(a,b,c,total)
!=============================================================================

    implicit none

    real(4),intent(in):: a,b,c
    real(4),intent(out):: total

    total = a + b + c

end subroutine add






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
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.