From gilles.guillot at inapg.inra.fr  Tue Jun 14 19:05:24 2005
From: gilles.guillot at inapg.inra.fr (Gilles GUILLOT)
Date: Tue, 14 Jun 2005 19:05:24 +0200
Subject: [Rd] Calling C from Fortran
Message-ID: <200506141905.24517.gilles.guillot@inapg.inra.fr>

I would like to call C routines from Fortran under linux as suggested in 
section 5.6 of 
the "Writing R extensions" documentation.

I'm familiar with Fortran but not with C.
I understand the example provided in Fortran:

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


but I don't understand the purpose of this C wrapper:
#include <R.h>  
 void F77_SUB(rndstart)(void) { GetRNGstate(); }
 void F77_SUB(rndend)(void) { PutRNGstate(); }
 double F77_SUB(normrnd)(void) { return norm_rand(); }

neither how I should compile it.

Could anyone explain how I should compile and link 
the C and Fortran files above, and call the Fortran subroutine from R.

Thanks,

Gilles



[Rd] Calling C from Fortran
Gilles GUILLOT