add

IMPLICIT NONE
DOUBLE PRECISION X(N),XMEAN
INTEGER N,J

to your subroutine.

Ciao

Simone

P.S. It is best to include IMPLICIT NONE in all of your subroutines and to
avoid underscores in subroutines' names.



On Wed, May 4, 2011 at 2:26 PM, vioravis <vioravis@gmail.com> wrote:

> I have the following FORTRAN code converted to a DLL:
>
> ! my_xmean.f90
> !
> ! FUNCTIONS/SUBROUTINES exported from my_function.dll:
> ! my_function - subroutine
> !
> subroutine my_xmean(X,N,XMEAN)
>
> ! Expose subroutine my_function to users of this DLL
> !
> !DEC$ ATTRIBUTES DLLEXPORT,C,REFERENCE,ALIAS:'my_xmean_'::my_xmean
>
> ! Body of my_function
>
> DOUBLE PRECISION X(N)
>
> XMEAN=0D0
> DO J=1,N
> XMEAN=XMEAN+X(J)
> END DO
> XMEAN=XMEAN/N
> RETURN
> end subroutine my_xmean
>
>
>
> When I call this DLL from R, it gets loaded properly but the values of
> XMEAN
> calcualted are way off:
>
>
> x <- 1:6
>
> > .Fortran("my_xmean",as.double(X),as.integer(length(X)),double(1))
>
> [[1]]
> [1] 1 2 3 4 5 6
>
> [[2]]
> [1] 6
>
> $xmean
> [1] 5.336073e-315
>
> Can someone please let me what is causing this huge difference??? Thank
> you.
>
> Ravi
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Error-in-Fortran-Call-tp3495319p3495319.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
______________________________________________________

Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153
http://www2.stat.unibo.it/giannerini/
______________________________________________________

	[[alternative HTML version deleted]]

