1

I am using a R/C wrapper to call a set of subroutines in a Fortran module. I want to get the outputs as arrays of 2D and 3D in R. However, I am having troubles defining the 3D output in the wrapper. So far I did not manage to define the output for a 3D array, since allocMatrix takes only three arguments (for 2D arrays/matrices):


SEXP output = PROTECT( allocMatrix(REALSXP, nt, 5) );   
// 2nd argument to allocMatrix is number of rows, 3rd is number of columns 

Does anyone know if it is possible or how to define the output as a 3D array in the wrapper?

I'm working on a Mac running Fortran 90, GNU Fortran, and the C compiler that comes with Xcode.

Any help/suggestion would be much appreciated.

  • [This post](https://stackoverflow.com/questions/34561835/pass-arrays-from-c-c-to-fortran-and-return-a-calculated-array) has something to say about this. I am not sure if it will help. – ryyker Mar 05 '20 at 12:45
  • Have you tried `SEXP Rf_alloc3DArray(SEXPTYPE, int, int, int);`? – Ralf Stubner Mar 05 '20 at 14:57
  • One needs to get their head around the column major fortran and have some way to account for that differing from C being row major? – Holmz Mar 06 '20 at 08:36

0 Answers0