From hartwig.deneke at gmail.com  Tue Dec 29 13:44:22 2009
From: hartwig.deneke at gmail.com (Hartwig Deneke)
Date: Tue, 29 Dec 2009 13:44:22 +0100
Subject: [Rd] Calling Fortran90 code from R
In-Reply-To: <3c12769c0912290337t65d774c4mf32ff36e78ed6923@mail.gmail.com>
References: <1cd92f370912290126s137f83d9k5223e877cc237c64@mail.gmail.com>
	<3c12769c0912290337t65d774c4mf32ff36e78ed6923@mail.gmail.com>
Message-ID: <1cd92f370912290444gffb6372o3006a746da671329@mail.gmail.com>

2009/12/29 Simone Giannerini <sgiannerini at gmail.com>:
> Dear Hartwig,
>
> I think there are many packages that use F90 code and you should really be
> able to call it by following the advices in the R-exts
> manual. There are no major differences with F77 and you do not need a C
> wrapper. Maybe you might start with a simple example like this one.
>
....(helpful example removed)...
> open R ************************
> dyn.load("foo.so")
> is.loaded("foo")
>
> TRUE
Dear Simone (and others reading),

first of all thanks for your helpful example. While I did something
similar yesterday, it did give me a simple example to start from which
worked, and find a nice approach to solving my problems. A brief
summary of the origin of my problems, which are related to the use of
Fortran90 module declarations.

It is perfectly possible to call Fortran90 code compiled with
gfortran. Compiling a subroutine/function "foo" will produce a symbol
"foo_" in the dynamic library. If, however, the subroutine is
contained in a module named "modname", the symbol will be called
"__modname_MOD_foo". In  this case, it will not be found by the
".Fortran" call or a call to "is.loaded", at least I have not found
any way to do this. However, for my purposes, I have simply added a
set of wrapper subroutines to the library (which I planned to add
anyway for other reasons, in particular to reduce the number of
arguments), which forwards the calls to the module functions, and
everything seems to work all right.

Kind Regards,
Hartwig



[Rd] Calling Fortran90 code from R
Hartwig Deneke