[R] Calling Fortran routines

Martyn Byng MartynB at nag.co.uk
Thu Apr 3 12:14:55 CEST 2003


Hi,

I am having problems calling a fortran routine from within R. When the
routine is called, R exits with an application error:
"The instruction at 0x004a8b7d referenced memory at 0x200000015. The memory
could not be written".

The R code used to call the routine is:
.Fortran("GTEST",a=as.integer(1),b=as.integer(3),c=as.integer(-10),d=as.inte
ger(0),e=as.integer(0))

The Fortran routine itself, is just a dummy routine, created to try and find
out why a more complex routine was causing R to crash, and consists of:

     SUBROUTINE GTEST_(A,B,C,D,E)
	INTEGER A,B,C,D,E

	!DEC$ ATTRIBUTES DLLEXPORT :: GTEST_
	!DEC$ ATTRIBUTES ALIAS:'GTEST_' :: GTEST_

      END

Where the !DEC commands are needed in Visual Fortran to create the DLL (I
think !, these were copied from an example file on the compaq web page).

The strange thing about this is that if I remove variable E from the
subroutine definition and recreate the DLL everything works as expected. The
routine causes R to crash only when it has more than 4 variables.

Any help would be appreciated.

Martyn

PS: I am using R version 1.6.2, under windows 2000 (professional), and the
Fortran code is compiled into a Windows 32bit DLL using Compaq Visual
Fortran Professional, edition 6.1.0

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk



More information about the R-help mailing list