From sebastiendurand at videotron.ca  Thu Aug  4 01:51:08 2005
From: sebastiendurand at videotron.ca (Sebastien Durand)
Date: Wed, 3 Aug 2005 19:51:08 -0400
Subject: [Rd] call fortran in R
In-Reply-To: <Pine.OSF.4.58.0508031659140.143402@odin.mdacc.tmc.edu>
References: <E2197479-19D7-4C89-9E0D-DF0419209387@videotron.ca>
	<Pine.OSF.4.58.0508031659140.143402@odin.mdacc.tmc.edu>
Message-ID: <a06200700bf1705775cc6@[192.168.2.3]>

Hi Paul,

In fact, I used the three points just hide the 
long and exhaustive serie of parameters.

>From what I understood of the error warnings, my 
serie of parameters didn't even had the chance to 
be properly read and shall not be the cause of 
what we are seeing.
Even so I change the function name in 
.Fortran("name",....), I get the same error 
message.  It is like if it couldn't find the 
library I have dynamically loaded using dyn.load.
And I don't understand why, or where shall I look to fix such issue.

By the way you spoke about R's registration 
tables, could you tell me where should I look to 
find such info?

Thanks.

S?bastien

>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)
>
>______________________________________________
>R-devel at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] call fortran in R
Sebastien Durand