[R] Help running a Fortran subroutine from R
dc896148
cyr.derek at gmail.com
Tue Mar 16 23:03:51 CET 2010
useR's,
I need help getting a Fortran DLL successfully returning the correct output.
The attached fortran source code (filter2d.f) and DLL (filter2d.dll) are
attached. Also, I attached a text file for which I want to apply the filter
to (time702.txt).
Here is what I am doing...
> dyn.load("C:/f/NEW/filter2d.dll")
> is.loaded("filter2d")
[1] TRUE
Then I pass the parameters according to the order they are specified in the
filter:
array <- data.matrix(read.table("time702.txt",header=F))
array1 <- array
nx <- 60
ny <- 120
halfintx <- 3
halfinty <- 3
mask <- matrix(array(rep(1.0,25)),5,5)
subarray <- matrix(0,5,5)
subarray1 <- matrix(0,5,5)
Then I run the Fortran subroutine...
out <- .Fortran("filter2d",
as.single(array),
as.single(array),
as.integer(nx),
as.integer(ny),
as.integer(halfintx),
as.integer(halfinty),
as.single(mask),
as.single(subarray),
as.single(subarray1))
The smoothed output is 'array1', which I just passed as 'array' in the
specification. It can be any matrix, but must be the same dimension as
'array', which is given as nx by ny.
Missing values in time702.txt are denoted by 999.00, and are defined that
way in the subroutine.
Can anyone see where I may be doing something wrong? I am not good with
fortran, as this code was previously written and now I am trying to adapt it
to R "on the fly".
Basically, filter2d smooths 'array' by averaging within the window halfintx
by halfinty.
Can anyone please help me out or provide some clarification?
THanks,
dxc13
http://n4.nabble.com/file/n1595641/filter2d.f filter2d.f
http://n4.nabble.com/file/n1595641/filter2d.dll filter2d.dll
http://n4.nabble.com/file/n1595641/time702.txt time702.txt
--
View this message in context: http://n4.nabble.com/Help-running-a-Fortran-subroutine-from-R-tp1595641p1595641.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list