Re: [f2py] Acces to used module variables
Pearu Peterson <[email protected]> Thu, 29 Jul 2010 14:44:37 +0300
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
The first solution to your problem: wrap both modules with f2py.
For example:
f2py -m test -c pimodule.f90 mine.f90
>>> import test
>>> test.mine.init()
>>> test.mine.e
array(2.7000000476837158, dtype=float32)
>>> test.pimodule.pi
array(3.1400001049041748, dtype=float32)
The second solution is to tell f2py to wrap also pi. For example,
module mine
use pimodule
!f2py real::pi
implicit none
real::e
contains
subroutine init()
call initpi()
e = 2.7
end subroutine init
end module mine
f2py -m test mine.f90 -h test.pyf
f2py -c test.pyf pimodule.f90 mine.f90
>>> import test
>>> test.mine.init()
>>> test.mine.e
array(2.7000000476837158, dtype=float32)
>>> test.mine.pi
array(3.1400001049041748, dtype=float32)
Regards,
Pearu
On Thu, Jul 29, 2010 at 1:51 PM, <[email protected]> wrote:
> Hello,
> I have a question about the functionality of f2py (actually its the functionality of fortran):
> Is it possible, to access variables, that are not deklared in my wrapped module, but in a module that is imported by my wrapped module?
>
> Here is an example:
>
> module mine
> use pimodule
> implicit none
> real::e
> contains
> subroutine init()
> call initpi()
> e = 2.7
> end subroutine init
> end module mine
>
> module pimodule
> implicit none
> real::pi
> contains
> subroutine initpi()
> pi = 3.14
> end subroutine initpi
> end module pimodule
>
> Now I wrap 'mine' and would like to read the variables "e" and "pi" from python.
> To access e is not the problem, the problem is pi!
>
> I do something like this:
>
> Python 2.6.4 (r264:75706, Jan 21 2010, 07:46:28)
> [GCC 4.1.2 20070115 (SUSE Linux)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from test import *
>>>> print mine.__doc__
> e - 'f'-scalar
> init - Function signature:
> init()
>
>>>> mine.init()
>>>> mine.e
> array(2.7000000476837158, dtype=float32)
>>>> mine.pi
> Traceback (most recent call las):
> File "<stdin>", line 1, in <module>
> AttributeError: pi
>>>> mine.pimodule.pi
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: pimodule
>
> Do you know a solution for this problem? Maybe with the PUBLIC option?
>
> Thank you in advance
> Malte
>
> -----------------------------------------------------------------------------
> Deutsches Zentrum für Luft- und Raumfahrt e.V.
> in der Helmholtz-Gemeinschaft
>
> Malte Mauelshagen
>
> Lilienthalplatz 7
> 38108 Braunschweig
> Tel.: 0531/295-2483
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>