From b.rowlingson at lancaster.ac.uk  Sun May  8 09:43:31 2011
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Sun, 8 May 2011 08:43:31 +0100
Subject: [Rd] fortan common block
In-Reply-To: <6441154A9FF1CD4386AF4ABF141A056D2159FADE@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
References: <6441154A9FF1CD4386AF4ABF141A056D2159FADE@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
Message-ID: <BANLkTi=9TBmpxT-UL-FGCsejnEZ0-X3c8A@mail.gmail.com>

On Fri, May 6, 2011 at 4:04 PM, Paul Gilbert
<pgilbert at bank-banque-canada.ca> wrote:
> Is it possible in R to call a fortran routine that sets variables in a common block and expect the values to persist when a call is made from R to a second routine that uses the common block?
>
> If not (as I suspect), ?is it possible to use a common block in a group of routines that are used together, for as long the routines do not return to R?

Simple test seems to confirm it. Here's some 'tran with a setter and a getter:

comchk.f:

      subroutine bar(n)
      common /c/ i
      i=n
      end

      subroutine geti(j)
      common /c/ i
      j = i
      end

R CMD SHLIB comchk.f
 > dyn.load("comchk.so")

 > .Fortran("bar",as.integer(9))
 [[1]]
 [1] 9

 > .Fortran("geti",as.integer(-1))
 [[1]]
 [1] 9

Barry



[Rd] fortan common block
Barry Rowlingson