[R] R-Fortran question (multiple subroutines)

Remko Duursma remkoduursma at gmail.com
Tue Oct 26 01:39:12 CEST 2010


Hi Berwin and all others who replied:

that did the trick, thanks for your help!


remko


> Actually, it turns out that this example is simplified enough. :)
>
> I put this snippet into a file, compiled it via "R CMD SHLIB", loaded
> it into R and then was very surprised about the result of ".Fortran("f",
> x=1.1, y=2.2, z=0.0)".
>
> Eventually it dawned to me, Remko needs to read the table in section
> 5.2 of "Writing R Extensions".  The simple fix in this case is to put
> a "double precision x, y, z" at the beginning of each subroutine.  The
> default precision in FORTRAN is not double precision, that's why the
> code seems to work when compiled as stand alone but not when called
> from R.
>
> In general, I would recommend to start each subroutine with "implicit
> none" (o.k., I know that this is not standard FORTRAN77 but most
> compiler support that construct; the alternative, that would confrom
> with the FORTRAN77 standard, is to declare everything to be implicitly
> of type character and then let the fun begin) and then to explicitly
> declare all variables to be of the appropriate type.
>
> HTH.
>
> Cheers,
>
>        Berwin
>



More information about the R-help mailing list