[R] [r] Problems with Fortran calls when loaded a dll compiled with gfortran-4 Cygwin 4.5.3
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Apr 24 19:46:36 CEST 2013
On 13-04-24 1:36 PM, Jens Olofsson wrote:
> Dear users of R
> I have a subroutine in Fortran95, compiled to a DLL with gfortran in Cygwin
> 4.5.3.
We don't support Cygwin. You should use the gfortran in Rtools, and get
R to set the command line options for you, either by putting the code in
a package, or by using R CMD SHLIB Mango.f95.
Duncan Murdoch
> The subroutine is:
> subroutine MyPBP( S, p, N )
> ! Expose subroutine rtest to users of this DLL
> !DEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE, ALIAS: "mypbp_" ::mypbp
> ! This function computes the Poisson-Binomial distribution
> ! of size N using p
> double precision, intent(inout) :: S(N+1)
> double precision, intent(in) :: p(N)
> integer, intent(in) :: N
> double precision :: X(N+1)
> integer i, j
> !X=0
> !S=0
> X(1) = 1 - p(1)
> X(2) = p(1)
> do i = 2, N
> S(1) = X(1)*(1-p(i))
> do j = 2,i
> S(j) = X(j-1)*p(i) + X(j)*(1-p(i))
> end do
> S(i+1) = X(i)*p(i)
> X = S
> if (i == N) then
> S = X
> end if
> end do
> end subroutine MyPBP
> and it is saved into Mango.f95
> I compile it from the bash shell using: gfortran-4 c- Mango.f95 and
> gfortran-4 -shared -o Mango.dll Mango.o
> I am on a Windows machine running Windows 7 with Intel i7.
> I load the dll in a 32-bit R by dyn.load("Mango.dll"). Using getLoadedDLLs
> I can see the DLL. However, is.loaded("Mango.dll") = FALSE. In addition, R
> stop responding when I try .Fortran("MyPBP", as.numeric(S), as.numeric(p),
> as.integer(N)),
> where N<-5, S<-array(0,N+1) and p<- c(0.1, 0.2, 0.5, 0.8, 0.9).
>
> What am I doing wrong?
> Any ideas, thoughts and/or comments are highly appreciated.
>
> Jens
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list