Parse a fortran subroutine/entry definition and return a C routine that can be used with .Call and R call snippet

make_dotcall_to_fortran(fun_strs)

Arguments

fun_str

a vector of subroutine definition strings with args

Value

a named list of C code and R code for each function

Examples

make_dotcall_to_fortran(c("subroutine foo(no,ni,x,y,w,theta)", "entry foobar(ix, y)", "subroutine bar(x,n,p,m)"))
#> $foo
#> $foo$c
#> [1] "SEXP c_foo(SEXP no,SEXP ni,SEXP x,SEXP y,SEXP w,SEXP theta) {"                
#> [2] "\tF77_NAME(foo)(INTEGER(no),INTEGER(ni),REAL(x),REAL(y),REAL(w),REAL(theta));"
#> [3] "\treturn(R_NilValue);"                                                        
#> [4] "}"                                                                            
#> 
#> $foo$r
#> [1] "result <- list(no=no,ni=ni,x=x,y=y,w=w,theta=theta)"                        
#> [2] ".Call('c_foo', result$no,result$ni,result$x,result$y,result$w,result$theta)"
#> 
#> 
#> $foobar
#> $foobar$c
#> [1] "SEXP c_foobar(SEXP ix,SEXP y) {"         
#> [2] "\tF77_NAME(foobar)(INTEGER(ix),REAL(y));"
#> [3] "\treturn(R_NilValue);"                   
#> [4] "}"                                       
#> 
#> $foobar$r
#> [1] "result <- list(ix=ix, y= y)"           
#> [2] ".Call('c_foobar', result$ix,result$ y)"
#> 
#> 
#> $bar
#> $bar$c
#> [1] "SEXP c_bar(SEXP x,SEXP n,SEXP p,SEXP m) {"              
#> [2] "\tF77_NAME(bar)(REAL(x),INTEGER(n),REAL(p),INTEGER(m));"
#> [3] "\treturn(R_NilValue);"                                  
#> [4] "}"                                                      
#> 
#> $bar$r
#> [1] "result <- list(x=x,n=n,p=p,m=m)"                    
#> [2] ".Call('c_bar', result$x,result$n,result$p,result$m)"
#> 
#>