how to wrap f90 modules

66 views
Skip to first unread message

Ondrej Certik

unread,
Aug 10, 2010, 12:43:14 AM8/10/10
to fwrap...@googlegroups.com
Hi,

I have successfully (e.g. it compiled into a Python module, that can
be imported) my fortran code.

However, I had to comment out the fortran module stuff and only keep
the subroutines as they are.

Is there any way to support compiling fortran modules? I saw some
tests for that in tests/todo. :)

Ondrej

Antony Hallam

unread,
Aug 10, 2010, 8:51:15 AM8/10/10
to fwrap...@googlegroups.com
This is also the main reason I am interested in fwrap, wrapping modules would be really useful with my code.

--
Regards Tony Hallam 19 Hefferan St Fairfield 4103 0407394671

Kurt Smith

unread,
Aug 10, 2010, 9:33:38 AM8/10/10
to fwrap...@googlegroups.com
On Tue, Aug 10, 2010 at 7:51 AM, Antony Hallam <trha...@gmail.com> wrote:
> On 10/08/10 14:43, Ondrej Certik wrote:
>
> Hi,
>
> I have successfully (e.g. it compiled into a Python module, that can
> be imported) my fortran code.
>
> However, I had to comment out the fortran module stuff and only keep
> the subroutines as they are.
>
> Is there any way to support compiling fortran modules? I saw some
> tests for that in tests/todo. :)
>
> Ondrej
>
>
>
> This is also the main reason I am interested in fwrap, wrapping modules
> would be really useful with my code.

The 0.1 release focused on getting top-level (non-module) functions &
subroutines wrapped, which covers a large portion of F77-style code.

The 0.2 release has planned support for 'use' statements and basic
module wrappers. There's always a competition for resources between
supporting the new F90-stuff and the legacy F77 stuff.

There is some significant work to be done in the parser to get module
support working correctly, which is why there isn't more mod support
right now.

Kurt


>
> --
> Regards Tony Hallam 19 Hefferan St Fairfield 4103 0407394671
>

> --
> You received this message because you are subscribed to the Google Groups
> "Fwrap Users" group.
> To post to this group, send email to fwrap...@googlegroups.com.
> To unsubscribe from this group, send email to
> fwrap-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fwrap-users?hl=en.
>

John McFarland

unread,
Sep 12, 2010, 11:35:49 AM9/12/10
to Fwrap Users
Hi,

If you are comfortable using Swig, you may want to check out FortWrap:
http://fortwrap.sourceforge.net/. It will wrap module procedures (and
also derived types) as C++ classes. If you want to create a Python
module, you would then need to use Swig to wrap the C++ header files
that it generates (although this is usually pretty easy). Make sure
to take a look at the list of unsupported features though: FortWrap
doesn't currently (maybe in the near future) wrap assumed shape
arrays, and it only has very limited support for KIND= specifiers
right now.

John

Ondrej Certik

unread,
Sep 13, 2010, 1:21:25 PM9/13/10
to fwrap...@googlegroups.com

Thanks for the link, I was not aware of this project.

I would use Cython to wrapp the C++ classes (I don't use swig
anymore...), but otherwise it would be useful.

Ondrej

Dag Sverre Seljebotn

unread,
Sep 13, 2010, 2:05:05 PM9/13/10
to fwrap...@googlegroups.com
That's very interesting; fwrap and fortwrap seems to have opposite
strengths/weaknesses...

Do you have an idea of the quality and completeness of the Fortran
parser used by fortwrap?

Dag Sverre

John McFarland

unread,
Sep 13, 2010, 2:23:45 PM9/13/10
to fwrap...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups
> "Fwrap Users" group.
> To post to this group, send email to fwrap...@googlegroups.com.
> To unsubscribe from this group, send email to
> fwrap-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fwrap-users?hl=en.
>
>

Well, I am actually the author and as of now sole maintainer. I just
put FortWrap on SourceForge last month, but have been using a
specialized version of it internally for about a year.

Unlike Fwrap, FortWrap doesn't use a general purpose Fortran parser --
basically I just wrote the parser myself and have been adapting it as
new cases have come up. As far as I know, it should be able to handle
most F90-F03 constructs and at least print errors/warnings for
constructs that it doesn't wrap. I have run it through most of the
Fwrap test cases, and while not all of those features are supported by
the wrapper generation (e.g. assumed shape arrays), it at least
doesn't crash and writes error messages where appropriate.

One construct it doesn't yet handle is a declaration like "integer x"
(i.e. no "::"), but hopefully I will get that added soon.

Overall, I haven't gotten any feedback on it yet, as it's pretty new,
so if someone wanted to run some code through it and see how it works
that would be appreciated. I'm more than happy to take my best stab
at fixing any bugs or making any enhancements needed to make it more
useful (assuming they're not too inconsistent with FortWrap's
objective, which is wrapping modern code).

John

Kurt Smith

unread,
Sep 13, 2010, 2:29:22 PM9/13/10
to fwrap...@googlegroups.com
On Sun, Sep 12, 2010 at 10:35 AM, John McFarland <mcfa...@gmail.com> wrote:
Hi,

If you are comfortable using Swig, you may want to check out FortWrap:
http://fortwrap.sourceforge.net/.  It will wrap module procedures (and
also derived types) as C++ classes.  If you want to create a Python
module, you would then need to use Swig to wrap the C++ header files
that it generates (although this is usually pretty easy).  Make sure
to take a look at the list of unsupported features though: FortWrap
doesn't currently (maybe in the near future) wrap assumed shape
arrays, and it only has very limited support for KIND= specifiers
right now.

Very interesting.  Apologies for the delay in approving your message -- I just got back from a 10-day unplugged vacation.

I'll be looking at FortWrap for inspiration, esp. as fwrap starts to support derived-types.

Kurt
 

John
 

Dag Sverre Seljebotn

unread,
Sep 13, 2010, 2:38:35 PM9/13/10
to fwrap...@googlegroups.com
Thanks for your overview. Note that fwrap is also able to produce pure C
wrappers (right Kurt?), or at least Fortran "wrappers" providing an
ISO_C_BINDING-compliant interface without assumed shape arrays. So in
the long term, it is at least technically possible for FortWrap and
Fwrap to share parser and backend for Fortran-to-C wrapping, which takes
care of all the assumed shape arrays and so on, while FortWrap generates
the C++ on top and Fwrap the Cython on top.


Dag Sverre

Reply all
Reply to author
Forward
0 new messages