[Rd] ALLOCATE in a FORTRAN subroutine

Martyn Byng martyn.byng at nag.co.uk
Mon Mar 7 18:27:45 CET 2016


Hi,

"we can, once we know how to do it, 'drive' R from within FORTRAN"
 I am not sure I understand what you mean by this ...

You can call routines written in Fortran or C from within R - how easy this is depends on the interfaces to those routines.
You can call (some) R functionality from C (see for example http://quantitative-ecology.blogspot.co.uk/2008/11/call-c-from-r-and-r-from-c.html). As you can call C from within Fortran, it is obviously possible also call R from within Fortran, but it is not something I have done so have no idea how much work is required to do that.

"for what I have understood in r_exts, it's more 'efficient' to translate R routines in C rather than in FORTRAN"
As far as I aware the R API for writing extensions etc is only available in C and there isn't a Fortran equivalent, so I guess it would be more "efficient" / easier in that sense as that would be one less level of cross-language programming you would have to worry about.

"I do not know why my customer (client ?) wanted to translate some R routines in FORTRAN."
Which language is preferred really boils down to personal preference and I am going to be slightly biased as I do almost all my numerical computing in Fortran. There is a good argument that Fortran is the most natural fit for numerical computing with its built in syntax to deal with complex numbers, matrices, array slicing, array operations  etc. In theory this gives compilers a good base to optimise from. The more restrictive nature of Fortran does make it more difficult to interface with other languages than C (but conversely makes it much more difficult to shoot yourself in the foot - and the Fortran compilers tend to pick up more problems at compile time than the C ones).

Martyn

-----Original Message-----
From: MAURICE Jean - externe [mailto:jean-externe.maurice at edf.fr]
Sent: 07 March 2016 15:46
To: Martyn Byng <martyn.byng at nag.co.uk>
Cc: r-devel at r-project.org
Subject: RE: ALLOCATE in a FORTRAN subroutine

Hi Martyn,

Many thanks for your answer. If I make it short :
we can, once we know how to do it, 'drive' R from within FORTRAN for example to do a
  Myarray = seq(0, mydimension)
in R once we have compute mydimension in FORTRAN. Is that correct ?
If yes : it's too 'complicated' for the time I am hired (I mean I have been hired to do FORTRAN code not to learn R !).

Second question : for what I have understood in r_exts, it's more 'efficient' to translate R routines in C rather than in FORTRAN (speed must be the 'same', but there are a lot more possibilities in C for the programmer) : right ? I do not know why my customer (client ?) wanted to translate some R routines in FORTRAN. May be it's by accident (in my humble opinion they even don't know about C). If you confirm this fact, I'll speak about C with my customer because we are at the very beginning of great works (great amounts of work ?) and I don't matter, I am also a skilled C programmer !!

I hope you understand what I want to say, english is not my natural language !

Thanks again and best regards.
Jean

________________________________________________________________________
This e-mail has been scanned for all viruses by Star.\ _...{{dropped:16}}



More information about the R-devel mailing list