[Rd] Error in .Fortran Call

2011-05-04 Thread vioravis
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


Re: [Rd] Error in .Fortran Call

2011-05-04 Thread vioravis
Thanks a lot. I will try the recommended changes.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-Fortran-Call-tp3495319p3495777.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


[Rd] Fortran Symbol Name not in Load Table

2011-05-09 Thread vioravis
I am trying to call a FORTRAN subroutine from R. is.loaded is turning out to
be TRUE. However when I run my .Fortran command I get the following error:

Error in .Fortran("VALUEAHROPTIMIZE", as.double(ahrArray),
as.double(kwArray),  : 
  Fortran symbol name "valueahroptimize" not in load table


I have given the FORTRAN declaration below:

subroutine VALUEAHROPTIMIZE(AHR,&
KW,&
min_IHR_delta,  &
max_AHR_error,  &
AHR_out,   & !! Output AHE array
IHR_out,   & !! Output IHR array
Errors_out)
  ! Expose subroutine my_function to users of this DLL
  !DEC$ ATTRIBUTES
DLLEXPORT,C,REFERENCE,ALIAS:'VALUEAHROPTIMIZE_'::VALUEAHROPTIMIZE
 
  ! Body of my_function
 
  Implicit None
 
  Integer *4  IERR, iSum
  DOUBLE PRECISION min_IHR_delta, max_AHR_error
  logical switch_AHR_tuner
  character * 512 AHR_tuner_FilePath
 
  !!DOUBLE PRECISION  AHR(500), kW(500)  !! Initial Array for reading
Namelist
  
  DOUBLE PRECISION  AHR(*), kW(*)  !! Initial Array for reading Namelist
  DOUBLE PRECISION  AHR_out(*), IHR_out(*)
  integer Errors_out(*)


The R code I tried using is given below:

ahrArray <- runif(147)
kwArray <- runif(147)
outputAHR <- c(rep(0,11*11))
outputIHR <- c(rep(0,11*11))
outputError <- c(rep(NA,11))

dyn.load("my_function.dll")
is.loaded("VALUEAHROPTIMIZE")

[1] TRUE

> .Fortran("VALUEAHROPTIMIZE",
  as.double(ahrArray),
  as.double(kwArray),
  as.double(0.0005),
  as.double(5),
  as.double(outputAHR),
  as.double(outputIHR),
  as.integer(outputError))

Can someone please help me with how to fix this issue? Thank you.

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3508719p3508719.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


Re: [Rd] Fortran Symbol Name not in Load Table

2011-05-09 Thread vioravis
Just realized that there are two functions in the same DLL. The other
function is working fine.

--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3508719p3508852.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


Re: [Rd] Fortran Symbol Name not in Load Table

2011-05-09 Thread vioravis
I used the DLL export viewer to what is the table name being exported. It is
showing as VALUEAHROPTIMIZE_. This is the name of the function we have used
plus the underscore.

Is there any other reason for the function not getting recognized??? Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3508719p3510758.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


Re: [Rd] Fortran Symbol Name not in Load Table

2011-05-10 Thread vioravis
Thank you Sharpie and Duncan.

I am using Compaq Visual Fortran compiler on a Windows machine.

I tried with all small letters for the function names and created the DLLs.
But somehow the DLL created only had all CAPS. But the DLL worked when I
changed the function name to myxmean. Not really sure what changed but it
worked fine :)

Ravi



--
View this message in context: 
http://r.789695.n4.nabble.com/Fortran-Symbol-Name-not-in-Load-Table-tp3508719p3513909.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