[R] problem of compile fortran program

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu May 30 16:44:59 CEST 2002


On Thu, 30 May 2002, Gao Feng                 (FIN) wrote:

>
>
> I want to call dll from R but encounter problem in compiling the fortran
> program.
>
> First I try "Rcmd shlib prog.f", it failed and warning:
>
>  make[1]: `libR.a' is up to date.
>  make: *** No rule to make target `'prog.o', needed by `prog.a'. stop.

No idea. When I use your example I get

[c:/TEMP]% Rcmd SHLIB prog.f
g77 -O2 -Wall  -c prog.f -o prog.o
ar cr prog.a *.o
ranlib prog.a
------- Building prog.dll from prog.a --------
echo LIBRARY prog > prog.def
echo EXPORTS >> prog.def
nm prog.a > Defs
sed -n '/^........ [BCDRT] _/s/^........ [BCDRT] _/ /p' Defs >> prog.def
rm -f Defs
gcc  --shared -s  -o prog.dll prog.def prog.a  -Lc:/R/rw1051/src/gnuwin32
-lg2c -lR
rm -f prog.def


> Then I try to compile it by absoft fortran compiler, it works and produces
> prog.dll.
> But when this routine is called in R, it did nothing in fact.
> For example,
>
> > x<-1:20
> > phi<-0.75
> > n<-20
> > .Fortran("_ARSIM",x,phi,n)
> [[1]]
>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
>
> [[2]]
> [1] 0.75
>
> [[3]]
> [1] 20
>
>
> What's wrong? I don't know how to deal with it.

Read ?Foreign.  The arguments should be DOUBLE PRECISION, but

.Fortran("arsim", as.single(x), as.single(phi), as.integer(20))

might work.  You've failed to match the types in Fortran and in R.

> Any suggestions would be great appreciated.
>
> Thanks in advance.
>
> -------FORTRAN CODE:  prog.f-------
>       SUBROUTINE ARSIM_(X,NDIM,PHI)
>       INTEGER NDIM
>       REAL X(NDIM),PHI
>       IF(NDIM.GT.1)THEN
>       DO 10 I=2,NDIM
>           X(I) = PHI*X(I-1)+X(I)
>    10 CONTINUE
>       ENDIF
>       RETURN
>       END
> ----------------------------

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list