From p.dalgaard at biostat.ku.dk  Thu Oct 20 17:55:27 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 20 Oct 2005 17:55:27 +0200
Subject: [Rd] calling fortran from C
In-Reply-To: <op.syx8kegag16iya@localhost.localdomain>
References: <XFMail.051020011342.Ted.Harding@nessie.mcc.ac.uk>
	<1129769164.5955.5.camel@localhost.localdomain>
	<971536df0510191809v3a7cd3d0k753e95a71be027d3@mail.gmail.com>
	<1129771685.5955.12.camel@localhost.localdomain>
	<17239.25754.59979.321531@stat.math.ethz.ch>
	<1129813104.8394.1.camel@localhost.localdomain>
	<op.syx8kegag16iya@localhost.localdomain>
Message-ID: <x21x2g6v4g.fsf@viggo.kubism.ku.dk>

"James Bullard" <bullard at berkeley.edu> writes:

> Hello, I had a question about calling some of R's fortran routines from C.  
> Specifically, I would like to call: dqrfit from some C code which will be  
> bundled as an R package. I was hoping someone knew of an example in some  
> of R's code which does something like this (any fortran call from R's C  
> would probably be a sufficient guide). So far I can only find locations  
> where R calls the Fortran directly, but this is not an option for me.
> 
> Also, I am trying to gauge the overhead of making this call, does anyone  
> have any knowledge of whether there might be some non-trivial constant  
> time penalty on making such a call.
> 
> Thanks in advance, Jim

The penalty is no bigger than on ordinary C calls. The main issue is
to get the naming convention right (HAVE_F77_UNDERSCORE, etc) and call
dqrfit_(....) if required -- all in a portable way. 

The whole thing is described in the Writing R Extensions manual,
section 5.6 specifically.



-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



[Rd] calling fortran from C
Peter Dalgaard