[R] R-Fortran question (multiple subroutines)
Berend Hasselman
bhh at xs4all.nl
Mon Oct 25 16:31:24 CEST 2010
Berwin A Turlach wrote:
>
>> Remko Duursma wrote:
> [...]
>> > I.e, my code looks something like this:
>> >
>> > subroutine f(x,y,z)
>> >
>> > call g(x,y,z)
>> >
>> > end
>> >
>> > subroutine g(x,y,z)
>> >
>> > z = x*y
>> >
>> > end
>> >
>> >
>> > calling this from R shows that subroutine g is not called. The code
>> > compiled as executable works fine.
>>
>> There are no such limitations imposed by R. I'd suggest your
>> diagnosis of the problem is wrong. If you can't spot the problem,
>> please post a real example (simplified if possible, but not as much
>> as the one above).
>
> 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.
>
I alway look for a command line option for the fortran compiler to achieve
the "implicit none".
gfortran has the option -fimplicit-none. I try to always use it.
For R package building I start out with using the implicit-none option and
comment it out in the makevars only in the final stage when R warns me about
non standard options.
Berend
--
View this message in context: http://r.789695.n4.nabble.com/R-Fortran-question-multiple-subroutines-tp3009729p3010385.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list