https://github.com/ibarraespinosa/rfortran
An R package to play with Fortran and OpenMP. Nothing serious
https://github.com/ibarraespinosa/rfortran
fortran openmp r
Last synced: about 2 months ago
JSON representation
An R package to play with Fortran and OpenMP. Nothing serious
- Host: GitHub
- URL: https://github.com/ibarraespinosa/rfortran
- Owner: ibarraespinosa
- Created: 2020-09-24T19:28:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-04T21:59:20.000Z (over 4 years ago)
- Last Synced: 2025-01-30T20:54:03.148Z (3 months ago)
- Topics: fortran, openmp, r
- Language: Fortran
- Homepage: https://ibarraespinosa.github.io/rfortran/
- Size: 84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
output: github_document
---[](https://travis-ci.org/ibarraespinosa/rfortran)
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```# An R package to play with Fortran and OpenMP
I want to learn more R+Fortran so I created this package to play with R+Fortran
**ALWAYS READ THE [R-EXTS](https://cran.r-project.org/doc/manuals/r-release/R-exts.html) MANUAL**
## Comparison R and Fortran
(TODO Move to wiki or vignette)```{r}
ma <- array(1:6, c(3,2))
dim(ma) # shape in fortran
length(ma) # size in fortran
nrow(ma) # size(ma, 1)
ncol(ma) # size(ma, 2)
length(dim(ma)) # rank ma
print(ma)
``````{r}
library(inline)
code <- "
real, dimension(3,2) :: a
print *, 'size of a: ', size(a)
print *, 'size of 1 dim a : ', size(a,1)
print *, 'size of 2 dim a : ',size(a,2)
print *, 'rank a: ', rank(a)
print *, 'shape a: ', shape(a)
"
cubefn <- cfunction(body = code, convention=".Fortran")
print(cubefn)
cubefn()
```## Implementing several new fortran subroutines
I've found a nice repo [AstroFrog](https://github.com/astrofrog/fortranlib) with
lots of fortran subroutines that I will implementing as R functions here.
The implementation in R is vectorial, hence in Fortra arrays with the required dimension.|id| Fortran | R |
|--|-----------------|-------------------------|
|1|OpenMP| [get_threads](https://ibarraespinosa.github.io/rfortran/reference/get_threads.html)|
|2| [base_types.f90](https://github.com/astrofrog/fortranlib/blob/master/src/base_types.f90)| [get_types](https://ibarraespinosa.github.io/rfortran/reference/get_types.html)|
|3| [lib_algebra.f90](https://github.com/astrofrog/fortranlib/blob/master/src/lib_algebra.f90)| [quadratic_reduced](https://ibarraespinosa.github.io/rfortran/reference/quadratic_reduced.html)|
|4| [lib_algebra.f90](https://github.com/astrofrog/fortranlib/blob/master/src/lib_algebra.f90)| [quadratic](https://ibarraespinosa.github.io/rfortran/reference/quadratic.html)|
|5| [lib_algebra.f90](https://github.com/astrofrog/fortranlib/blob/master/src/lib_algebra.f90)| [cbrt](https://ibarraespinosa.github.io/rfortran/reference/cbrt.html)|```{r}
library(rfortran)
get_threads()
cbrt(1:3)
dp_quadratic_reduced(1:4,4:1)
dp_quadratic(1:4,4:1,4:1)
dp_quadratic_pascal(1:4,4:1,4:1)```
## Add more
If you know any play, fortran subroutine, trick or anything let me know, make a [pull request](https://github.com/ibarraespinosa/rfortran/pulls) or anything