[Rd] Using FPP preprocessor for Fortran Code

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 1 10:45:53 CET 2014


On 30/11/2014 06:46, Michael Hahsler wrote:
> Dear R Developers,
>
> For package seriation I use Fortran code. I recently got a request to add
>
> #if defined(__ICC) || defined(__INTEL_COMPILER)
>        USE IFPORT
> #endif
>
> to the code since the Intel Fortran compiler otherwise has problems with
> rand(). However, to enable the FPP preprocessor I have to either add a

'Writing R Extensions' advises you not to use system RNGs, so this is a 
good time to comply.  §6.6 of 'Writing R Extensions' describes how to 
use the R RNG from Fortran.

> compiler flag (-cpp for gFortran) which is possibly not portable or
> change the extension to .F, .fpp, .FPP (and a few others) which
> automatically invokes the preprocessor (hopefully on all platforms). I

Many compilers do not know about .fpp or .FPP, and .F is not portable to 
case-independent file systems.

> tried .fpp and added the following to Makevars:
>
> OBJECTS=arsa.o bburcg.o bbwrcg.o bea.o criterion.o dist.o fprintf.o
> greedy.o optimal.o stress.o
>
> %.o: %.fpp
>          $(F77) $(ALL_FFLAGS) -c $< -o $@
>
> It seems to work (I tried Linux and Windows) but R CMD check gives me:
>
> * checking if this is a source package ... WARNING
> Subdirectory ‘src’ contains:
>    arsa.fpp bburcg.fpp
>
> Is there a different preferred method to do this? Is it possible to add
> support for Fortran with the fpp preprocessor (.fpp files) to the R
> package building process?

The support is as described in 'Writing R Extensions' §1.1.5.

You could add flags in PKG_FFLAGS, but you would have to use a configure 
script to find the right one (-xpp=fpp is also used).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK



More information about the R-devel mailing list