felipevargas93 / rfortran

Automatically exported from code.google.com/p/rfortran
0 stars 0 forks source link

Rput failed in a loop #103

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
*** What steps will reproduce the problem?

1. construct a loop
2. pass an value to the entry of an array defined in R
3.

*** What is the expected output? an array contains values which are passed from 
fortran within each loop

*** What do you see instead? 0 values

*** What version of RFortran are you using? RFortran Library v3.0.0 - 14 Feb 
2011

*** On which Windows operating system? Windows 7

*** What Fortran compiler (name and version number) are you using? Intel

*** What version of R are you using? R version 2.12.1

*** Run the simple test program, "RFortran\Simple Test Programs\_RputRgetRe
valRcall_IVF_unitTests\RputRgetRevalRcall_IVF_unitTests.exe" and provide a
copy of the RFortran.log file (located in the same folder)

*** If there were installer errors - please provide of the output from the
installer window(s)

*** If there were build errors - please provide a copy of the build output
from IVF/CVF

*** If you have a coding solution to this defect please include the file
(or preferably a svn patch) as an attachment

*** Please provide any additional information below.

Original issue reported on code.google.com by j...@civeng.adelaide.edu.au on 4 Aug 2011 at 6:39

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for this. The fail is not to do with the loop in Fortran. It is an issue 
with IStatConnector_SetSymbol which does not evaluate the string param[i] ... 
which would become param[1] on the first iteration but somehow manages to 
create a new variable called "param[i]". It assigns the value to this new 
variable. The setting routine takes a literal approach to the variable name.

There are several workarounds for this. The key is to not use Rput to assign a 
value to something in R that requires evaluation, i.e. the "[i]" part.

1. Create the whole array in Fortran and tranfer it in one hit.
2. Pass the data: Rput("temp",par) and then assign it within R: 
Reval("param[i]=temp")

Original comment by Michael....@gmail.com on 3 Nov 2011 at 12:47

GoogleCodeExporter commented 8 years ago
A note for future development:

Either 
1. Submit bug report to StatCon and get IStatConnector_SetSymbol to evaluate 
expressions.
2. Replace Rput() with a fortran function that formalises the workaround above, 
e.g.

function RputFIXED(var,val) result(ok)
  !... declare variables

  ok = RPut("temp",val)           ! first dump the data in R
  ok = Reval(trim(var)//"=temp")  ! evaluate any expression in var and assign temp to it

end function

Original comment by Michael....@gmail.com on 3 Nov 2011 at 12:52