An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

---
output: github_document
---

[![Travis-CI Build Status](https://travis-ci.org/ibarraespinosa/rfortran.svg?branch=master)](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