Calling FORTRAN function from R issue?
On 06/03/2012 06:28, Berwin A Turlach wrote:
G'day Dominick, On Mon, 5 Mar 2012 19:21:01 -0500 Dominick Samperi<djsamperi at gmail.com> wrote:
...
This is consistent with the interface prototype for the BLAS
routine zdotc contained in<R>/include/R_ext/BLAS.h, namely,
BLAS_extern Rcomplex
F77_NAME(zdotc)(Rcomplex * ret_val, int *n,
Rcomplex *zx, int *incx, Rcomplex *zy, int *incy);
[...]
On the other hand, this is not consistent with the standard
FORTRAN definition for zdotc that is contained in
<R>/src/extra/blas/cmplxblas.f, where the first argument is
n, not ret_val.
This seems to be indeed inconsistent and, presumably, a bug. Applying the attach patch to R's development version (compiles, installs and passes all checks with this patch), and changing in your code the line
As I said elsewhere in this thread, this really is very compiler-specific, and rather than being a bug, that header is not appropriate to the compilers used (it came from the days of f2c and Fortran compilers based on it such as g77). I'll change the sources to follow your patch as I think it is much more likely to be correct these days, but also add a warning in the header. I don't think it is safe to call these functions from C without configure-testing the effect.
F77_CALL(zdotc)(&ret_val,&n, zx,&incx, zy,&incy); to ret_val = F77_CALL(zdotc)(&n, zx,&incx, zy,&incy); produces the expected output.
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