[Rd] call fortran in R

Paul Roebuck roebuck at odin.mdacc.tmc.edu
Thu Aug 4 00:07:10 CEST 2005


On Wed, 3 Aug 2005, =?iso-8859-1?Q?S=E9bastien_Durand_ wrote:

> I used a mac G5, R.2.1.1, and G77 3.4.4 and I would like to use and
> call a fortran subroutine.
> The trouble is that it seems I am not able to correctly load the
> compiled code.
>
> Here is what I have done:
>
> In the terminal this how I compiled my fortran code:
>
>          R CMD SHLIB  ~/Desktop/Fortan_kmeans/kmeans3.f
>
> There is the wrapper I have paste inside de kmeans3.f file:
>
>          c THIS IS THE WRAPPER
>                subroutine wrapper(n, p, nran, mat, ishort, w, z,
>              + ntran, istand, k1, k2, iassign, iseed)
>                integer n,p,kmax
>                real*8 mat(n,p),sx(kmax,p),sx2(kmax,p),vect(p),
>              +     xbar(kmax,p),var(kmax,p),mean(p),coord(10)
>                real*8 D1,Dref,SSE,SSEref,Dvec(kmax),w(p),SST
>                real*8 CH,CHr(kmax),SSEr(kmax),temp
>                integer list(n),howmany(kmax),no(n),nobest(kmax)
>                integer listr(kmax,n),howmanyr(kmax,kmax),nnitr(kmax)
>                integer ishort(p)
>                double precision kmeans,
>                external kmeans
>
>                call kmeans(n, p, nran, mat, ishort, w,
>              + ntran, istand, k1, k2, iassign, iseed)
>                end
>              c THIS IS THE BEGINNING OF THE ORIGINAL FORTRAN CODE
>                subroutine kmeans(n, p, nran, mat, ishort, w,
>              + ntran, istand, k1, k2, iassign, iseed, CHr, SSEr)
>               ......
>
> Once compiled, in R, I get the following:
>
>  > dyn.load("/Users/sebas/Desktop/Fortan_kmeans/K-means3.so")
>  > getLoadedDLLs()
>
>    Filename
> 1
>      base
> 2  /Library/Frameworks/R.framework/Resources/library/grDevices/libs/
> grDevices.so
> 3          /Library/Frameworks/R.framework/Resources/library/stats/
> libs/stats.so
> 4      /Library/Frameworks/R.framework/Resources/library/methods/libs/
> methods.so
> 5   /Users/sebas/Desktop/Fortan_kmeans/kmeans3.so
>
>     Dynamic.Lookup
> 1           FALSE
> 2           FALSE
> 3           FALSE
> 4           FALSE
> 5            TRUE
>  >
>  > is.loaded(symbol.For("/Users/sebas/Desktop/Fortan_kmeans/
> kmeans3.so"))
> [1] FALSE
>  > is.loaded(symbol.For("kmeans3"))
> [1] FALSE
>  > is.loaded(symbol.For("wrapper"))
> [1] FALSE
>
> Then whatever I write in .Fortran("",...), I always get :
> Erreur in .Fortran("/Users/sebas/Desktop/Fortan_kmeans/kmeans3.so",... :
>      the function name "Fortran" is absent of the allocation table
>      (this warning was translated from french)

Shouldn't that be .Fortran("wrapper", <arglist>) or something
to that effect? I'm surprised that a null string didn't
crash the program.

Might want to look into R's registration tables as well.
That way you might get some additional debugging help.

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



More information about the R-devel mailing list