[R] Error of exp() in a dll from Fortran

Hao Ren Sr renhao at msu.edu
Sat Jul 12 09:56:10 CEST 2008


Hi, 

I have an error happened when I use exp() in my Fortran code. My Fortran 
code is
     SUBROUTINE f(n,c)
	
	    REAL, INTENT(IN) :: n(10)
	    REAL, INTENT(OUT) :: c(10)
	    INTEGER :: k
	
	    DO k=1, 10
	       c(k) = exp( n(k) )
	    END DO
     END 

I compiled the fortran code as a dll 

 Rcmd SHLIB -o f.dll f.f -L -lacml 

Then I loaded the dll file to R, and try some number 

> dyn.load("C:/Program Files/R/R-2.7.1/bin/code/f.dll")
> .Fortran("f",as.real(c(1:10)),A=real(10))
[[1]]
[1]  1  2  3  4  5  6  7  8  9 10 

$A
[1]  17066.21  58265.20 179948.41 390001.06 576529.12      0.00      0.00
[8]      0.00      0.00      0.00 

I tried to figur out what happened, but confused. Any suggestion?
Thanks 

Hao Ren



More information about the R-help mailing list