Transferring characters / strings from R to Fortran
I have a Fortran routine that selects a function based on a string value and then executes that function.
!! file:select.f90
module funcs
contains
subroutine add(x, y, xy)
real :: x, y, xy
xy = x + y
return
end subroutine
subroutine diff(x, y, xy)
real :: x, y, xy
xy = x - y
return
end subroutine
end module
subroutine simple(modname)
use funcs
procedure(), pointer :: model => null()
character(10) :: modname
real :: x, y, xy
print *, "-",modname,"-"
select case (modname)
case("add")
model => add
case("diff")
model => diff
case default
print *, "No model with that name!"
stop
end select
x = 4
y = 3
call model(x, y, xy)
print *, xy
end subroutine
I would like to call this subroutine from an R script.
# file:select.R
dyn.load("select.so")
.Fortran("simple", "add")
.Fortran("simple", "diff")
As a standalone Fortran program
that takes a command line argument, this works great. He is even insensitive to the spaces before or after modname
. However, when I try to pass a character as an argument from R, it retypes the character correctly (no extra whitespace), but then doesn't recognize it as case
and skips over it default
. What's going on here? Is there some issue with the R character encoding that makes them incompatible with Fortran?
source to share
No one has answered this question yet
Check out similar questions: