[R] .Fortran()

John Bjornar Bremnes J.B.Bremnes at dnmi.no
Tue Oct 9 16:14:24 CEST 2001


Prof Brian Ripley wrote:
> 
> On Mon, 8 Oct 2001, John Bjornar Bremnes wrote:
> 
> > I am trying to call some Fortran subroutines using .Fortran(). These
> > subroutines have arguments of type 'character', 'real', 'integer', and
> > 'integer*2'. Is it impossible to call  subroutines expecting both
> > 'character' and 'real' as input?
> 
> No, but it is impossible to call those expecting 'integer*2'

Ok, it seems that I can easily avoid using 'integer*2'
 
> See ?.Foreign for what is supported, and note the comments there about
> character types: they work on some compilers and not on others.

Is g77 one of those where it does not work? I use R-1.3.0 on linux (PC).
I have tried the following simple example:

      subroutine mysub(filein, m, x, n)
c
      integer        m, n, i
      character*255  filein
      real           x(n)
c
      write(6,*) 'file: ', filein(1:m)
      do i=1,n
         x(i) = sqrt(1.0*i)
      enddo
      end

% R CMD SHLIB mysub.f 
g77   -fPIC  -g -O2 -c mysub.f -o mysub.o
gcc -shared  -o mysub.so mysub.o -L/usr/local/lib -lg2c -lm
-L/usr/local/lib -L. -L/usr/lib/gcc-lib/i386-linux/2.95.2 -lm 

> dyn.load("mysub.so")
> .Fortran( "mysub", as.character("myfile"), as.integer(6), as.single(rep(0,10)), as.integer(10), DUP=T )
 file: myfile
Segmentation fault (core dumped)
% R
> dyn.load("mysub.so")
> .Fortran( "mysub", as.character("myfile"), as.integer(6), as.single(rep(0,10)), as.integer(10), DUP=F )
Error: character variables must be duplicated in .C/.Fortran
>

Any comments?


Thanks again
John Bjornar Bremnes
Norwegian Meteorological Institute
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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