From plummerm at iarc.fr  Tue Sep 23 14:37:59 2014
From: plummerm at iarc.fr (Martyn Plummer)
Date: Tue, 23 Sep 2014 12:37:59 +0000
Subject: [Rd] Replace isnan and lgamma in Fortran subroutine in R package
In-Reply-To: <EB63692D-FE02-4767-A999-FDBB5A805B82@xs4all.nl>
References: <DABBA49CC8C7AA4B959D2D0FEE496D721C506A65@EXINFRCHMB1P.ccmc.local>
	<EB63692D-FE02-4767-A999-FDBB5A805B82@xs4all.nl>
Message-ID: <1411475879.3567.54.camel@braque.iarc.fr>

On Tue, 2014-09-23 at 07:43 +0200, Berend Hasselman wrote:
> On 23-09-2014, at 00:33, Wang, Zhu <Zwang at connecticutchildrens.org> wrote:
> 
> > Hello,
> > 
> > I submitted a package which used Fortran functions isnan and lgamma. However, I was told that:
> > 
> > isnan and lgamma are not Fortran 95 functions.
> > 
> > I was asked to write 'cross-platform portable code' and so should not be writing GNU extensions to Fortran.
> > 
> > See http://cran.r-project.org/web/checks/check_results_mpath.html, which will shortly show installation failures under Solaris.
> > 
> > I will appreciate advice on how to replace these two functions to avoid failure on some platforms.
> > 
> 
> I don?t know about lgamma.
> 
> Instead of isnan you could use Lapack?s logical function disnan to test for NaN (it?s in lapack 3.4.2; I don?t know about earlier versions).
> 
> Another way would be to write a C function using functions provided by R to test for NaN. 
> That function should be declared with F77_NAME so that it can be called from a Fortran routine.
> 
> I haven?t tried this so I don?t know if this would be foolproof or is the best way to do it..
> 
> Berend
> 

As described by Berend (See also section 6.6 of Writing R Extensions)
you can define Fortran-callable wrappers around ISNAN and lgammafn, both
of which are provided with the C interface to R (lgammafn is declared in
Rmath.h).  Then declare these wrappers as external subroutines in your
Fortran code and call them in place of isnan and lgamma.

Martyn


[Rd] Replace isnan and lgamma in Fortran subroutine in R package
Martyn Plummer