[Rd] LOGICAL arguments in FORTRAN code

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Apr 8 15:22:36 CEST 2010


On Thu, 8 Apr 2010, Berwin A Turlach wrote:

> G'day Brian,
>
>
>
> On Thu, 8 Apr 2010 12:40:45 +0100 (BST)
> Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>
>> On Thu, 8 Apr 2010, Berwin A Turlach wrote:
> [...]
>>> Thus, given that the port of quadprog existed for quite some time, I
>>> am wondering whether it is o.k. to pass R objects with storage mode
>>> logical into FORTRAN code to arguments declared as LOGICAL?  Or
>>> should the FORTRAN code be corrected to declare the argument in
>>> question as INTEGER?
>>
>> The second to be safe.  [...]
>
> Thanks for the quick and informative response.  I will make the
> necessary changes.
>
> BTW, can I assume that if R passes down TRUE to the FORTRAN routine the
> corresponding integer argument will be set to 1, and that it will be
> set to zero if FALSE is passed down?  Likewise, can I assume that if at
> the end of the FORTRAN routine the integer holds a value of zero, then
> FALSE is passed back to R and if the integer holds any other value then
> TRUE is passed back?  I don't remember ever reading any documentation
> about this; and most documentation that I would search is not at hand
> but back on the bookshelves of my office.....

NA_INTEGER is a possible value in both directions.  So R may send 0, 1 
or (if NAOK=TRUE) -2^31, and will copy back any value (but as 
a logical in R, it is intended that any value other than 0 and 
NA_LOGICAL is true).

Brian Ripley

>
> Cheers,
>
> 	Berwin
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list