[Rd] Good practice for packages with Fortran and C code
ih m@iii@g oii ih@rreii@com
ih m@iii@g oii ih@rreii@com
Fri Oct 25 22:03:54 CEST 2024
My older packages have some Fortran and C routines. The Fortran is ancient and I am started to convert it to Fortran 2018 (thanks ChatGPT). To have a mixture of Fortran and C code in a package I have had a src/init.c file that provides names for routines of the form F77_name, and I called the routines with .Fortran(F77_name, ...) and in NAMESPACE had useDynLib(package name, .registration=TRUE, .fixes="F_").
Now I find that I can get rid of init.c, and change NAMESPACE to use useDynLib(package name, list of compiled routine names) (without .registration and .fixes) after making sure the Fortran and C routines are not named the same as the package name. The routines are called using .Fortran(binary module name, args) or .Call(C binary module name, ...).
Can anyone see any problem with streamlining in this way?
I'm also using Fortran's dynamic array allocation instead of passing working vectors from R. For R arrays passed to Fortran I just have to also pass dimensions as arguments because R (or is it Fortran) does not allow us to use array declarations without dimensions in Fortran.
Thanks
Frank
More information about the R-devel
mailing list