[R] ALLOCATE in a FORTRAN subroutine

Berend Hasselman bhh at xs4all.nl
Fri Mar 4 09:23:01 CET 2016


> On 4 Mar 2016, at 08:51, MAURICE Jean - externe <jean-externe.maurice at edf.fr> wrote:
> 
> Hi Berend,
> 
> 
>> The question belongs on the R-devel mailinglist.
> I try to find this mailing-list ...
> 

See https://www.r-project.org/mail.html

>> You are calling your Fortran routines directly from an R file with .Fortran, I presume?
> Yes. Is there another solution (possibility ?)
> 

Yes. Use C to interface with Fortran.

See for example packages: minpack.lm, QZ, expm, nleqslv. And more: rootSolve, ucminf.
There are probably even more.

>> Declare them with (:,:) or (*,*), allocate and the return the array? A Fortran95 pointer?
> That was what I wanted to do ...
> 
>> I think  all of that is just a no no.
> It would be a big problem with memory management but R could copy the result before the memory attached to the FORTRAN subroutine is cleared at the end of the routine. R does so strange things (for an old programmer as I am).
> 
>> Is it possible to calculate the required size of the array in a separate routine given some parameters (as can often be done with >Lapack routines) before calling the main subroutine?
>> If so, call the sizing routine and then declare the correctly sized array in your R code and pass it to the main subroutine.
> 
> It's a good idea : a 'two shots' routine. I'll dig that (I'll work in this direction).
> 

Commercial:  Have a look at (my) packages nleqslv and geigen for that approach.

Berend



More information about the R-help mailing list