Hello,
I am trying to call a FORTRAN subroutine from R. The Fortran code is @:
http://lib.stat.cmu.edu/apstat/206
It performs a bivariate isotonic regression on a rectangular grid (m X n) matrix. I used the g77 compiler and successfully created a dll file and it also loads successfully from R. But somehow the programs fails to run properly. (I do get the correct result when I compile the FORTRAN code). Please see below and note that since my input matrix X is monotonically increasing in both directions, input should be equal to output since the weights are set to 1 for all elements. (also verified this in FORTRAN to make sure that the subroutine works). Output[[10]] is supposed to be the monotonically regressed output, but it does not come out correctly. I don't know if its something to do with the way I am feeding the parameters to the DLL. Thanks in advance for any help I can receive. I am not god with FORTRAN - very very infrequent FORTRAN user. I am using R 2.4.0.
Regards
Krishna.
# Here is how the subroutine says to input the parameters;
#SUBROUTINE SMOOTH(NROW, NCOL, NDIM, X, W, A, B, NCYCLE, ICYCLE, G, EPS, IFAULT)
# Definitions of each of these input parameters are below;
#REAL X(NROW,NCOL), W(NROW,NCOL), A(NROW,NCOL,4), B(NDIM,5), G(NROW,NCOL), EPS, ZERO, DELTA, DELC, DELR, ORD, WW, FRACT
DATA ZERO/0.0/, DELTA/0.00001/, FRACT/0.5/
# Here is my R output;
1) You are calling FORTRAN code and not C code, so why are you using .C
instead of .Fortran?
2) Why do you append an underscore to the name of the routine that you
are using?
3) According to the FORTRAN source, the variables are defined as
REALs, not as DOUBLE PRECISION. R, by default expects to interface to
DOUBLE PRECISION. If you want to interface to REALs, you have to use
as.single or set the storage mode to single.
Details regarding all these points are in the "Writing R Extensions"
manual which I would strongly recommend you to study.
Cheers,
Berwin
=========================== Full address =============================
Berwin A Turlach Tel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability +65 6516 6650 (self)
Faculty of Science FAX : +65 6872 3919
National University of Singapore
6 Science Drive 2, Blk S16, Level 7 e-mail: statba at nus.edu.sg
Singapore 117546 http://www.stat.nus.edu.sg/~statba