[R] Calling C from FORTRAN and vice versa

Michael Höhle Michael.Hoehle at stat.uni-muenchen.de
Sat Jan 10 16:09:12 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear R-Help,

as I am not sure where to put this suggestion for improving the
documentation in "Writing R extensions" Section 6.6 (Calling C from
FORTRAN and vice versa) I send it to R-Help as suggested by the R Bug
Report page.

In Sect 6.6 an example is given on how to create .f and .c file in order
to call C from Fortran and vice versa. For better readability and for
preventing ppl calling the .c and the .f file the same base name
(causing "multiple definitions of symbol") I suggest that the docu
should provide file names for the two example programs, e.g.:

frand.f:

      subroutine testit()
      double precision normrnd, x
      call rndstart()
      x = normrnd()
      call dblepr("X was", 5, x, 1)
      call rndend()
      end

frand-helper.c:

#include <R.h>

/* Fortran */
void F77_SUB(rndstart)(void) { GetRNGstate(); }
void F77_SUB(rndend)(void) { PutRNGstate(); }
double F77_SUB(normrnd)(void) { return norm_rand(); }

As a further suggestion, it would also be nice to provide the call for
generating the dynamic library at this point:
R CMD SHLIB frand.f frand-helper.c .

At least this would have helped me in trying to get things to work, but
again - its just a suggestion.

Best regards,

Michael


- --

Michael Höhle, Ph.D.
Department of Statistics
University of Munich
Ludwigstrasse 33
80539 Munich
Germany

Phone:    +49 89 2180 6404
Fax:      +49 89 2180 5040

Email: hoehle at stat.uni-muenchen.de
Homepage: http://www.stat.uni-muenchen.de/~hoehle
PGP public key id: 0xA9589121
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJaLoYJenxFqlYkSERAgMeAKCtuX+SByQR4Eo1/xJj8Pg073jM8ACfa56t
7xnDhLzuS4q75ownnESyqek=
=yYKr
-----END PGP SIGNATURE-----




More information about the R-help mailing list