Skip to content
Prev 308790 / 398503 Next

Trouble returning 2D array into R from Fortran

On 23-10-2012, at 12:33, paulfjbrowne wrote:

            
But then any results are not reproducible. So there is no purpose in trying to reproduce your results.

See inline for further comments.
Output matrix defined with dimensions length(ti) rows and 2 columns!!!
This conflicts with the use in the Fortran code. See further on.
You are now changing the rules of the game.
Array y is now  2 rows and k columns.  And k == length(ti).

In your previous post, which I used, y was an array of k rows and 2 columns!
In your previous post this loop was

	do i=1,k
	   call xypos_parallax(year,ra,dec,ti(i),t0,tE,alpha,u0,piee,pien,y1,y2)
	   y(i,1) = y1
	   y(i,2) = y2

So you seem to have changed things.

But how can you expect to get interpretable results if you let R know that your matrix is Nx2
when in the Fortran code you declare the array as 2xN?

Since the total number of elements is 2N in both cases you are not getting into memory access trouble.
So in Fortran you want an array of N rows and 2 columns printed as

column 1 and 2 of row 1
column 1 and 2 of row 2
....

In other words you want the output matrix as defined in your Fortran program to be printed in Transposed form.

You should get what you want if in the R calling function you declare the matrix correctly.
I.e. length(ti) rows and 2 columns.

R is not storing anything in the wrong order; it is taking what the Fortran code is delivering.
R receives a matrix and you are telling R the dimensions.

Thereafter R is doing what you tell it to do.
Use t(y) which should display what you want.

Berend